我正在尝试使用主题定制API,但不断收到错误

时间:2014-04-17 作者:user50476

这是错误:

对/home/content/54/11786754/html/wp includes/class wp customize control中的非对象调用成员函数check\\u capabilities()。php在线161

这是我在函数中的代码。php

function lmao_customizer_register($wp_customize) {

$wp_customize->add_section(\'lmao_colors\',  array(

    \'title\' => __(\'colors\', \'lmao\'),
    \'description\' => \'modify the theme colors\'

));



$wp_customize->add_setting(\'background_color\',  array(

    \'default\' => \'#fff\',
    \'type\' => \'option\' 

));

$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, \'background_color\',  array(

    \'label\' => __(\'Edit Background Color\', \'lmao\'),
    \'section\' => \'lmao_colors\',
    \'settings\' => \'background_color\'

) ));

$wp_customize->add_setting(\'link_color\',  array(

    \'default\' => \'#fff\',
    \'type\' => \'option\' 

));

$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, \'link_color\',  array(

    \'label\' => __(\'Edit link Color\', \'lmao\'),
    \'section\' => \'lmao_colors\',
    \'settings\' => \'link_color\'

) ));

$wp_customize->add_setting(\'link_background_color\',  array(

    \'default\' => \'#fff\',
    \'type\' => \'option\' 

));

$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, \'link_background_color\',  array(

    \'label\' => __(\'Edit link background Color\', \'lmao\'),
    \'section\' => \'lmao_colors\',
    \'settings\' => \'link_background_color\'

) ));

$wp_customize->add_setting(\'link_background_color_hover\',  array(

    \'default\' => \'#fff\',
    \'type\' => \'option\' 

));

$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, \'link_background_color_hover\',  array(

    \'label\' => __(\'Edit link background hover Color\', \'lmao\'),
    \'section\' => \'lmao_colors\',
    \'settings\' => \'link_background_color_hover\'

) ));

//start image settings
$wp_customize->add_section(\'lmao_images\',  array(

    \'title\' => __(\'Images\', \'lmao\'),
    \'description\' => \'modify the theme images\'


));

$wp_customize->add_setting(\'main_image\',  array(

    \'default\' => \'http://hottraxstudioproductions.com/rawr/wp-content/uploads/2014/04/radio-logo.jpg\',
    \'type\' => \'option\' 

));

$wp_customize->add_control( new WP_Customize_image_Control($wp_customize, \'main_image\',  array(

    \'label\' => __(\'Edit main image\', \'lmao\'),
    \'section\' => \'lmao_images\',
    \'settings\' => \'main_image\'

) ));


    //start copyright settings
$wp_customize->add_section(\'lmao_copyright\',  array(

    \'title\' => __(\'Copyright_Details\', \'lmao\'),
    \'description\' => \'Edit copyright info\'

));

$wp_customize->add_setting(\'Copyright_Details\',  array(

    \'default\' => \'Copyright\',
    \'type\' => \'option\' 

));

$wp_customize->add_control(\'Copyright_Details\',  array(

    \'label\' => __(\'Edit copyright info\', \'lmao\'),
    \'section\' => \'lmao_copyright\',
    \'settings\' => \'copyright_details\'

));



}



function lmao_css_customizer() {
?>

<style type="text/css">

    body { background-color: #<?php echo get_theme_mod(\'background_color\'); ?    >;}

    nav ul li a {

        color: <?php echo get_theme_mod(\'link_color\'); ?>;
        background-color: <?php echo get_theme_mod(\'link_background_color\'); ?>;


    }

    nav ul li a:hover {

        background-color: <?php echo get_theme_mod(\'link_background_color_hover\'); ?>;


    }


</style>

<?php



}



add_action(\'wp_head\', \'lmao_css_customizer\');
add_action(\'customize_register\', \'LMAO_customizer_register\');
如果您需要更多信息,请告诉我。。。

2 个回复
SO网友:starryVere

我对Wordpress开发还比较陌生,但这段代码不应该在customizer中。php,在“inc”文件夹中(在活动主题的文件夹中)?

此外,我知道抄本上说,这段特定的代码只是用于实时预览,但在我的一个项目中添加了它之后,它似乎解决了我的问题。因此,您可能需要为添加到customizer\\u register函数中的每个部分包含这些get命令。例如,在代码的第一位之前,请尝试包括:

function lmao_customize_register( $wp_customize ) {
    $wp_customize->get_setting( \'lmao_colors\' )->transport=\'postMessage\';
}
add_action( \'customize_register\', \'testing_customize_register\' );
然后您将从添加节开始

function lmao_customizer_register($wp_customize) {
    $wp_customize->add_section(\'lmao_colors\',  array(
        \'title\' => __(\'colors\', \'lmao\'),
        \'description\' => \'modify the theme colors\'
));

    $wp_customize->add_setting(\'background_color\',  array(
        \'default\' => \'#fff\',
        \'type\' => \'option\' 
));

    $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, \'background_color\',  array(

        \'label\' => __(\'Edit Background Color\', \'lmao\'),
        \'section\' => \'lmao_colors\',
        \'settings\' => \'background_color\'

) ));
}
我希望这会有所帮助。如果不是,我很抱歉,就像我说的,我自己还是新手,但我想试着回答一下,因为你似乎已经有一段时间没有回复这个问题了。

祝你好运!

SO网友:Akash Kumar Sharma

这很可能只是一个拼写错误。

就在这里

//start copyright settings
$wp_customize->add_section(\'lmao_copyright\',  array(

\'title\' => __(\'Copyright_Details\', \'lmao\'),
\'description\' => \'Edit copyright info\'

));

$wp_customize->add_setting(\'Copyright_Details\',  array(

\'default\' => \'Copyright\',
\'type\' => \'option\' 

));

$wp_customize->add_control(\'Copyright_Details\',  array(

\'label\' => __(\'Edit copyright info\', \'lmao\'),
\'section\' => \'lmao_copyright\',
\'settings\' => \'copyright_details\'

));
请注意,copyright\\u details在以下情况下有不同的情况:

$wp_customize->add_setting(\'Copyright_Details\',  array
而不是在add\\u control部分的设置中:

\'settings\' => \'copyright_details\'
这两个设置应该相同,否则将触发您得到的功能错误。

结束

相关推荐

设置API监听页面

我需要创建一个PHP脚本,该脚本将通过HTTP post从另一个应用程序接收数据,处理该数据,并更新WordPress数据库。此脚本将以静默方式运行(即没有HTTP输出)。设置这样一个页面的最佳方式是什么?我曾想过用PHP脚本创建一个自定义模板文件,并将该模板分配给一个空白的WordPress页面,但有没有更好的方法可以使用呢?