init(); // WC templates: SLB plugin directory is checked before the theme. add_filter( 'woocommerce_locate_template', static function( $template, $template_name ) { $plugin_path = SLBUILD_PATH . 'woocommerce/' . $template_name; if ( file_exists( $plugin_path ) ) { return $plugin_path; } return $template; }, 10, 2 ); // Auto-seed global regions when a new SLB theme is activated. add_action( 'after_switch_theme', array( 'SLBUILD_ThemeSetup', 'seed_globals' ) ); // Bridge saved global settings into WP/WC hooks (after WC has loaded). add_action( 'init', array( 'SLBUILD_SettingsHooks', 'init' ), 20 ); // Enqueue per-section assets (scripts/styles declared in the schema `assets` key). add_action( 'wp_enqueue_scripts', array( SLBUILD_SectionLoader::instance(), 'maybe_enqueue_assets' ), 20 ); // Load the bundled, precompiled utility stylesheet on SLB pages and preview. No // script runs in the browser and nothing is fetched from an external host. // Themes that already load Tailwind with their own config should opt out via: // add_filter( 'slbuild_load_tailwind', '__return_false' ); add_action( 'wp_enqueue_scripts', function() { $is_preview = isset( $_GET['slbuild_preview'] ) || isset( $_GET['slbuild_preview_token'] ); // phpcs:ignore WordPress.Security.NonceVerification if ( ! $is_preview && ! ( is_singular() && get_post_meta( get_the_ID(), SLBUILD_DataStore::PAGE_META_KEY, true ) ) ) { return; } if ( apply_filters( 'slbuild_load_tailwind', true ) ) { wp_enqueue_style( 'slbuild-tailwind', SLBUILD_URL . 'assets/slbuild-tailwind.css', array(), SLBUILD_VERSION ); } // Saved colour-scheme overrides are generated rules, kept apart from the // compiled file so they still apply when a theme opts out of it. $overrides = function_exists( 'slbuild_scheme_override_css' ) ? slbuild_scheme_override_css() : ''; if ( '' !== $overrides ) { wp_register_style( 'slbuild-scheme-overrides', false, array(), SLBUILD_VERSION ); wp_enqueue_style( 'slbuild-scheme-overrides' ); wp_add_inline_style( 'slbuild-scheme-overrides', $overrides ); } } ); // Never cache any SLB preview request. // Covers all major caching plugins (DONOTCACHEPAGE) and CDNs (Cache-Control header). add_action( 'init', function() { $is_preview = isset( $_GET['slbuild_preview'] ) // phpcs:ignore WordPress.Security.NonceVerification || isset( $_GET['slbuild_preview_token'] ); // phpcs:ignore WordPress.Security.NonceVerification if ( ! $is_preview ) { return; } if ( ! defined( 'DONOTCACHEPAGE' ) ) { define( 'DONOTCACHEPAGE', true ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound } header( 'Cache-Control: no-store, no-cache, must-revalidate, private' ); header( 'Pragma: no-cache' ); do_action( 'litespeed_control_set_nocache', 'slbuild_preview' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound } ); // Hide the admin bar inside the preview iframe. add_filter( 'show_admin_bar', function( $show ) { if ( isset( $_GET['slbuild_preview'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification return false; } return $show; } ); // Noindex pages served via a preview token - they are client-review-only URLs. add_action( 'wp_head', function() { if ( isset( $_GET['slbuild_preview_token'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification echo '' . "\n"; } } ); // Output theme-settings CSS custom properties via wp_add_inline_style(). // Priority 5 - before theme styles so Tailwind arbitrary values can reference them. add_action( 'wp_enqueue_scripts', function() { if ( ! function_exists( 'slbuild_global_setting' ) ) { return; } $lines = array(); $color_fields = array( 'primary_color' => '--slb-primary', 'secondary_color' => '--slb-secondary', 'tertiary_color' => '--slb-tertiary', 'surface_color' => '--slb-surface', 'on_surface_color' => '--slb-on-surface', 'accent_color' => '--slb-accent', ); foreach ( $color_fields as $field => $var ) { $val = sanitize_hex_color( (string) slbuild_global_setting( 'theme-settings', $field, '' ) ); if ( $val ) { $lines[] = "\t" . $var . ': ' . $val . ';'; } } $threshold = slbuild_global_setting( 'theme-settings', 'free_shipping_threshold', '' ); if ( $threshold !== '' ) { $lines[] = "\t--slb-free-shipping: " . (int) $threshold . ';'; } if ( empty( $lines ) ) { return; } wp_register_style( 'slbuild-theme-vars', false, array(), SLBUILD_VERSION ); wp_enqueue_style( 'slbuild-theme-vars' ); wp_add_inline_style( 'slbuild-theme-vars', ':root {' . "\n" . implode( "\n", $lines ) . "\n}" ); }, 5 );