• Resolved charlener

    (@charlener)


    I’m having trouble migrating my plugin to 2.7 – an issue with options where it’ll show the options page but upon hitting save says “Error! Options page not found.”

    I decided to try a very simple example first to isolate the problem, and it’s still happening. Could someone take a look at this and tell me what I’m doing wrong options-wise? Would greatly appreciate it…and I’ll post later as a generic example for others to use too. The plugin dev docs are kind of fragmented so it’s hard to pull together something without looking at about 10 pages…

    <?php
    /*
    Plugin Name: Test
    Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
    Description: A brief description of the Plugin.
    Version: The Plugin's Version Number, e.g.: 1.0
    Author: Name Of The Plugin Author
    Author URI: http://URI_Of_The_Plugin_Author
    */
    
    function my_plugin_activate() {
    	add_option("test", "12345");
    	register_setting('test-options', 'test');
    }
    
    function my_plugin_menu() {
      add_options_page('My Plugin Options', 'My Plugin', 8, __FILE__, 'my_plugin_options');
    }
    
    function my_plugin_options() {
    	register_setting('test-options', 'test');
    ?>
    	<div class="wrap">
    	<h2>Plugin name</h2>
    	<form method="post" action="options.php">
    	<?php wp_nonce_field('update-options'); ?>
    	<table class="form-table">
    	<tr valign="top">
    	<th scope="row">New Option Name</th>
    	<td><input type="text" name="test" value="<?php echo get_option('test'); ?>" /></td></tr>
    	</table>
    	<?php settings_fields('test-options'); ?>
    	<p class="submit">
    	<input type="submit" name="Submit" value="Save changes" />
    	</p>
    	</form>
    	</div>
    <?php
    }
    
    add_action('admin_menu', 'my_plugin_menu');
    register_activation_hook( __FILE__, 'my_plugin_activate' );
    ?>
Viewing 1 replies (of 1 total)
  • Thread Starter charlener

    (@charlener)

    Thanks to this blog post I figured it out.

    Here’s the modified and working code:

    <?php
    /*
    Plugin Name: Test
    Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
    Description: A brief description of the Plugin.
    Version: The Plugin's Version Number, e.g.: 1.0
    Author: Name Of The Plugin Author
    Author URI: http://URI_Of_The_Plugin_Author
    */
    
    /*  Copyright YEAR  PLUGIN_AUTHOR_NAME  (email : PLUGIN AUTHOR EMAIL)
    
        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    */
    
    function my_plugin_activate() {
    	add_option("test", "12345");
    }
    
    function myplugin_admin_init(){
    	register_setting('test-options', 'test');
    }
    
    function my_plugin_menu() {
      add_options_page('My Plugin Options', 'My Plugin', 8, __FILE__, 'my_plugin_options');
    }
    
    function my_plugin_options() {
    	register_setting('test-options', 'test');
    ?>
    	<div class="wrap">
    	<h2>Plugin name</h2>
    	<form method="post" action="options.php">
    	<?php settings_fields('test-options'); ?>
    	<table class="form-table">
    	<tr valign="top">
    	<th scope="row">New Option Name</th>
    	<td><input type="text" name="test" value="<?php echo get_option('test'); ?>" /></td></tr>
    	</table>
    	<p class="submit">
    	<input type="submit" name="Submit" value="Save changes" />
    	</p>
    	</form>
    	</div>
    <?php
    }
    
    add_action('admin_menu', 'my_plugin_menu');
    add_action( 'admin_init', 'myplugin_admin_init' );
    register_activation_hook( __FILE__, 'my_plugin_activate' );
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘saving options issue with 2.7’ is closed to new replies.