wordpress 在 functions.php 第 5 行的非对象上调用成员函数 add_section() [英] wordpress Call to a member function add_section() on a non-object in functions.php line 5

查看:22
本文介绍了wordpress 在 functions.php 第 5 行的非对象上调用成员函数 add_section()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我对 php 和 wordpress 开发有点陌生,我只是在试验 wordpress 的工作原理和主题的工作原理.现在我已经试过多次查找这个,但没有帮助.它总是不同的东西,对那些人有用的东西,对我不起作用.这是代码,

Hey I'm kinda new to php and wordpress development and I'm just experimenting with how wordpress works and how the themes work. Now I have tried looking this up many times but no help. It was always something different and things that worked for those people, didnt work for me. here is the code,

    <?php

function sandor_hero_cap() {

$wp_customize->add_section('sandor_subhead_title', array(
        'title' => __('Sub-Header', 'sandor'),
));

$wp_customize->add_setting('sandor_subhead_title', array(
        'default' => 'A Virtual PLAYGROUND',
        'capability' => 'edit_theme_options',
        'sanitize_callback' => 'sanitize_text_field'
));

$wp_customize->add_control('sandor_subhead_title', array(
        'label' => __('Sub-Header Title', 'sandor'),
        'section' => 'sandor_subhead_section',
        'priority' => 5,
        'settings' => 'sandor_subhead_title'
));

}

add_action( 'customize_register', 'sandor_hero_cap' );

?>

我得到的错误是:

在functions.php第5行的非对象上调用成员函数add_section()我已经尝试了很多东西,但似乎没有任何效果,希望你们能帮我解决这个问题.谢谢:)

Call to a member function add_section() on a non-object in functions.php line 5 I have tried a lot of things but nothing seems to be working, hopefully you guys can help me solve this issue. thanks :)

推荐答案

您缺少 $wp_customize 参数.而且,如果我没记错的话,为 add_settingadd_control 使用不同的名称可能是一个想法.请参阅下面的代码.

You're missing the $wp_customize argument. And, if I'm not mistaken, it might be an idea to use a different name for add_setting and add_control. See the code below.

function sandor_hero_cap($wp_customize) {

    $wp_customize->add_section('sandor_subhead_title', array(
    'title' => __('Sub-Header', 'sandor'),
));

    $wp_customize->add_setting('sandor_playground', array(
    'default' => 'A Virtual PLAYGROUND',
    'capability' => 'edit_theme_options',
    'sanitize_callback' => 'sanitize_text_field'
));

$wp_customize->add_control('sandor_playground', array(
    'label' => __('Sub-Header Title', 'sandor'),
    'section' => 'sandor_subhead_section',
    'priority' => 5,
    'settings' => 'sandor_subhead_title'
));

}

add_action( 'customize_register', 'sandor_hero_cap' );

这篇关于wordpress 在 functions.php 第 5 行的非对象上调用成员函数 add_section()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆