无法将变量传递给主题定制器ADD_SETTINGS()

时间:2013-02-11 作者:Sisir

我将主题选项保存为序列化数据。我通过获取主题名称来命名选项名称。

$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\'
                    )
                    )
                                                    );                                          
    }

1 个回复
最合适的回答,由SO网友:Sisir 整理而成

感谢@chip\\u bennett指出这一点!

我使用设置api注册了设置,并尝试按类型在自定义api上添加设置theme_mod 这就是它显示错误的原因。更改后\'type\' => \'theme_mod\'\'type\' => \'option\', 成功了:)

结束

相关推荐