Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在wordpress中创建自定义选项页_Php_Wordpress - Fatal编程技术网

Php 在wordpress中创建自定义选项页

Php 在wordpress中创建自定义选项页,php,wordpress,Php,Wordpress,在为我的wordpress主题在选项页中创建自定义字段时,在每个输入类型文本调用上显示一些错误。\u user\u func()希望参数1是有效回调,类“MySettingsPage”没有方法徽标。\u callback()或social\u callback()。请建议一些解决方案 private$options; 公共函数构造() { 添加操作('admin_menu',数组('bguru_register_options_page'); 添加操作('admin_init',数组('bgu

在为我的wordpress主题在选项页中创建自定义字段时,在每个输入类型文本调用上显示一些错误。\u user\u func()希望参数1是有效回调,类“MySettingsPage”没有方法徽标。\u callback()或social\u callback()。请建议一些解决方案

private$options;
公共函数构造()
{
添加操作('admin_menu',数组('bguru_register_options_page');
添加操作('admin_init',数组('bguru_register_settings');
}
公共功能bguru\u寄存器\u选项\u页面()
{
//此页面将位于“设置”下
添加主题页面(“业务专家选项”,
“主题定制器”,
“编辑主题选项”,
“bguru选项”,
数组($this'bguru\u options\u page')
);
}
公共功能bguru_选项_第页()
{
//设置类属性
$this->options=get_option('bguru_logo');
$this->options=get_option('bguru_vimeo');
?>
商业大师选择

查看代码后,我认为您需要从数组中删除()(“logo\u callback()”)

见以下代码,我已更改和修复:-

class MySettingsPage
{
    private $options;
    public function __construct()
    {
        add_action( 'admin_menu', array( $this, 'bguru_register_options_page' ) );
        add_action( 'admin_init', array( $this, 'bguru_register_settings' ) );
    }

    public function bguru_register_options_page()
    {
        // This page will be under "Settings"
        add_theme_page('Business Guru Options',
                'Theme Customizer',
                'edit_theme_options',
                'bguru-options',
                array( $this, 'bguru_options_page')
        );
    }

    public function bguru_options_page()
    {
        // Set class property
        $this->options['bguru_logo'] = get_option( 'bguru_logo' );
        $this->options['bguru_vimeo'] = get_option( 'bguru_vimeo' );
        ?>
        <div class="wrap">
            <?php screen_icon(); ?>
            <h1>Business Guru Options</h1>
            <form method="post" action="options.php">
                <?php
                // This prints out all hidden setting fields
                settings_fields( 'defaultbg' );
                do_settings_sections( 'defaultbg' );
                submit_button();
                ?>
            </form>
        </div>
        <?php
    }

    public function bguru_register_settings()
    {
        register_setting('defaultbg','bguru_logo',  array( $this, 'sanitize' ) );
        register_setting('defaultbg', 'bguru_vimeo',  array( $this, 'sanitize' ));
        add_settings_section(
                'setting_section_id', // ID
                'General',
                array( $this, 'print_section_info' ), // Callback
                'defaultbg' // Page

        );

        add_settings_field(
                'bguru_logo', // ID
                'Logo', // Title
                array($this,'logo_callback' ), // Callback
                'defaultbg', // Page
                'setting_section_id' // Section
        );

        add_settings_field(
                'bguru_vimeo', // ID
                'Vimeo', // Vimeo
                array( $this, 'socialv_callback' ), // Callback
                'defaultbg', // Page
                'setting_section_id' // Section
        );
    }

    public function sanitize( $input )
    {
        $new_input = array();

        if( isset( $input['bguru_logo'] ) )
            $new_input['bguru_logo'] = sanitize_text_field( $input['bguru_logo'] );

        if( isset( $input['bguru_vimeo'] ) )
            $new_input['bguru_vimeo'] = sanitize_text_field( $input['bguru_vimeo'] );

        return $new_input;
    }
    public function print_section_info()
    {
        print 'Enter your settings below:';
    }

    public function logo_callback()
    {
        printf('<input type="text" id="bguru_logo"  size="50" name="bguru_logo" value="%s" />',
                isset( $this->options['bguru_logo'] ) ? esc_attr( $this->options['bguru_logo']) : ''
        );
    }

    public function socialv_callback()
    {
        printf('<input type="text" id="bguru_vimeo"  size="50" name="bguru_vimeo" value="%s" />',
                isset( $this->options['bguru_vimeo'] ) ? esc_attr( $this->options['bguru_vimeo']) : ''
        );
    }
}
if( is_admin() )
    $my_settings_page = new MySettingsPage();
classmysettingspage
{
私人美元期权;
公共函数构造()
{
添加操作('admin_menu',数组('bguru_register_options_page');
添加操作('admin_init',数组('bguru_register_settings');
}
公共功能bguru\u寄存器\u选项\u页面()
{
//此页面将位于“设置”下
添加主题页面(“业务专家选项”,
“主题定制器”,
“编辑主题选项”,
“bguru选项”,
数组($this'bguru\u options\u page')
);
}
公共功能bguru_选项_第页()
{
//设置类属性
$this->options['bguru_logo']=get_选项('bguru_logo');
$this->options['bguru_vimeo']=get_option('bguru_vimeo');
?>
商业大师选择

感谢akshay的工作,但在提交所有信息后,我的输入标签中仍然存在一个问题。保存的信息很清楚。你能给我建议一些解决方案,以便在提交表单后保存填写信息吗?请参阅我的更新答案,我在
bguru\u options\u page()中添加了更改
function.akshay我认为您只对printf(
在此处输入代码
)函数做了一次更改,但它没有解决我的问题,并且显示了一些语法错误,意外的“
$this->options['bguru\u logo']&$this->options['bguru\u vimeo']
我已经添加了这个。好的,akshay仍然在第584行的C:\xampp\htdocs\wordpress\wp includes\formatting.php中显示了通知数组到字符串的转换
class MySettingsPage
{
    private $options;
    public function __construct()
    {
        add_action( 'admin_menu', array( $this, 'bguru_register_options_page' ) );
        add_action( 'admin_init', array( $this, 'bguru_register_settings' ) );
    }

    public function bguru_register_options_page()
    {
        // This page will be under "Settings"
        add_theme_page('Business Guru Options',
                'Theme Customizer',
                'edit_theme_options',
                'bguru-options',
                array( $this, 'bguru_options_page')
        );
    }

    public function bguru_options_page()
    {
        // Set class property
        $this->options['bguru_logo'] = get_option( 'bguru_logo' );
        $this->options['bguru_vimeo'] = get_option( 'bguru_vimeo' );
        ?>
        <div class="wrap">
            <?php screen_icon(); ?>
            <h1>Business Guru Options</h1>
            <form method="post" action="options.php">
                <?php
                // This prints out all hidden setting fields
                settings_fields( 'defaultbg' );
                do_settings_sections( 'defaultbg' );
                submit_button();
                ?>
            </form>
        </div>
        <?php
    }

    public function bguru_register_settings()
    {
        register_setting('defaultbg','bguru_logo',  array( $this, 'sanitize' ) );
        register_setting('defaultbg', 'bguru_vimeo',  array( $this, 'sanitize' ));
        add_settings_section(
                'setting_section_id', // ID
                'General',
                array( $this, 'print_section_info' ), // Callback
                'defaultbg' // Page

        );

        add_settings_field(
                'bguru_logo', // ID
                'Logo', // Title
                array($this,'logo_callback' ), // Callback
                'defaultbg', // Page
                'setting_section_id' // Section
        );

        add_settings_field(
                'bguru_vimeo', // ID
                'Vimeo', // Vimeo
                array( $this, 'socialv_callback' ), // Callback
                'defaultbg', // Page
                'setting_section_id' // Section
        );
    }

    public function sanitize( $input )
    {
        $new_input = array();

        if( isset( $input['bguru_logo'] ) )
            $new_input['bguru_logo'] = sanitize_text_field( $input['bguru_logo'] );

        if( isset( $input['bguru_vimeo'] ) )
            $new_input['bguru_vimeo'] = sanitize_text_field( $input['bguru_vimeo'] );

        return $new_input;
    }
    public function print_section_info()
    {
        print 'Enter your settings below:';
    }

    public function logo_callback()
    {
        printf('<input type="text" id="bguru_logo"  size="50" name="bguru_logo" value="%s" />',
                isset( $this->options['bguru_logo'] ) ? esc_attr( $this->options['bguru_logo']) : ''
        );
    }

    public function socialv_callback()
    {
        printf('<input type="text" id="bguru_vimeo"  size="50" name="bguru_vimeo" value="%s" />',
                isset( $this->options['bguru_vimeo'] ) ? esc_attr( $this->options['bguru_vimeo']) : ''
        );
    }
}
if( is_admin() )
    $my_settings_page = new MySettingsPage();