You can get and check the value of your theme mod as you normally do anywhere.
This code is tested and working (the code inside cyb_customizer()
is exactly the code you posted in the question, only added add_section
part):
function flag_is_custom_excerpt_enabled(){
$blueplanet_options = get_theme_mod( 'blueplanet_options');
if( empty( $blueplanet_options['theme_enable_custom_excerpt'] ) ) {
return false;
}
return true;
}
add_action( 'customize_register', 'cyb_customizer' );
function cyb_customizer( $wp_customize ) {
$wp_customize->add_section(
'admin_section',
array(
'title' => 'Admin section',
'description' => 'Admin section',
'priority' => 0,
)
);
$wp_customize->add_setting( 'blueplanet_options[theme_enable_custom_excerpt]',
array(
'default' => false,
'capability' => 'edit_theme_options',
)
);
$wp_customize->add_control(
'theme_enable_custom_excerpt',
array(
'label' => 'Enable Custom Excerpt Length',
'section' => 'admin_section',
'settings' => 'blueplanet_options[theme_enable_custom_excerpt]',
'type' => 'checkbox',
)
);
$wp_customize->add_setting( 'blueplanet_options[theme_custom_excerpt_length]',
array(
'default' => 20,
'capability' => 'edit_theme_options',
)
);
$wp_customize->add_control(
'theme_custom_excerpt_length',
array(
'label' => 'Custom Excerpt Length',
'section' => 'admin_section',
'settings' => 'blueplanet_options[theme_custom_excerpt_length]',
'type' => 'text',
'active_callback' => 'flag_is_custom_excerpt_enabled',
)
);
}