创建WordPress主题:

时间:2015-05-04 08:23:19

标签: wordpress wordpress-theme-customize

我正在尝试创建一个选项面板WordPress主题。选项页面显示正常,但在提交表格后我得到:

  

错误:找不到选项页面。

这是我的代码。

<?php
/*
Plugin Name: Option Man
Description: A test plugin to manage site 
Author: Pravin Mishra
Version: 0.1
*/
add_action('admin_menu', 'test_plugin_setup_menu');
function test_plugin_setup_menu(){
        add_menu_page( 'Option-Man-Plugin', 'Option Man', 'manage_options', 'test-plugin', 'test_init' );

}

function test_init(){

    add_action( 'admin_init', 'register_my_setting' );

function register_my_setting() {
    //register_setting( 'myoptions-group', 'my_option_name', 'intval' ); 
    register_setting(‘myoptions-group’, ‘testplugin_option1′);

    register_setting(‘myoptions-group’, ‘testplugin_option2′);
} 
	echo "Hello world!";
	?>
    <div class="wrap">
        <u><h2>BS3 Custom Options</h2></u>
        <form method="post" action="http://192.168.2.139/web/wp-admin/options.php">
        <?php //settings_fields( 'myoptions-group' );
        //do_settings_sections( 'myoption-group' );
        settings_fields( 'myoptions-group' );
				?>
<input type="text"   name="testplugin-option1" value="<?php echo get_option('testplugin_option1'); ?>"/>
<input type="text"  name="testplugin-option2" value="<?php echo get_option('testplugin_option2'); ?>"/>


				<?php
			submit_button(); 
            ?>
</form>
</div>
<?php
} 
?>

2 个答案:

答案 0 :(得分:1)

<form method="post" action="http://192.168.2.139/web/wp-admin/options.php">更改为<form method="post" action="">

答案 1 :(得分:1)

我已经纠正了代码,现在它工作正常。

add_action('admin_menu', 'test_plugin_setup_menu');
function test_plugin_setup_menu(){
        add_menu_page( 'Option-Man-Plugin', 'Option Man', 'manage_options', __FILE__, 'test_init' );

    add_action( 'admin_init', 'register_my_setting' );
}

function register_my_setting() {
    //register_setting( 'myoptions-group', 'my_option_name', 'intval' ); 
    register_setting('myoptions-group', 'testplugin_option1');

    register_setting('myoptions-group', 'testplugin_option2');
} 

function test_init(){
  ?>
    <div class="wrap">
        <u><h2>BS3 Custom Options</h2></u>
        <form method="post" action="options.php" enctype="multipart/form-data">
        <?php
        settings_fields('myoptions-group');
        do_settings_sections('myoptions-group');
        ?>

<input type="text"   name="testplugin_option1" value="<?php echo get_option('testplugin_option1'); ?>"/>
<input type="text"  name="testplugin_option2" value="<?php echo get_option('testplugin_option2'); ?>"/>


        <?php
      submit_button(); 
            ?>
</form>
</div>
<?php
} 

您的字段名称和选项名称不同,选项页面路径也是错误的。