The deprecated_argument_run WordPress PHP action fires when a deprecated argument is called.
Usage
add_action('deprecated_argument_run', 'my_custom_function', 10, 3); function my_custom_function($function_name, $message, $version) { // your custom code here }
Parameters
$function_name
(string) – The function that was called.$message
(string) – A message regarding the change.$version
(string) – The version of WordPress that deprecated the argument used.
More information
See WordPress Developer Resources: deprecated_argument_run
Examples
Log Deprecated Argument Usage
Log the deprecated arguments used in the website to a custom log file.
add_action('deprecated_argument_run', 'log_deprecated_argument', 10, 3); function log_deprecated_argument($function_name, $message, $version) { $log_message = "Deprecated argument used in {$function_name} (v{$version}): {$message}\n"; error_log($log_message, 3, "/path/to/your/log/file.log"); }
Email Deprecated Argument Usage
Send an email notification when a deprecated argument is used.
add_action('deprecated_argument_run', 'email_deprecated_argument', 10, 3); function email_deprecated_argument($function_name, $message, $version) { $to = '[email protected]'; $subject = 'Deprecated Argument Used'; $body = "Function: {$function_name}\nMessage: {$message}\nVersion: {$version}"; wp_mail($to, $subject, $body); }
Show Deprecated Argument Usage in Admin Area
Display a notice in the admin area when a deprecated argument is used.
add_action('deprecated_argument_run', 'admin_notice_deprecated_argument', 10, 3); function admin_notice_deprecated_argument($function_name, $message, $version) { if (is_admin()) { $notice = "Deprecated argument used in {$function_name} (v{$version}): {$message}"; add_action('admin_notices', function() use ($notice) { echo "<div class='notice notice-warning'><p>{$notice}</p></div>"; }); } }
Redirect Deprecated Argument Usage
Redirect users to a specific page when a deprecated argument is used.
add_action('deprecated_argument_run', 'redirect_deprecated_argument', 10, 3); function redirect_deprecated_argument($function_name, $message, $version) { wp_redirect('https://example.com/deprecated-argument-notice'); exit; }
Modify Deprecated Argument Message
Customize the deprecated argument message and show it in a JavaScript alert.
add_action('deprecated_argument_run', 'custom_deprecated_argument_message', 10, 3); function custom_deprecated_argument_message($function_name, $message, $version) { $custom_message = "Please be aware: {$function_name} is using a deprecated argument since version {$version}. {$message}"; echo "<script>alert('{$custom_message}');</script>"; }