我将主题选项保存为序列化数据。我通过获取主题名称来命名选项名称。
$theme = wp_get_theme();
$settings = sanitize_title($theme).\'-options\'; // do not change!
但是,当我尝试传递$settings变量时,无论是否串联。它最终会出现这个致命错误。
Fatal error: Call to a member function check_capabilities() on a non-object in C:\\Users\\SISIR\\Dropbox\\wamp\\www\\l\\wp-includes\\class-wp-customize-control.php on line 160
检查
$settings.\'[skin\']
当我用
\'lead_capture_theme_option[skin]\'
, 它起作用了。致命错误本身也令人费解。
add_action( \'customize_register\', \'lead_capture_theme_customize_register\', 11 );
function lead_capture_theme_customize_register($wp_customize) {
$theme = wp_get_theme();
$settings = sanitize_title($theme).\'-options\'; // do not change!
// var_dump($settings);
$wp_customize->add_section( \'lead_cap_color_scheme\', array( \'title\' => __( \'Color Scheme\', \'themename\' ),
\'priority\' => 35
)
);
$wp_customize->add_setting( $settings.\'[skin]\', array( \'default\' => \'light\',
\'type\' => \'theme_mod\',
\'capability\' => \'edit_theme_options\' )
);
$wp_customize->add_control( \'lead_capture_theme_option[skin]\', array( \'label\' => \'Select a Color Scheme\',
\'type\' => \'select\',
\'choices\' => array(\'default\', \'custom\'),
\'section\' => \'lead_cap_color_scheme\',
\'settings\' => \'lead_capture_theme_option[skin]\'
)
);
$wp_customize->add_setting( \'lead_capture_theme_option[logo]\', array(
\'type\' => \'theme_mod\',
\'capability\' => \'edit_theme_options\'
)
);
$wp_customize->add_control(
new WP_Customize_Image_Control( $wp_customize, \'lead_capture_theme_option[logo]\', array(
\'label\' => \'Upload Logo\',
\'section\' => \'lead_cap_color_scheme\'
)
)
);
}