wp_debug_mode()
- Since
- 3.0.0, 5.1.0
- Source
wp-includes/load.php:578
Description
Uses three constants: WP_DEBUG, WP_DEBUG_DISPLAY, and WP_DEBUG_LOG.
All three can be defined in wp-config.php. By default, WP_DEBUG and WP_DEBUG_LOG are set to false, and WP_DEBUG_DISPLAY is set to true.
When WP_DEBUG is true, all PHP notices are reported. WordPress will also display internal notices: when a deprecated WordPress function, function argument, or file is used. Deprecated code may be removed from a later version.
It is strongly recommended that plugin and theme developers use WP_DEBUG in their development environments.
WP_DEBUG_DISPLAY and WP_DEBUG_LOG perform no function unless WP_DEBUG is true.
When WP_DEBUG_DISPLAY is true, WordPress will force errors to be displayed.WP_DEBUG_DISPLAY defaults to true. Defining it as null prevents WordPress from changing the global configuration setting. Defining WP_DEBUG_DISPLAY as false will force errors to be hidden.
When WP_DEBUG_LOG is true, errors will be logged to wp-content/debug.log.
When WP_DEBUG_LOG is a valid path, errors will be logged to the specified file.
Errors are never displayed for XML-RPC, REST, ms-files.php, and Ajax requests.
Compatibility
- WordPress
- since 5.1.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Performance profile
How much work a call to wp_debug_mode() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 6–62
- Plugin surface
- 1 hook
- Called by
- 0
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 75.
Third-party callbacks on 'enable_wp_debug_mode_checks' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()called directly
What one call costs · 21 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_debug_mode() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!apply_filters() | 6 | apply_filters() |
apply_filters() | 17–25 | apply_filters(), error_reporting(), ini_set() |
apply_filters() && !defined('XMLRPC_REQUEST') && !defined('REST_REQUEST') && !defined('MS_FILES_REQUEST') && !wp_doing_ajax() && !wp_is_json_request() | 25–27 | apply_filters(), error_reporting(), wp_doing_ajax(), wp_is_json_request() |
apply_filters() && !defined('XMLRPC_REQUEST') && !defined('REST_REQUEST') && !defined('MS_FILES_REQUEST') && wp_doing_ajax() | 26–28 | apply_filters(), error_reporting(), wp_doing_ajax(), ini_set() |
apply_filters() && !defined('XMLRPC_REQUEST') && !defined('REST_REQUEST') && !defined('MS_FILES_REQUEST') && !wp_doing_ajax() && wp_is_json_request() | 29–31 | apply_filters(), error_reporting(), wp_doing_ajax(), wp_is_json_request(), ini_set() |
apply_filters() | 33–43 | apply_filters(), error_reporting(), strtolower(), ini_set() |
apply_filters() | 35–47 | apply_filters(), error_reporting(), ini_set(), strtolower(), ini_set() |
apply_filters() && !defined('XMLRPC_REQUEST') && !defined('REST_REQUEST') && !defined('MS_FILES_REQUEST') && !wp_doing_ajax() && !wp_is_json_request() | 41–45 | apply_filters(), error_reporting(), strtolower(), wp_doing_ajax(), wp_is_json_request() |
apply_filters() && !defined('XMLRPC_REQUEST') && !defined('REST_REQUEST') && !defined('MS_FILES_REQUEST') && wp_doing_ajax() | 42–46 | apply_filters(), error_reporting(), strtolower(), wp_doing_ajax(), ini_set() |
apply_filters() | 42–52 | apply_filters(), error_reporting(), strtolower(), ini_set(), ini_set(), ini_set() |
apply_filters() && !defined('XMLRPC_REQUEST') && !defined('REST_REQUEST') && !defined('MS_FILES_REQUEST') && !wp_doing_ajax() && !wp_is_json_request() | 43–49 | apply_filters(), error_reporting(), ini_set(), strtolower(), wp_doing_ajax(), wp_is_json_request() |
apply_filters() && !defined('XMLRPC_REQUEST') && !defined('REST_REQUEST') && !defined('MS_FILES_REQUEST') && wp_doing_ajax() | 44–50 | apply_filters(), error_reporting(), ini_set(), strtolower(), wp_doing_ajax(), ini_set() |
9 further outcomes, up to 62 instructions
apply_filters() | 44–56 | apply_filters(), error_reporting(), ini_set(), strtolower(), ini_set(), ini_set(), ini_set() |
apply_filters() && !defined('XMLRPC_REQUEST') && !defined('REST_REQUEST') && !defined('MS_FILES_REQUEST') && !wp_doing_ajax() && wp_is_json_request() | 45–49 | apply_filters(), error_reporting(), strtolower(), wp_doing_ajax(), wp_is_json_request(), ini_set() |
apply_filters() && !defined('XMLRPC_REQUEST') && !defined('REST_REQUEST') && !defined('MS_FILES_REQUEST') && !wp_doing_ajax() && wp_is_json_request() | 47–53 | apply_filters(), error_reporting(), ini_set(), strtolower(), wp_doing_ajax(), wp_is_json_request(), ini_set() |
apply_filters() && !defined('XMLRPC_REQUEST') && !defined('REST_REQUEST') && !defined('MS_FILES_REQUEST') && !wp_doing_ajax() && !wp_is_json_request() | 50–54 | apply_filters(), error_reporting(), strtolower(), ini_set(), ini_set(), wp_doing_ajax(), wp_is_json_request() |
apply_filters() && !defined('XMLRPC_REQUEST') && !defined('REST_REQUEST') && !defined('MS_FILES_REQUEST') && wp_doing_ajax() | 51–55 | apply_filters(), error_reporting(), strtolower(), ini_set(), ini_set(), wp_doing_ajax(), ini_set() |
apply_filters() && !defined('XMLRPC_REQUEST') && !defined('REST_REQUEST') && !defined('MS_FILES_REQUEST') && !wp_doing_ajax() && !wp_is_json_request() | 52–58 | apply_filters(), error_reporting(), ini_set(), strtolower(), ini_set(), ini_set(), wp_doing_ajax(), wp_is_json_request() |
apply_filters() && !defined('XMLRPC_REQUEST') && !defined('REST_REQUEST') && !defined('MS_FILES_REQUEST') && wp_doing_ajax() | 53–59 | apply_filters(), error_reporting(), ini_set(), strtolower(), ini_set(), ini_set(), wp_doing_ajax(), ini_set() |
apply_filters() && !defined('XMLRPC_REQUEST') && !defined('REST_REQUEST') && !defined('MS_FILES_REQUEST') && !wp_doing_ajax() && wp_is_json_request() | 54–58 | apply_filters(), error_reporting(), strtolower(), ini_set(), ini_set(), wp_doing_ajax(), wp_is_json_request(), ini_set() |
apply_filters() && !defined('XMLRPC_REQUEST') && !defined('REST_REQUEST') && !defined('MS_FILES_REQUEST') && !wp_doing_ajax() && wp_is_json_request() | 56–62 | apply_filters(), error_reporting(), ini_set(), strtolower(), ini_set(), ini_set(), wp_doing_ajax(), wp_is_json_request(), ini_set() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 75 instructions, 6–62 executed per call, 14 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while wp_debug_mode() runs, in this order:
- apply_filters( enable_wp_debug_mode_checks )filterline 609 (+31 into the body)
Filters whether to allow the debug mode check to occur.
Uses · 3
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_doing_ajax()Determines whether the current request is a WordPress Ajax request.
- wp_is_json_request()Checks whether current request is a JSON request, or is expecting a JSON response.
Source code
function wp_debug_mode() { /** * Filters whether to allow the debug mode check to occur. * * This filter runs before it can be used by plugins. It is designed for * non-web runtimes. Returning false causes the `WP_DEBUG` and related * constants to not be checked and the default PHP values for errors * will be used unless you take care to update them yourself. * * To use this filter you must define a `$wp_filter` global before * WordPress loads, usually in `wp-config.php`. * * Example: * * $GLOBALS['wp_filter'] = array( * 'enable_wp_debug_mode_checks' => array( * 10 => array( * array( * 'accepted_args' => 0, * 'function' => function() { * return false; * }, * ), * ), * ), * ); * * @since 4.6.0 * * @param bool $enable_debug_mode Whether to enable debug mode checks to occur. Default true. */ if ( ! apply_filters( 'enable_wp_debug_mode_checks', true ) ) { return; } if ( WP_DEBUG ) { error_reporting( E_ALL ); if ( WP_DEBUG_DISPLAY ) { ini_set( 'display_errors', 1 ); } elseif ( null !== WP_DEBUG_DISPLAY ) { ini_set( 'display_errors', 0 ); } if ( in_array( strtolower( (string) WP_DEBUG_LOG ), array( 'true', '1' ), true ) ) { $log_path = WP_CONTENT_DIR . '/debug.log'; } elseif ( is_string( WP_DEBUG_LOG ) ) { $log_path = WP_DEBUG_LOG; } else { $log_path = false; } if ( $log_path ) { ini_set( 'log_errors', 1 ); ini_set( 'error_log', $log_path ); } } else { error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR ); } /* * The 'REST_REQUEST' check here is optimistic as the constant is most * likely not set at this point even if it is in fact a REST request. */ if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || defined( 'MS_FILES_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() || wp_is_json_request() ) { ini_set( 'display_errors', 0 ); }}Changelog
Introduced in 3.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
WP_DEBUG_LOG can be a file path.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/load.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.