[wp-trac] Re: [WordPress Trac] #7277: page_options doesn't work for plugin pages

WordPress Trac wp-trac at lists.automattic.com
Mon Jul 21 12:41:52 GMT 2008


#7277: page_options doesn't work for plugin pages
---------------------+------------------------------------------------------
 Reporter:  Mr Pete  |        Owner:  anonymous
     Type:  defect   |       Status:  reopened 
 Priority:  normal   |    Milestone:           
Component:  General  |      Version:           
 Severity:  normal   |   Resolution:           
 Keywords:           |  
---------------------+------------------------------------------------------
Comment (by Mr Pete):

 Thanks, donncha (and core team!)

 For future reference, here is generic backward-compatible plugin code that
 should handle all three cases correctly: no nonce, old nonce, whitelist
 nonce.

 {{{
 function myplug_validOptions() {
   global $whitelist_options;
   $whitelist_options['myplug-update'] = array(
 'myplug_opt1','myplug_opt2');
 }

 global $whitelist_options; // (Need this if inside a function)

 if (isset($whitelist_options)) {
   echo '<input name="option_page"  value="myplug-update"
 type="hidden" />';
   add_filter('whitelist_options', 'myplug_validOptions');
   wp_nonce_field('myplug-update-options');
 } else {
   echo '<input name="option_page"  value="update"
 type="hidden" />';
   echo '<input name="page_options" value="myplug_opt1,myplug_opt2"
 type="hidden" />';
   if (function_exists('wp_nonce_field')) wp_nonce_field('update-options');
 }
 }}}

 The code is formatted to highlight the three important bits:
  1. Set option_page ('update' in old scheme, unique in new).
  1. Define valid options via filter (new) or form field (old).
  1. Call wp_nonce_field using option_page value with '-options' appended.

-- 
Ticket URL: <http://trac.wordpress.org/ticket/7277#comment:6>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list