wp_debug_mode

Set PHP error reporting based on WordPress debug settings.

Description

wp_debug_mode(); 

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 debug.log in the content directory.

Errors are never displayed for XML-RPC, REST, and Ajax requests.


Usage

  1. if ( !function_exists( 'wp_debug_mode' ) ) { 
  2. require_once ABSPATH . WPINC . '/load.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_debug_mode(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/load.php  
  1. function wp_debug_mode() { 
  2. /** 
  3. * Filters whether to allow the debug mode check to occur. 
  4. * This filter runs before it can be used by plugins. It is designed for 
  5. * non-web run-times. Returning false causes the `WP_DEBUG` and related 
  6. * constants to not be checked and the default php values for errors 
  7. * will be used unless you take care to update them yourself. 
  8. * @since 4.6.0 
  9. * @param bool $enable_debug_mode Whether to enable debug mode checks to occur. Default true. 
  10. */ 
  11. return; 
  12.  
  13. if ( WP_DEBUG ) { 
  14. error_reporting( E_ALL ); 
  15.  
  16. ini_set( 'display_errors', 1 ); 
  17. elseif ( null !== WP_DEBUG_DISPLAY
  18. ini_set( 'display_errors', 0 ); 
  19.  
  20. if ( WP_DEBUG_LOG ) { 
  21. ini_set( 'log_errors', 1 ); 
  22. ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' ); 
  23. } else { 
  24. 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 ); 
  25.  
  26. if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() ) { 
  27. @ini_set( 'display_errors', 0 );