The deprecated_hook_run WordPress PHP action fires when a deprecated hook is called.
Usage
add_action('deprecated_hook_run', 'your_custom_function', 10, 4); function your_custom_function($hook, $replacement, $version, $message) { // your custom code here }
Parameters
- $hook (string): The hook that was called.
- $replacement (string): The hook that should be used as a replacement.
- $version (string): The version of WordPress that deprecated the argument used.
- $message (string): A message regarding the change.
More information
See WordPress Developer Resources: deprecated_hook_run
Examples
Log Deprecated Hooks
Log all deprecated hooks to a custom log file.
add_action('deprecated_hook_run', 'log_deprecated_hooks', 10, 4); function log_deprecated_hooks($hook, $replacement, $version, $message) { $log_message = "Deprecated Hook: {$hook} | Replacement: {$replacement} | Version: {$version} | Message: {$message}"; error_log($log_message, 3, '/path/to/your/custom_log.log'); }
Notify Admin via Email
Send an email to the administrator when a deprecated hook is called.
add_action('deprecated_hook_run', 'notify_admin_deprecated_hook', 10, 4); function notify_admin_deprecated_hook($hook, $replacement, $version, $message) { $admin_email = get_option('admin_email'); $subject = "Deprecated Hook Alert"; $body = "Deprecated Hook: {$hook}\nReplacement: {$replacement}\nVersion: {$version}\nMessage: {$message}"; wp_mail($admin_email, $subject, $body); }
Display Deprecated Hooks
Display a list of deprecated hooks in the admin area.
add_action('deprecated_hook_run', 'list_deprecated_hooks', 10, 4); function list_deprecated_hooks($hook, $replacement, $version, $message) { $deprecated_hooks = get_option('deprecated_hooks_list', []); $deprecated_hooks[] = compact('hook', 'replacement', 'version', 'message'); update_option('deprecated_hooks_list', $deprecated_hooks); }
Display Deprecated Hooks Alert
Show an alert in the admin area when a deprecated hook is called.
add_action('deprecated_hook_run', 'deprecated_hooks_alert', 10, 4); function deprecated_hooks_alert($hook, $replacement, $version, $message) { $alert_message = "Deprecated Hook: {$hook} | Replacement: {$replacement} | Version: {$version} | Message: {$message}"; set_transient('deprecated_hook_alert', $alert_message, 60); }
Disable Deprecated Hooks
Disable a specific deprecated hook from running by returning early.
add_action('deprecated_hook_run', 'disable_deprecated_hook', 10, 4); function disable_deprecated_hook($hook, $replacement, $version, $message) { if ($hook === 'some_deprecated_hook') { return; } // your custom code here }