$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 ) {
$premium_active = (bool) get_option( 'bongoto_premium_active', false );
$is_pro = $premium_active || apply_filters(
'bongoto_woocommerce/is_pro_active',
( defined( 'BONGOTO_WOOCOMMERCE_PRO_ACTIVE' ) && BONGOTO_WOOCOMMERCE_PRO_ACTIVE )
);
// Single top-level panel requested by client.
$wp_customize->add_panel(
'bongoto_general_panel',
array(
'title' => __( 'General', 'bongoto-woocommerce' ),
'description' => __( 'Theme-wide layout & styling options.', 'bongoto-woocommerce' ),
'priority' => 30,
)
);
/* ---------------------------------------------------------------------
* 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' => false,
'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' ) );
},
)
);
// Refresh left header branding (Logo + Site Title/Tagline) when any identity-related setting changes.
$wp_customize->selective_refresh->add_partial(
'bongoto_woocommerce_header_left_branding',
array(
'selector' => '.bt-header-left',
'settings' => array(
'custom_logo',
'bongoto_woocommerce_logo_max_height',
'bongoto_woocommerce_show_title_text',
'bongoto_woocommerce_show_tagline_text',
'blogname',
'blogdescription',
),
'container_inclusive' => true,
'render_callback' => function () {
ob_start();
if ( function_exists( 'bongoto_woocommerce_header_manager' ) ) {
bongoto_woocommerce_header_manager()->render_zone( 'left' );
} else {
get_template_part( 'template-parts/headers/components/logo' );
get_template_part( 'template-parts/headers/components/site-title' );
}
return ob_get_clean();
},
)
);
}
// Note: Header/Footer/Colors/Containers sections are registered in their respective option files.
}
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' ),
filemtime( $file ),
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' );
// NOTE: This theme supports two generations of theme_mod keys.
// Newer keys (bongoto_woocommerce_color_*) were used in early versions,
// while demo presets + current Customizer color section use bongoto_color_*.
// Prefer bongoto_color_* when present so Buy Now / Checkout colors reflect correctly.
$add_to_cart = get_theme_mod( 'bongoto_color_add_to_cart', get_theme_mod( 'bongoto_woocommerce_color_add_to_cart', $primary ) );
$buy_now = get_theme_mod( 'bongoto_color_buy_now', get_theme_mod( 'bongoto_woocommerce_color_buy_now', $accent ) );
$checkout = get_theme_mod( 'bongoto_color_checkout_btn', get_theme_mod( 'bongoto_woocommerce_color_checkout', $text ) );
printf(
'',
esc_html( $primary ),
esc_html( $accent ),
esc_html( $text ),
esc_html( $bg ),
esc_html( $add_to_cart ),
esc_html( $buy_now ),
esc_html( $checkout )
);
}
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 = false;
// 1) Primary: license activation option
$is_pro = (bool) get_option( 'bongoto_premium_active', false );
// 2) Compatibility: if helper exists
if ( ! $is_pro && function_exists( 'bongoto_woocommerce_is_pro_active' ) ) {
$is_pro = (bool) bongoto_woocommerce_is_pro_active();
}
// 3) Fallback: filter (premium/plugin)
if ( ! $is_pro ) {
$is_pro = (bool) apply_filters( 'bongoto_woocommerce/is_pro_active', false );
}
$pro_link = esc_url( 'https://bongoto.com/product/bongoto-woocommerce-theme/' );
?>