[wp-trac] [WordPress Trac] #58855: Fix and enhance wp_in_development_mode() to be able to return whether a development mode is beiung used

WordPress Trac noreply at wordpress.org
Thu Jul 20 05:54:53 UTC 2023


#58855: Fix and enhance wp_in_development_mode() to be able to return whether a
development mode is beiung used
-------------------------+---------------------
 Reporter:  azaozz       |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  6.4
Component:  General      |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:
-------------------------+---------------------

Comment (by costdev):

 Some possible configurations that may help clarify the differences in
 possible usage:

 Remote work on a staging site.
 {{{
 Development mode: 'theme'
 Environment type: 'staging'
 WP_DEBUG: false
 }}}

 An issue that's happening on production but not locally or on a staging
 site, causing confusion.
 {{{
 Development mode: ''
 Environment type: 'production'
 WP_DEBUG: true
 WP_DEBUG_DISPLAY: false
 WP_DEBUG_LOG: true
 }}}

 While development work ''should'' always be done locally first, and
 staging ''should'' always be 1:1 with production, we know that's not
 always the case, nor always available. Having the fine-grained control

 -----

 Regarding:
 > `wp_is_development_mode()` returning `true` (or
 `wp_get_development_mode()` returning a non-empty value)

 I don't believe there would be a difference. If it's a valid value,
 `wp_get_development_mode()` should return that value.

 However, we have a snag: `''` is a valid value in
 `wp_get_development_mode()`. Casting it to boolean would mean
 `wp_in_development_mode( '' )` would always return `false`, even though
 explicitly checking for `''` should be `true` based on `default-
 constants.php`.

 Note the description of `wp_is_development_mode()`:
  Checks whether the site is in **the given development mode**.
 (my emphasis)

 From what I can tell, these changes to `wp_is_development_mode()` should
 suffice:
 - Make `$mode` optional with a default value of `null`.
 - Change the first guard to:
 {{{#!php
 if ( empty( $current_mode ) ) {
     return '' === $mode;
 }
 }}}
 See [https://3v4l.org/dvnNh 3v4l].

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


More information about the wp-trac mailing list