代码示例的问题是,设置正在使用widget_ 作为前缀。根据customizer handbook:
Important: 不要使用如下设置IDwidget_*, sidebars_widgets[*], nav_menu[*], 或nav_menu_item[*]. 这些设置ID模式分别为小部件实例、侧栏、导航菜单和导航菜单项保留。如果您需要在设置ID中使用“widget”,请将其用作后缀,而不是前缀,例如“homepage_widget”.
以下是按预期工作的修改代码:
<?php
namespace Roots\\Sage\\Customizer;
use Roots\\Sage\\Assets;
/**
* Add customization settings for the theme
*/
function customize_register($wp_customize) {
//////////////////////////
// WIDGET STYLE OPTIONS //
//////////////////////////
$wp_customize->add_section( \'style_section_widget\', array(
\'title\' => __(\'Widget Styling\', __NAMESPACE__),
\'priority\' => 115,
));
$wp_customize->add_setting( \'list_style_widget\', array(
\'default\' => \'hide\',
\'transport\' => \'postMessage\',
));
$wp_customize->add_control( \'widget_list_style_control\', array(
\'label\' => __( \'Display List Style?\', __NAMESPACE__),
\'Description\' => __(\'Removes the symbols next to bulleted and unbulleted lists in Widgets\', __NAMESPACE__),
\'section\' => \'style_section_widget\',
\'settings\' => \'list_style_widget\',
\'type\' => \'radio\',
\'choices\' => array(
\'hide\' => __(\'Hide\'),
\'show\' => __(\'Show\'),
),
));
// Add postMessage support
$wp_customize->get_setting(\'blogname\')->transport = \'postMessage\';
$wp_customize->get_setting(\'blogdescription\')->transport = \'postMessage\';
}
add_action(\'customize_register\', __NAMESPACE__ . \'\\\\customize_register\', 11);
还请注意,我更改了的优先级
customize_register 从10(默认值)到11
blogname 和
blogdescription 此时可能无法注册设置。