[wp-trac] [WordPress Trac] #40280: Short-circuit filters can't return common values
    WordPress Trac 
    noreply at wordpress.org
       
    Thu Jun  8 19:35:54 UTC 2017
    
    
  
#40280: Short-circuit filters can't return common values
-------------------------+------------------------------
 Reporter:  andy         |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  General      |     Version:  4.8
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:
-------------------------+------------------------------
Comment (by flixos90):
 Revising my previous patch, I think there's a simpler solution to the
 problem. The class itself already does the trick - we don't need new
 functions to short-circuit and can instead use actions and filter hooks as
 we know. Therefore [attachment:40280.2.diff] is the new
 `WP_Short_Circuit_Result` class only, without new functions.
 Possible patch for #37930 (now more clear than the one with the previous
 patch):
 {{{
 #!php
 $short_circuit_result = new WP_Short_Circuit_Result();
 /**
  * Allows to short-circuit the process of retrieving the value of an
 existing option.
  *
  * @since 4.9.0
  *
  * @param WP_Short_Circuit_Result $short_circuit_result Short-circuit
 result to adjust in case the process should be short-circuited.
  * @param string                  $option               Option name.
  * @param mixed                   $default              The default value
 to return if the option does not
  *                                                      exist in the
 database.
  */
 do_action( 'short_circuit_get_option', $short_circuit_result, $option,
 $default );
 if ( $short_circuit_result->short_circuit() ) {
         return $short_circuit_result->value();
 }
 }}}
 The above could of course be a filter as well, but I used an action since
 this makes it unnecessary to return the instance here. Maybe a filter may
 be better for code clarity, but this needs to be discussed.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/40280#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
    
    
More information about the wp-trac
mailing list