Creating options page for plugin in PHP: get_option()

admin

Administrator
Staff member
I am trying to create a smile plugin for wordpress. I need to be able to update the get_option() variables for my custom options. Please let me know if you know what is wrong with the script below.

It will add the fields to the database and display the settings page but it will not Update them when I hit "Save changes" button.

Please let me know what's I'm doing wrong...

<strong>I cannot change any option values from the options page of my plugin...</strong>

Code:
&gt; &lt;?php /* Plugin Name: Mobile Marketing Mob plugin Plugin URI:
&gt; http://www.example.co Description: A Simple plugin
&gt; Version: 1.0 Author: TxtClub Author URI:
&gt; http://www.example.com License: GPL
&gt; */
&gt; 
&gt; 
&gt; /* Runs when plugin is activated */
&gt; register_activation_hook(__FILE__,'mmm_install'); 
&gt; 
&gt; /* Runs on plugin deactivation*/ register_deactivation_hook( __FILE__,
&gt; 'mmm_remove' );
&gt; 
&gt; function mmm_install() { /* Creates new database field */
&gt; add_option("mmm-token", 'e.g. 14859298165079c736f31a6', '', 'yes');
&gt; add_option("mmm-spliton", '0', '', 'yes'); add_option("mmm-senderid",
&gt; 'e.g. Chico\'s Garage', '', 'yes'); }
&gt; 
&gt; function mmm_remove() { /* Deletes the database field */
&gt; delete_option('mmm-token'); delete_option('mmm-spliton');
&gt; delete_option('mmm-senderid'); }
&gt; 
&gt; 
&gt; 
&gt; //create custom options page add_action( 'admin_menu',
&gt; 'my_plugin_menu' );
&gt; 
&gt; function my_plugin_menu() { $page_title = 'Mobile Marketing Mob
&gt; Settings'; $menu_title = 'MMM Settings'; $capability =
&gt; 'manage_options'; $menu_slug = 'mobile-marketing-mob-settings';
&gt; $function = 'my_plugin_options'; add_options_page( $page_title,
&gt; $menu_title, $capability, $menu_slug, $function );
&gt; 
&gt; 
&gt; add_action( 'admin_init', 'register_mysettings' ); }
&gt; 
&gt; function register_mysettings() {  //register our settings
&gt;   register_setting( 'mmm-options-group', 'mmm-token' );
&gt;   register_setting( 'mmm-options-group', 'mmm-spliton' );
&gt;   register_setting( 'mmm-options-group', 'mmm-senderid' ); }
&gt; 
&gt; 
&gt; 
&gt; function my_plugin_options() {    if ( !current_user_can(
&gt; 'manage_options' ) )  {       wp_die( __( 'You do not have sufficient
&gt; permissions to access this page.' ) );    }   else { ?&gt; &lt;h2&gt; Mobile
&gt; Marketing Mob Settings &lt;/h2&gt;
&gt;       
&gt;         
&gt;         &lt;form method="post" action="&lt;?php $_SERVER['PHP_SELF']?&gt;"&gt;
&gt;     &lt;?php settings_fields( 'mmm-options-group' ); ?&gt;
&gt;     &lt;!-- Wordpress documentation is wrong and suggests do_settings (which is for older versions below 2.7) --&gt;
&gt;     &lt;?php do_settings_sections( 'mmm-options-group' ); ?&gt;
&gt;     &lt;table class="form-table"&gt;
&gt;         &lt;tr valign="top"&gt;
&gt;         &lt;th scope="row"&gt;Unique token&lt;/th&gt;
&gt;         &lt;td&gt;&lt;input type="text" name="mmm-token" value="&lt;?php echo get_option('mmm-token'); ?&gt;" /&gt;&lt;/td&gt;
&gt;         &lt;/tr&gt;
&gt;          
&gt;         &lt;tr valign="top"&gt;
&gt;         &lt;th scope="row"&gt;Split test on&lt;/th&gt;
&gt;         &lt;td&gt;&lt;input type="text" name="mmm-spliton" value="&lt;?php echo get_option('mmm-spliton'); ?&gt;" /&gt;  (0 = off  1 = on)&lt;/td&gt;
&gt;         &lt;/tr&gt;
&gt;         
&gt;         &lt;tr valign="top"&gt;
&gt;         &lt;th scope="row"&gt;Sender ID&lt;/th&gt;
&gt;         &lt;td&gt;&lt;input type="text" name="mmm-senderid" value="&lt;?php echo get_option('mmm-senderid'); ?&gt;" /&gt;&lt;/td&gt;
&gt;         &lt;/tr&gt;
&gt;     &lt;/table&gt;
&gt;     
&gt;     &lt;?php submit_button(); ?&gt;
&gt; 
&gt; &lt;/form&gt; &lt;/div&gt;
&gt;         
&gt;         
&gt;           &lt;?php } } ?&gt;