The deprecated_function_trigger_error WordPress PHP filter allows you to control whether an error should be triggered for deprecated functions.
Usage
add_filter('deprecated_function_trigger_error', 'your_custom_function_name'); function your_custom_function_name($trigger) { // your custom code here return $trigger; }
Parameters
$trigger
(bool): Whether to trigger the error for deprecated functions. Default is true.
More information
See WordPress Developer Resources: deprecated_function_trigger_error
Examples
Suppressing errors for all deprecated functions
Prevent error messages from being displayed for any deprecated function.
add_filter('deprecated_function_trigger_error', '__return_false');
Allowing errors for a specific deprecated function
Allow error messages for a specific deprecated function while suppressing others.
add_filter('deprecated_function_trigger_error', 'allow_specific_deprecated_function_error', 10, 2); function allow_specific_deprecated_function_error($trigger, $function) { if ($function == 'specific_deprecated_function') { return true; } return false; }
Logging deprecated function errors
Log errors for deprecated functions instead of displaying them.
add_filter('deprecated_function_trigger_error', 'log_deprecated_function_errors', 10, 2); function log_deprecated_function_errors($trigger, $function) { error_log("Deprecated function used: {$function}"); return false; }
Displaying custom error message for deprecated functions
Show a custom error message for deprecated functions.
add_filter('deprecated_function_trigger_error', 'custom_deprecated_function_error', 10, 2); function custom_deprecated_function_error($trigger, $function) { if ($trigger) { trigger_error("Custom message: {$function} is deprecated.", E_USER_DEPRECATED); } return false; }
Conditionally suppressing deprecated function errors
Suppress errors for deprecated functions based on a condition, e.g., user role.
add_filter('deprecated_function_trigger_error', 'conditionally_suppress_deprecated_function_errors'); function conditionally_suppress_deprecated_function_errors($trigger) { if (current_user_can('manage_options')) { return false; } return $trigger; }