0

我正在尝试为 wordpress 创建一个微笑插件。我需要能够为我的自定义选项更新 get_option() 变量。如果您知道下面的脚本有什么问题,请告诉我。

它将字段添加到数据库并显示设置页面,但当我点击“保存更改”按钮时它不会更新它们。

请让我知道我做错了什么......

我无法从插件的选项页面更改任何选项值...

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

1 回答 1

1

尝试使用update_option()更新选项。

add_option()添加选项但它不会更新它,update_option()如果它不存在也会创建它。

希望这可以帮助。

于 2012-11-09T09:04:41.830 回答