[wp-trac] [WordPress Trac] #16577: The register_setting function doesn't exist in Network Admin area

WordPress Trac wp-trac at lists.automattic.com
Thu Feb 17 21:50:54 UTC 2011


#16577: The register_setting function doesn't exist in Network Admin area
-------------------------------------+------------------------------
 Reporter:  cgrymala                 |       Owner:
     Type:  defect (bug)             |      Status:  new
 Priority:  normal                   |   Milestone:  Awaiting Review
Component:  Plugins                  |     Version:  3.1
 Severity:  normal                   |  Resolution:
 Keywords:  needs-codex 2nd-opinion  |
-------------------------------------+------------------------------

Comment (by cgrymala):

 If you look at the source of the class-extended-super-admins.php file for
 version 0.4a of the [http://wordpress.org/extend/plugins/extended-super-
 admins/ Extended Super Admins] plugin (function excerpted below - the
 function shown below is hooked to the 'init' action), you will see how I
 was trying to use the register_setting function.

 Version 0.5a now uses the add_filter() function if the register_setting()
 function is not available. Keep in mind that I am talking about using this
 within the '''Network Admin''' area, not the '''Site Admin''' area.



 {{{
                 function _init() {
                         if( function_exists( 'load_plugin_textdomain' ) )
                                 load_plugin_textdomain( ESA_TEXT_DOMAIN,
 false, ESA_PLUGIN_PATH . '/lang/' );

                         if( is_admin() && isset( $_REQUEST['page'] ) &&
 $_REQUEST['page'] == ESA_OPTIONS_PAGE ) {
                                 if( function_exists( 'register_setting' )
 )
                                         register_setting( ESA_OPTION_NAME,
 ESA_OPTION_NAME, array( $this, 'verify_options' ) );
                                 if( function_exists( 'wp_enqueue_script' )
 ) {
                                         wp_enqueue_script(
 'esa_admin_scripts' );
                                 }

                                 if( function_exists( 'wp_enqueue_style' )
 ) {
                                         wp_enqueue_style(
 'esa_admin_styles' );
                                 }
                         }
                 }

 }}}

 In earlier versions of the plugin, I was getting a PHP error about the
 fact that the `register_setting()` function didn't exist, which is why I
 added the check to see if the function exists or not.

 As I said, in version 0.5a of the plugin (and beyond), I started using the
 following function to get around the issue.

 {{{
                 function _init() {
                         if( function_exists( 'load_plugin_textdomain' ) )
                                 load_plugin_textdomain( ESA_TEXT_DOMAIN,
 false, ESA_PLUGIN_PATH . '/lang/' );

                         if( is_admin() && isset( $_REQUEST['page'] ) &&
 $_REQUEST['page'] == ESA_OPTIONS_PAGE ) {
                                 if( function_exists( 'register_setting' )
 )
                                         register_setting( ESA_OPTION_NAME,
 ESA_OPTION_NAME, array( $this, 'verify_options' ) );
                                 else
                                         add_filter( 'sanitize_option_' .
 ESA_OPTION_NAME, array( $this, 'verify_options' ) );
                                 if( function_exists( 'wp_enqueue_script' )
 ) {
                                         wp_enqueue_script(
 'esa_admin_scripts' );
                                 }

                                 if( function_exists( 'wp_enqueue_style' )
 ) {
                                         wp_enqueue_style(
 'esa_admin_styles' );
                                 }
                         }
                 }
 }}}

 Just in case it makes a difference, here is how I'm instantiating the
 class for my plugin (includes a check to see if any of the multi-network
 plugins are installed, as well):
 {{{
 function instantiate_extended_super_admins() {
         if( !is_multisite() )
                 return;
         if( is_multinetwork() ) {
                 require_once( 'class-wpmn_super_admins.php' );
                 $wpsa = new wpmn_super_admins;
                 $wpsa->is_multi_network = true;
                 return $wpsa;
         } else {
                 require_once( 'class-extended_super_admins.php' );
                 $wpsa = new extended_super_admins;
                 $wpsa->is_multi_network = false;
                 return $wpsa;
         }
 }
 add_action( 'plugins_loaded', 'instantiate_extended_super_admins' );
 }}}

 Then, within the `__construct()` method of my class, I have the following
 call:
 {{{
                         add_action( 'init', array( $this, '_init' ) );
 }}}

 With version 0.4a of the plugin (using just the `register_setting()`
 function), everything worked fine in version 3.0.5 of WordPress. However,
 in version 3.1, the `register_setting()` function is unavailable.

 I hope this helps. Thank you.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/16577#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list