[wp-trac] [WordPress Trac] #22251: Helper function to simplify checking for constants

WordPress Trac noreply at wordpress.org
Mon Oct 22 05:09:50 UTC 2012


#22251: Helper function to simplify checking for constants
-------------------------+------------------------------
 Reporter:  evansolomon  |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  General      |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |
-------------------------+------------------------------

Comment (by rmccue):

 Replying to [comment:11 MikeSchinkel]:
 > After re-reading your comment I think I see what you are saying. My
 P.O.C. does the following to deal with the issue:
 >
 > {{{
 > /*
 >  * Early in /wp-settings.php
 >  */
 > $wp_const = $wp;
 > unset( $wp );  // Some functions like register_taxonomy() will use $wp
 if it exists.
 > ...
 > $wp = new WP();
 > /*
 >  * This immediately follows the preceding line that assigns new WP() to
 $wp.
 >  */
 > foreach( get_object_vars( $wp_const ) as $property_name =>
 $property_value ) {
 >   $wp->$property_name = $property_value;
 > }
 > unset( $wp_const );
 > }}}

 I really like this, but how do we ensure `$wp` is defined before `wp-
 config.php`? If we don't, there'll be warnings (at least) from PHP. I
 guess adding `$wp = (object) array();` to the top of `wp-config.php` by
 default is probably the easiest way.

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


More information about the wp-trac mailing list