在WordPress主题中融入设置API--作者:奇普·贝内特

时间:2013-04-25 作者:Joe

我正在使用Chip Bennett的代码为我的插件创建一个设置选项页面。问题是,我得到一个警告错误,如下所示,我无法找出它。非常感谢您的帮助。

警告:call\\u user\\u func(ch\\u settings\\u defaults\\u style\\u section\\u text)[函数.call user func]:第一个参数应该是/home/loc123/public\\u html/domaindvb中的有效回调。com/wp admin/includes/template。php在线1083

    <?php
function ch_admin_options_page() {
    global $pagenow;
 ?>
    <div class="wrap">
<?php
        /* Calls function to add tabs */
        ch_admin_options_page_tabs ();

        /* adds the "updated" admin notice */
        if ( isset( $_GET[\'settings-updated\'] ) ) {
            echo "<div class=\'updated\'><p>Custom Header settings updated successfully.</p></div>";
        }
?>
        <form action="options.php" method="post">   
            <?php
            settings_fields(\'mycustom_options\');
            do_settings_sections(\'mycustom\');
            ?>
        <?php
        if ( \'themes.php\' == $pagenow && isset( $_GET[\'page\'] ) && \'ch-settings\' == $_GET[\'page\'] ) :
             if ( isset ( $_GET[\'tab\'] ) ) :
                  $tab = $_GET[\'tab\'];
             else:
                  $tab = \'general\';
             endif;
             switch ( $tab ) :
                  case \'general\' :
                require (\'options-register-defaults.php\') ; 
                break;
                  case \'Home Page\' :
                require( \'options-register-homepage.php\' );
                break;
             endswitch;
        endif; 
         ?>
        <p></br></p>

        <input name="mycustom_options[submit-<?php echo $tab; ?>]" type="submit" class="button-primary" value="<?php esc_attr_e(\'Save Settings\', \'default\'); ?>" />

        <?php /* Add a Reset Button */ ?>
        <input name="mycustom_options[reset-<?php echo $tab; ?>]" type="submit" class="button-secondary" value="<?php esc_attr_e(\'Reset Defaults\', \'default\'); ?>" />

        </form>

    </div>
<?php
}
?>

<?php
add_action(\'admin_init\', \'chr_settings\');
function chr_settings() {

    /*  register_setting( $option_group, $option_name, $sanitize_callback )- Associates an option group passed to settings_fields with database entry */
    register_setting( \'mycustom_options\', \'mycustom_options\', \'ch_options_validate\' ); 
    add_settings_section(\'ch_settings_defaults_style\', \'Style Options\', \'ch_settings_defaults_style_section_text\', \'mycustom\');

}
?>
File: options-register-defaults.php

<?php
function ch_settings_defaults_style_section_text() { ?>

     <p><?php _e( \'Manage Header options for the Oenology Theme. Refer to the contextual help screen for descriptions and help regarding each theme option.\', \'mycustom\' ); ?></p>
<?php 
}
?>

1 个回复
SO网友:Ralf912

您应该包括options-register-defaults.php 使回调可用。

function chr_settings() {

require_once \'options-register-defaults.php\'; // add path to file

    /*  register_setting( $option_group, $option_name, $sanitize_callback )- Associates an option group passed to settings_fields with database entry */
    register_setting( \'mycustom_options\', \'mycustom_options\', \'ch_options_validate\' ); 
    add_settings_section(\'ch_settings_defaults_style\', \'Style Options\', \'ch_settings_defaults_style_section_text\', \'mycustom\');

}

结束

相关推荐

暂时授予“Manage_Options”功能

为了允许编辑编辑编辑其他人的author meta(update\\u user\\u属性),我必须给他们“manage\\u options”功能,否则我会收到一条“作弊”消息。我只想在一个特定的编辑作者元页面上给他们这个功能。我为“list\\u users”授予“editor”权限,以访问users admin表。在进入特定的作者元页面时,我授予“编辑器”权限以“管理\\u选项”。(我尝试将其放置在函数save\\u profile\\u字段的顶部,但仍然收到了死亡消息。)我删除了save\\u p