The deprecated_file_trigger_error WordPress PHP filter allows you to control whether an error should be triggered for deprecated files.
Usage
add_filter('deprecated_file_trigger_error', 'my_custom_function'); function my_custom_function($trigger) { // Your custom code here return $trigger; }
Parameters
$trigger
(bool): Whether to trigger the error for deprecated files. Default true.
More information
See WordPress Developer Resources: deprecated_file_trigger_error
Examples
Prevent errors for all deprecated files
Prevent triggering errors for all deprecated files.
add_filter('deprecated_file_trigger_error', '__return_false');
Allow errors for specific deprecated files
Allow triggering errors only for specific deprecated files by checking the file name.
add_filter('deprecated_file_trigger_error', 'allow_specific_deprecated_file_errors', 10, 2); function allow_specific_deprecated_file_errors($trigger, $file) { if ($file === 'my_deprecated_file.php') { return true; } return $trigger; }
Log deprecated file errors
Log deprecated file errors instead of displaying them.
add_filter('deprecated_file_trigger_error', 'log_deprecated_file_errors', 10, 2); function log_deprecated_file_errors($trigger, $file) { error_log("Deprecated file used: {$file}"); return false; }
Show custom message for deprecated file errors
Display a custom message when a deprecated file is used.
add_filter('deprecated_file_trigger_error', 'custom_deprecated_file_message', 10, 2); function custom_deprecated_file_message($trigger, $file) { if ($trigger) { echo "Warning: {$file} is deprecated!"; } return $trigger; }
Send email notification for deprecated file errors
Send an email notification to the admin when a deprecated file is used.
add_filter('deprecated_file_trigger_error', 'email_on_deprecated_file', 10, 2); function email_on_deprecated_file($trigger, $file) { if ($trigger) { $admin_email = get_option('admin_email'); $subject = 'Deprecated file used'; $message = "The following deprecated file was used: {$file}"; wp_mail($admin_email, $subject, $message); } return $trigger; }