Files
hoponhopofftickets/astra-child-hoponhopoff/functions.php
amir 35368fb5f9 perf/fix: externalize images to WP media; normalize Astra leaks; full-width
Plugin (1.8.2):
- remove all bundled raster images (~9.3MB) from assets/img; hero + single
  hero figure now come from the WP Media Library (Settings), shortcode args
  ([viator_hero image_id]), or the vc_testimonials filter — rendered responsive
- vc_hero_image_source() prefers an attachment ID (srcset); listing/hero use it
- settings: store hero_image_id + single_hero_figure_id (media pickers)
- enqueue at priority 20 + depend on astra-theme-css so our CSS wins ties
- stronger Astra overrides (!important): kill page-builder article top padding
  (gap above hero), force full-bleed containers, guard horizontal scroll
- normalize theme leaks inside .vc-app: no link underline, no list bullets
  (with prose exceptions for the tour Overview); gradient hero fallback

Theme: normalize .hoho link/list leaks; rebuild installable ZIP.
Also: move optimized originals to /removed-images/; ship viator-collector.zip.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J4hNL1PSHxXbu94SCenpKj
2026-09-15 19:42:49 +03:30

146 lines
5.8 KiB
PHP

<?php
/**
* Hop On Hop Off — Astra child theme.
*
* Replaces the Astra header/footer with the "Hop On Hop Off" design and loads
* the scoped chrome stylesheet + SVG icon sprite site-wide.
*/
defined( 'ABSPATH' ) || exit;
/**
* Styles & scripts.
*/
add_action( 'wp_enqueue_scripts', function () {
// Parent (Astra) base styles.
wp_enqueue_style( 'astra-parent', get_template_directory_uri() . '/style.css', array(), null );
// Design typeface (same as the plugin's pages).
wp_enqueue_style( 'hoho-fonts', 'https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;700;800&display=swap', array(), null );
// Header/footer design, scoped to .hoho so it can't fight Astra. Depend on
// the Astra stylesheet (when present) so our rules load AFTER it and win ties.
$deps = array( 'astra-parent' );
if ( wp_style_is( 'astra-theme-css', 'registered' ) ) {
$deps[] = 'astra-theme-css';
}
wp_enqueue_style( 'hoho-chrome', get_stylesheet_directory_uri() . '/assets/chrome.css', $deps, '1.0.1' );
// Header interactions: burger, submenu, sticky, back-to-top, search toggle.
wp_enqueue_script( 'hoho-chrome', get_stylesheet_directory_uri() . '/assets/chrome.js', array(), '1.0.1', true );
wp_add_inline_style(
'hoho-chrome',
implode(
'',
array(
// Solid, sticky header on pages without a hero to overlay (added by
// chrome.js as .is-solid) so it stays readable and doesn't cover content.
'.hoho .site-header.is-solid{position:sticky;inset-block-start:0;padding-block:var(--sp-2);background:rgba(0,0,0,.85);-webkit-backdrop-filter:blur(12px);backdrop-filter:blur(12px);}',
// Force the design font over Astra inside the header/footer.
'.hoho,.hoho h1,.hoho h2,.hoho h3,.hoho p,.hoho a,.hoho span,.hoho li,.hoho button,.hoho input{font-family:"Plus Jakarta Sans",system-ui,-apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;}',
// Normalize: stop Astra decorating header/footer links & lists.
'.hoho a,.hoho.hoho a{text-decoration:none!important;box-shadow:none!important;}',
'.hoho :is(ul,ol){list-style:none!important;margin:0!important;padding:0!important;}',
'.hoho li{margin:0!important;}',
// Expanding header search field.
'.hoho .header__search{display:flex;align-items:center;gap:.25rem;}',
'.hoho .header__search-input{width:0;min-width:0;padding:0;border:0;outline:0;opacity:0;height:var(--control-h);border-radius:var(--r-pill);background:rgba(255,255,255,.15);color:#fff;transition:width .25s var(--ease),opacity .2s var(--ease),padding .25s var(--ease);}',
'.hoho .header__search.is-open .header__search-input{width:min(52vw,15rem);padding:0 1rem;opacity:1;}',
'.hoho .header__search-input::placeholder{color:rgba(255,255,255,.7);}',
)
)
);
}, 20 );
/**
* Theme supports + menu locations.
*/
add_action( 'after_setup_theme', function () {
add_theme_support( 'custom-logo', array( 'flex-width' => true, 'flex-height' => true ) );
register_nav_menus(
array(
'hoho_primary' => __( 'HoHo — Header Menu', 'hoponhopoff' ),
'hoho_quick' => __( 'HoHo — Footer: Quick Access', 'hoponhopoff' ),
'hoho_tours' => __( 'HoHo — Footer: Tours', 'hoponhopoff' ),
'hoho_account' => __( 'HoHo — Footer: User Account', 'hoponhopoff' ),
)
);
} );
/**
* Print the SVG icon sprite once, high in the footer, so <use href="#i-…">
* resolves everywhere (header, footer, and the plugin's pages).
*/
add_action( 'wp_footer', function () {
// Reuse the plugin's guarded printer when available, so the sprite is never
// output twice on plugin pages.
if ( function_exists( 'vc_print_icon_sprite' ) ) {
vc_print_icon_sprite();
return;
}
$sprite = get_stylesheet_directory() . '/assets/sprite.svg';
if ( is_readable( $sprite ) ) {
echo file_get_contents( $sprite ); // phpcs:ignore
}
}, 1 );
/**
* Swap Astra's header/footer markup for ours.
*
* Astra prints its header via astra_header_markup() on the `astra_header`
* action, and its footer via astra_footer_markup() on `astra_footer`. We remove
* those and render our own template parts. Deferred to `wp` so Astra's parent
* functions.php (which registers the callbacks) has already loaded.
*/
add_action( 'wp', function () {
if ( function_exists( 'astra_header_markup' ) ) {
remove_action( 'astra_header', 'astra_header_markup' );
}
add_action( 'astra_header', 'hoho_render_header' );
if ( function_exists( 'astra_footer_markup' ) ) {
remove_action( 'astra_footer', 'astra_footer_markup' );
}
add_action( 'astra_footer', 'hoho_render_footer' );
} );
function hoho_render_header() {
require get_stylesheet_directory() . '/inc/header.php';
}
function hoho_render_footer() {
require get_stylesheet_directory() . '/inc/footer.php';
}
require get_stylesheet_directory() . '/inc/nav-walker.php';
/**
* The logo: a linked WordPress Custom Logo if one is set, otherwise the bundled
* "Hop On Hop Off" SVG wordmark.
*/
function hoho_logo() {
$home = esc_url( home_url( '/' ) );
if ( has_custom_logo() ) {
$id = get_theme_mod( 'custom_logo' );
$img = wp_get_attachment_image( $id, 'full', false, array( 'class' => 'logo' ) );
if ( $img ) {
return '<a class="header__logo" href="' . $home . '" aria-label="' . esc_attr( get_bloginfo( 'name' ) ) . '">' . $img . '</a>';
}
}
ob_start();
?>
<a class="header__logo" href="<?php echo $home; ?>" aria-label="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>">
<?php require get_stylesheet_directory() . '/inc/logo.php'; ?>
</a>
<?php
return ob_get_clean();
}
/**
* Small helper: inline-icon markup referencing the sprite.
*/
function hoho_icon( $name, $extra = '' ) {
$name = preg_replace( '/[^a-z0-9\-]/', '', 'i-' . ltrim( (string) $name, 'i-' ) );
$class = 'icon' . ( $extra ? ' ' . $extra : '' );
return '<svg class="' . esc_attr( $class ) . '" aria-hidden="true"><use href="#' . esc_attr( $name ) . '"></use></svg>';
}