[wp-trac] [WordPress Trac] #19041: function to list all (true) conditionals (in an array)

WordPress Trac wp-trac at lists.automattic.com
Tue Oct 25 18:08:54 UTC 2011


#19041: function to list all (true) conditionals (in an array)
-----------------------------------+------------------------------
 Reporter:  F J Kaiser             |       Owner:
     Type:  enhancement            |      Status:  new
 Priority:  normal                 |   Milestone:  Awaiting Review
Component:  Query                  |     Version:  3.3
 Severity:  normal                 |  Resolution:
 Keywords:  has-patch 2nd-opinion  |
-----------------------------------+------------------------------

Comment (by F J Kaiser):

 Replying to [comment:2 johnbillion]:
 > Can you post a code snippet where use of this function saves code?

 I currently use it in two classes (breadcrumbs & pagination) for function
 routing/name guessing. It lets me avoid long {{{if/elseif/else}}}
 statements and long {{{switch( $case )}}} statements.

 {{{
 $output = array();
 foreach ( get_conditionals() as $conditional )
 {
     // Can catch everything using a simple string replace:
     $fn_name = str_replace( 'is_', 'get_', $conditional );
     if ( method_exists( __CLASS__, $fn_name ) )
         $output[] = $this->$fn_name( $args );
 }
 }}}

 If someone is not so much into consistant naming, it wouldn't help too
 much. I'm sure there are other use cases that I'm currently not aware of,
 but it's a public API extension that doesn't hurt if you don't use it.

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


More information about the wp-trac mailing list