$max ) { $val = $max; } return $val; } } if ( ! function_exists( 'bongoto_woocommerce_sanitize_hex_color' ) ) { function bongoto_woocommerce_sanitize_hex_color( $color ) { $color = trim( (string) $color ); return ( '' === $color ) ? '' : sanitize_hex_color( $color ); } } /* ------------------------------------------------------------------------- * Register main panel, sections, and core controls * ------------------------------------------------------------------------- */ function bongoto_woocommerce_customize_register( WP_Customize_Manager $wp_customize ) { $is_pro = apply_filters( 'bongoto_woocommerce/is_pro_active', ( defined( 'BONGOTO_WOOCOMMERCE_PRO_ACTIVE' ) && BONGOTO_WOOCOMMERCE_PRO_ACTIVE ) ); // Main panel (theme + add-on share this). $wp_customize->add_panel( 'bongoto_woocommerce_panel', array( 'title' => __( 'Bongoto WooCommerce Options', 'bongoto-woocommerce' ), 'description' => __( 'Global theme options. Site Identity controls remain in the WordPress core section.', 'bongoto-woocommerce' ), 'priority' => 160, ) ); /** * General → only a shell section here. * Actual color settings/controls live in inc/customizer/options-general.php. */ if ( ! $wp_customize->get_section( 'bongoto_woocommerce_section_general' ) ) { $wp_customize->add_section( 'bongoto_woocommerce_section_general', array( 'title' => __( 'General', 'bongoto-woocommerce' ), 'priority' => 10, 'panel' => 'bongoto_woocommerce_panel', ) ); } /* --------------------------------------------------------------------- * Site Identity extras (logo size, title/tagline toggles) * ------------------------------------------------------------------- */ // Logo max height. $wp_customize->add_setting( 'bongoto_woocommerce_logo_max_height', array( 'default' => 40, 'transport' => 'postMessage', 'sanitize_callback' => function ( $v ) { return bongoto_woocommerce_sanitize_int_range( $v, 16, 200, 40 ); }, ) ); $wp_customize->add_control( 'bongoto_woocommerce_logo_max_height', array( 'section' => 'title_tagline', 'label' => __( 'Logo Max Height (px)', 'bongoto-woocommerce' ), 'description' => __( 'Sets the maximum rendered height of the logo image.', 'bongoto-woocommerce' ), 'type' => 'number', 'priority' => 43, 'input_attrs' => array( 'min' => 16, 'max' => 200, 'step' => 1, ), ) ); // Show title text. $wp_customize->add_setting( 'bongoto_woocommerce_show_title_text', array( 'default' => true, 'transport' => 'postMessage', 'sanitize_callback' => 'bongoto_woocommerce_sanitize_checkbox', ) ); $wp_customize->add_control( 'bongoto_woocommerce_show_title_text', array( 'section' => 'title_tagline', 'label' => __( 'Show Title (text)', 'bongoto-woocommerce' ), 'type' => 'checkbox', 'priority' => 44, ) ); // Show tagline text. $wp_customize->add_setting( 'bongoto_woocommerce_show_tagline_text', array( 'default' => true, 'transport' => 'postMessage', 'sanitize_callback' => 'bongoto_woocommerce_sanitize_checkbox', ) ); $wp_customize->add_control( 'bongoto_woocommerce_show_tagline_text', array( 'section' => 'title_tagline', 'label' => __( 'Show Tagline (description)', 'bongoto-woocommerce' ), 'type' => 'checkbox', 'priority' => 45, ) ); // Selective refresh for identity. if ( isset( $wp_customize->selective_refresh ) ) { $wp_customize->selective_refresh->add_partial( 'blogname', array( 'selector' => '.site-title a', 'render_callback' => function () { return esc_html( get_bloginfo( 'name' ) ); }, ) ); $wp_customize->selective_refresh->add_partial( 'blogdescription', array( 'selector' => '.site-description', 'render_callback' => function () { return esc_html( get_bloginfo( 'description', 'display' ) ); }, ) ); } /* --------------------------------------------------------------------- * Shell sections (real settings live in included option files) * ------------------------------------------------------------------- */ // Header section (Header Settings). if ( ! $wp_customize->get_section( 'bongoto_woocommerce_section_header' ) ) { $wp_customize->add_section( 'bongoto_woocommerce_section_header', array( 'title' => __( 'Header Settings', 'bongoto-woocommerce' ), 'priority' => 20, 'panel' => 'bongoto_woocommerce_panel', ) ); } // Footer section (Footer Settings). if ( ! $wp_customize->get_section( 'bongoto_woocommerce_section_footer' ) ) { $wp_customize->add_section( 'bongoto_woocommerce_section_footer', array( 'title' => __( 'Footer Settings', 'bongoto-woocommerce' ), 'priority' => 40, 'panel' => 'bongoto_woocommerce_panel', 'description' => $is_pro ? __( 'Footer layout and copyright settings.', 'bongoto-woocommerce' ) : __( 'Footer layout settings. (Copyright text editing is available in Bongoto WooCommerce Pro)', 'bongoto-woocommerce' ), ) ); } } add_action( 'customize_register', 'bongoto_woocommerce_customize_register' ); /* ------------------------------------------------------------------------- * Cleanup: remove legacy/duplicate controls and core Colors section * ------------------------------------------------------------------------- */ add_action( 'customize_register', function ( WP_Customize_Manager $wp_customize ) { // Remove legacy IDs (if present). foreach ( array( 'bongoto_show_site_title', 'bongoto_show_tagline', 'bongoto_show_site_icon', 'bongoto_show_site_icon_header' ) as $id ) { if ( $wp_customize->get_control( $id ) ) { $wp_customize->remove_control( $id ); } if ( $wp_customize->get_setting( $id ) ) { $wp_customize->remove_setting( $id ); } } // Remove WP core "Display Site Title & Tagline" control (we use our own). if ( $wp_customize->get_control( 'display_header_text' ) ) { $wp_customize->remove_control( 'display_header_text' ); } // Remove core Colors section to avoid duplication (we provide our own). if ( $wp_customize->get_section( 'colors' ) ) { $wp_customize->remove_section( 'colors' ); } // Strip identity-like controls that might slip into General. foreach ( $wp_customize->controls() as $control ) { $label = is_string( $control->label ) ? $control->label : ''; $section = $control->section; if ( 'bongoto_woocommerce_section_general' === $section ) { if ( stripos( $label, 'Site Title' ) !== false || stripos( $label, 'Tagline' ) !== false || stripos( $label, 'Site Icon' ) !== false ) { $wp_customize->remove_control( $control->id ); if ( $wp_customize->get_setting( $control->id ) ) { $wp_customize->remove_setting( $control->id ); } } } } }, 999 ); /* ------------------------------------------------------------------------- * Include option files (if present) * ------------------------------------------------------------------------- */ function bongoto_woocommerce_customize_include_option_files() { $base = trailingslashit( get_template_directory() ) . 'inc/customizer/'; $files = array( 'sanitize.php', 'options-general.php', 'options-header.php', 'options-topbar.php', // if present 'options-footer.php', 'options-hero.php', 'controls/class-sortable-control.php', ); foreach ( $files as $rel ) { $path = $base . ltrim( $rel, '/' ); if ( file_exists( $path ) ) { require_once $path; } } } add_action( 'after_setup_theme', 'bongoto_woocommerce_customize_include_option_files', 20 ); /* ------------------------------------------------------------------------- * Live preview (optional) * ------------------------------------------------------------------------- */ function bongoto_woocommerce_customize_live_preview_js() { $rel = 'assets/js/customizer.js'; $file = trailingslashit( get_template_directory() ) . $rel; if ( file_exists( $file ) ) { wp_enqueue_script( 'bongoto-woocommerce-customizer-live', trailingslashit( get_template_directory_uri() ) . $rel, array( 'customize-preview', 'jquery' ), '1.0.0', true ); } } add_action( 'customize_preview_init', 'bongoto_woocommerce_customize_live_preview_js' ); /* ------------------------------------------------------------------------- * Output CSS variables for colors * ------------------------------------------------------------------------- */ function bongoto_woocommerce_customizer_colors_css() { $primary = get_theme_mod( 'bongoto_woocommerce_color_primary', '#2563eb' ); $accent = get_theme_mod( 'bongoto_woocommerce_color_accent', '#10b981' ); $text = get_theme_mod( 'bongoto_woocommerce_color_text', '#111827' ); $bg = get_theme_mod( 'bongoto_woocommerce_color_bg', '#ffffff' ); printf( '', esc_html( $primary ), esc_html( $accent ), esc_html( $text ), esc_html( $bg ) ); } add_action( 'wp_head', 'bongoto_woocommerce_customizer_colors_css', 20 ); /* ------------------------------------------------------------------------- * Small “Pro” badge in Customizer header * ------------------------------------------------------------------------- */ add_action( 'customize_controls_print_footer_scripts', function () { $is_pro = apply_filters( 'bongoto_woocommerce/is_pro_active', false ); $pro_link = esc_url( 'https://bongoto.com/product/bongoto-woocommerce-add-on-plugin/' ); ?>