The deprecated_constructor_trigger_error WordPress PHP filter allows you to control whether to trigger an error for deprecated functions when WP_DEBUG is set to true.
Usage
add_filter('deprecated_constructor_trigger_error', 'your_custom_function');
function your_custom_function($trigger) {
// your custom code here
return $trigger;
}
Parameters
$trigger(bool): Whether to trigger the error for deprecated functions. Default istrue.
More information
See WordPress Developer Resources: deprecated_constructor_trigger_error
Examples
Suppressing Deprecated Constructor Error
To suppress the error for deprecated functions, set the $trigger variable to false.
add_filter('deprecated_constructor_trigger_error', 'suppress_deprecated_constructor_error');
function suppress_deprecated_constructor_error($trigger) {
return false;
}
Logging Deprecated Constructor Error
Log the deprecated constructor error to a custom log file instead of triggering the error.
add_filter('deprecated_constructor_trigger_error', 'log_deprecated_constructor_error', 10, 2);
function log_deprecated_constructor_error($trigger, $function_name) {
error_log("Deprecated constructor used: $function_name");
return false;
}
Allowing Deprecated Constructor Error for Specific Functions
Only trigger deprecated constructor errors for specific functions by checking the function name.
add_filter('deprecated_constructor_trigger_error', 'allow_specific_deprecated_constructor_error', 10, 2);
function allow_specific_deprecated_constructor_error($trigger, $function_name) {
$allowed_functions = array('function_name_1', 'function_name_2');
return in_array($function_name, $allowed_functions);
}
Custom Error Message for Deprecated Constructor Error
Display a custom error message for deprecated constructor errors.
add_filter('deprecated_constructor_trigger_error', 'custom_error_message_deprecated_constructor', 10, 2);
function custom_error_message_deprecated_constructor($trigger, $function_name) {
trigger_error("Custom Error: Deprecated constructor called - $function_name", E_USER_DEPRECATED);
return false;
}
Conditionally Trigger Deprecated Constructor Error
Trigger deprecated constructor errors only when a specific condition is met.
add_filter('deprecated_constructor_trigger_error', 'conditionally_trigger_deprecated_constructor_error', 10, 2);
function conditionally_trigger_deprecated_constructor_error($trigger, $function_name) {
if (your_custom_condition()) {
return true;
}
return false;
}