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

WordPress Trac noreply at wordpress.org
Mon Oct 22 00:32:28 UTC 2012


#22251: Helper function to simplify checking for constants
-----------------------------+-------------------------
 Reporter:  evansolomon      |       Type:  enhancement
   Status:  new              |   Priority:  normal
Milestone:  Awaiting Review  |  Component:  General
  Version:                   |   Severity:  normal
 Keywords:  has-patch        |
-----------------------------+-------------------------
 Love 'em or hate 'em, WordPress uses lots of constants.  As a result, this
 pattern is all over core and plugins, and occasionally themes:

 `if ( defined( 'CONSTANT_NAME' ) && CONSTANT_NAME )`

 Right now on trunk, it's used 57 times (excluding 2 in Akismet).

 {{{
 ~/code/wptrunk $ ack "defined\( ?('|\")([^'\"]+)\1 ?\) \&\& \2" -h
 --ignore-dir=wp-content/plugins/ | wc -l
       57
 }}}

 How about a new function to make that verbose logic a little bit less
 repetitive.

 {{{
 function wp_constant( $constant ) {
         return defined( $constant ) && constant( $constant );
 }
 }}}

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


More information about the wp-trac mailing list