[wp-trac] [WordPress Trac] #50896: Add filters to wp_get_environment_type()

WordPress Trac noreply at wordpress.org
Tue Aug 11 18:09:49 UTC 2020


#50896: Add filters to wp_get_environment_type()
----------------------------+------------------------------
 Reporter:  crstauf         |       Owner:  (none)
     Type:  enhancement     |      Status:  new
 Priority:  normal          |   Milestone:  Awaiting Review
Component:  Bootstrap/Load  |     Version:  trunk
 Severity:  normal          |  Resolution:
 Keywords:                  |     Focuses:
----------------------------+------------------------------

Comment (by crstauf):

 Replying to [comment:5 crstauf]:
 > a solution that does not use two static variables is (feeling) unlikely
 to be simple or elegant.

 So glad I was wrong; this is much more elegant, though perhaps slightly
 less performant:

 {{{#!php
 <?php
 function wp_get_environment_type() {
         static $cached_env = '';

         if ( $cached_env ) {
                 return $cached_env;
         }

         ...

         if ( did_action( 'muplugins_loaded' ) ) {
                 $cached_env = $current_env;
         }

         return $current_env;
 }
 }}}

 I used `$cached_env` just to be descriptive; there's probably a more
 appropriate variable name.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/50896#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list