php - Wordpress plugin development --- upgrade routine: Interaction with user confirmation -


i try develop wordpress plugin, can upgraded smoothly , more importantly, want user choose whether upgrade or not.

i got there, have refresh plugin setting page manually see upgrade complished.

to make question more clear, let see following code:

<?php class myplugin_admin_setting_class {     private $options;     public function __construct()     {         add_action('admin_menu', array(             $this,             'myplugin_admin_menu'         ));         add_action('admin_init', array(             $this,             'myplugin_admin_init'         ));     }     public function myplugin_admin_menu()     {         add_options_page('my plugin setting page', 'myplugin', 'manage_options', 'myplugin', array(             $this,             'myplugin_admin_page'         ));     }     public function myplugin_admin_page()     {         $this->options = get_option('myplugin_options'); ?>         <div class="wrap">             <form action='options.php', method='post'>                 <?php         setting_fields('myplugin_admin_page');         do_settings_sections('myplugin_admin_page');         submit_button('upgrade'); ?>         </form>         </div>         <?php     }     public function myplugin_admin_init()     {         register_setting('myplugin_upgrade_page', 'myplugin_options');         add_settings_section('myplugin_version', //section id         __('version infomation', 'myplugin') , 'myplugin_upgrade_callback', 'myplugin_upgrade_page'         //page         );         add_settings_field('ver', 'current version:', array(             $this,             'myplugin_upgrade_render'         ) , 'myplugin_upgrade_page', //page         'myplugin_version', //section         array(             'field' => 'ver'         ));         add_settings_field('upgrade_confirm', 'upgrade?', array(             $this,             'myplugin_upgrade_confirm_render'         ) , 'myplugin_upgrade_page', //page         'myplugin_version', //section         array(             'field' => 'upgrade_confirm'         ));     }     public function myplugin_upgrade_render($args)     {         $this->options = get_option('myplugin_options');         $field = $args['field'];         $value = $this->options['ver'];         //we add hidden filed save 'ver' option         echo "<input type='text' size='4' disabled='disabled' value='<?php         echo $value; ?>'>";         echo "<input name='myplugin_options[<?php         echo $field; ?>]' type='hidden'  value='<?php         echo $value; ?>'>";     }     public function myplugin_upgrade_confirm_render($args)     {         $this->options = get_option('myplugin_options');         $field = $args['field'];         $value = $this->options['upgrade_confirm']; ?>         <input type="checkbox" name="myplugin_options[<?php         echo $field; ?>]" id="<?php         echo $field; ?>" <?php         checked($value, true); ?> value="1" />         <?php     }     public function myplugin_upgrade_callback()     {         //check user option of upgrade true/false         if ($this->options['upgrade_confirm']) {             echo "do upgrade!"; //the fake code             $options = get_option('myplugin_options');             $options['upgrade_confirm'] = false; // no upgrade again             $options['ver'] = 'new version'; //update 'ver' filed             update_option('myplugin_options', $options);             //i want add function/action/filter here refresh setting page failed.          }     } } 

in above code, add admin menu called myplugin, has page(called myplugin_admin_page) generated function myplugin_admin_page(). page includes section called myplugin_version filed called ver, real render of filed done myplugin_upgrade_render(). in add_settings_section() have callback myplugin_upgrade_callback(), real upgrade.

the problem that, although data written database correctly clicking on upgrade button, seems setting page not automatically refreshed (i note there notification says settings saved, maybe reload page then?), since on setting page field ver not change @ all.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -