你可以像往常一样在任何地方获取和检查你的主题模型的值。
此代码经过测试并正常工作(内部代码cyb_customizer()
正是您在问题中发布的代码,只添加了add_section
零件号):
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\',
)
);
}