The enable_wp_debug_mode_checks WordPress PHP filter allows you to control whether the debug mode check should occur or not. It’s particularly useful for non-web runtimes.
Usage
add_filter('enable_wp_debug_mode_checks', 'your_custom_function_name'); function your_custom_function_name($enable_debug_mode) { // your custom code here return $enable_debug_mode; }
Parameters
- $enable_debug_mode (bool): Determines if the debug mode checks should be enabled (default is true).
More information
See WordPress Developer Resources: enable_wp_debug_mode_checks
Examples
Disable Debug Mode Checks
Disable WP_DEBUG and related constants checks, relying on default PHP values for errors.
add_filter('enable_wp_debug_mode_checks', 'disable_debug_mode_checks'); function disable_debug_mode_checks($enable_debug_mode) { return false; }
Enable Debug Mode Checks
Ensure that debug mode checks are enabled.
add_filter('enable_wp_debug_mode_checks', 'enable_debug_mode_checks'); function enable_debug_mode_checks($enable_debug_mode) { return true; }
Conditional Debug Mode Checks
Enable debug mode checks only when on the staging environment.
add_filter('enable_wp_debug_mode_checks', 'conditional_debug_mode_checks'); function conditional_debug_mode_checks($enable_debug_mode) { return (strpos($_SERVER['HTTP_HOST'], 'staging.') !== false); }
Disable Debug Mode Checks for CLI
Disable debug mode checks when running WordPress via command line interface (CLI).
add_filter('enable_wp_debug_mode_checks', 'disable_debug_mode_checks_for_cli'); function disable_debug_mode_checks_for_cli($enable_debug_mode) { return (php_sapi_name() !== 'cli'); }
Enable Debug Mode Checks for Specific User Roles
Enable debug mode checks only for users with the “administrator” role.
add_filter('enable_wp_debug_mode_checks', 'enable_debug_mode_checks_for_admins'); function enable_debug_mode_checks_for_admins($enable_debug_mode) { return (current_user_can('administrator')); }