如何创建多个顶级管理菜单页面以将数据提交到Options表?

时间:2013-11-27 作者:Amen Ra

我试图在wordpress主题中创建多个顶级选项页面。但现在我只能保存一个的数据。如何在不必创建选项卡式面板的情况下为两个人保存数据?

// create custom plugin settings menu
add_action(\'admin_menu\', \'baw_create_menu\');

function baw_create_menu() {

//create new top-level menu
 add_menu_page(\'BAW Plugin Settings\', \'BAW Settings\', \'administrator\', \'baw-settings\', \'baw_settings_page\');

//call register settings function
add_action( \'admin_init\', \'register_mysettings\' );
}


function register_mysettings() {
//register our settings
register_setting( \'baw-settings-group\', \'new_option_name\' );
register_setting( \'baw-settings-group\', \'some_other_option\' );
register_setting( \'baw-settings-group\', \'option_etc\' );
}

function baw_settings_page() {
?>
<div class="wrap">
<h2>Your Plugin Name</h2>

<form method="post" action="options.php">
<?php settings_fields( \'baw-settings-group\' ); ?>
<?php do_settings_sections( \'baw-settings-group\' ); ?>
<table class="form-table">
    <tr valign="top">
    <th scope="row">New Option Name</th>
    <td><input type="text" name="new_option_name" value="<?php echo get_option(\'new_option_name\'); ?>" /></td>
    </tr>

    <tr valign="top">
    <th scope="row">Some Other Option</th>
    <td><input type="text" name="some_other_option" value="<?php echo get_option(\'some_other_option\'); ?>" /></td>
    </tr>

    <tr valign="top">
    <th scope="row">Options, Etc.</th>
    <td><input type="text" name="option_etc" value="<?php echo get_option(\'option_etc\'); ?>" /></td>
    </tr>
</table>

<?php submit_button(); ?>

   </form>
   </div>
   <?php 
}


// create second custom plugin settings menu
add_action(\'admin_menu\', \'bax_create_menu\');

function bax_create_menu() {

//create new top-level menu
add_menu_page(\'BAX Plugin Settings\', \'BAX Settings\', \'administrator\', \'bax-settings\', \'bax_settings_page\');

//call register settings function
add_action( \'admin_init\', \'register_settings\' );
}


function register_settings() {
//register our settings
register_setting( \'bax-settings-group\', \'option_name\' );
register_setting( \'bax-settings-group\', \'other_option\' );
register_setting( \'bax-settings-group\', \'etc\' );
}

function bax_settings_page() {
?>
<div class="wrap">
<h2>Your Plugin Name</h2>

<form method="post" action="options.php">
<?php settings_fields( \'bax-settings-group\' ); ?>
<?php do_settings_sections( \'bax-settings-group\' ); ?>
<table class="form-table">
    <tr valign="top">
    <th scope="row">New Option Name</th>
    <td><input type="text" name="new_option_name" value="<?php echo get_option(\'option_name\'); ?>" /></td>
    </tr>

    <tr valign="top">
    <th scope="row">Some Other Option</th>
    <td><input type="text" name="some_other_option" value="<?php echo get_option(\'other_option\'); ?>" /></td>
    </tr>

    <tr valign="top">
    <th scope="row">Options, Etc.</th>
    <td><input type="text" name="option_etc" value="<?php echo get_option(\'etc\'); ?>" /></td>
    </tr>
</table>

<?php submit_button(); ?>

</form>
</div>
<?php 
}

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

我找到了答案!!我遇到的问题是有多个表单被提交到选项数据库。我找到了一个解决此问题的教程:

WordPress设置API:同一页上有多个表单

http://www.mendoweb.be/blog/wordpress-settings-api-multiple-forms-on-same-page/

结束

相关推荐

Multi Upload In Theme Options

我需要在主题选项页面上使用WordPress媒体上传。它需要能够在一个页面上有多个字段。我在网站上看到了一些使用搜索的东西,但没有最新的,也没有我能找到的工作。有人能告诉我一个简单的方法吗。确实希望使用新的库样式,从媒体库中选择图片,或选择上载。