The deprecated_constructor_run WordPress PHP action fires when a deprecated constructor is called.
Usage
add_action('deprecated_constructor_run', 'your_custom_function', 10, 3); function your_custom_function($class_name, $version, $parent_class) { // your custom code here }
Parameters
$class_name
(string) – The class containing the deprecated constructor.$version
(string) – The version of WordPress that deprecated the function.$parent_class
(string) – The parent class calling the deprecated constructor.
More information
See WordPress Developer Resources: deprecated_constructor_run
Examples
Log Deprecated Constructors
Log deprecated constructors to a custom log file.
add_action('deprecated_constructor_run', 'log_deprecated_constructors', 10, 3); function log_deprecated_constructors($class_name, $version, $parent_class) { // Log deprecated constructor error_log("Deprecated constructor {$class_name} called in version {$version} from parent class {$parent_class}"); }
Send Email Notification on Deprecated Constructor Call
Send an email notification to the admin when a deprecated constructor is called.
add_action('deprecated_constructor_run', 'email_on_deprecated_constructor', 10, 3); function email_on_deprecated_constructor($class_name, $version, $parent_class) { $to = get_bloginfo('admin_email'); $subject = "Deprecated Constructor Alert"; $message = "Deprecated constructor {$class_name} called in version {$version} from parent class {$parent_class}"; wp_mail($to, $subject, $message); }
Display Deprecated Constructor Warning in Admin Dashboard
Show a warning in the admin dashboard when a deprecated constructor is called.
add_action('deprecated_constructor_run', 'admin_deprecated_constructor_warning', 10, 3); function admin_deprecated_constructor_warning($class_name, $version, $parent_class) { add_action('admin_notices', function() use ($class_name, $version, $parent_class) { echo "<div class='notice notice-warning'><p>Deprecated constructor {$class_name} called in version {$version} from parent class {$parent_class}.</p></div>"; }); }
Add Custom Deprecated Constructor Handling
Add custom handling for specific deprecated constructors.
add_action('deprecated_constructor_run', 'handle_specific_deprecated_constructors', 10, 3); function handle_specific_deprecated_constructors($class_name, $version, $parent_class) { if ($class_name === 'My_Deprecated_Class') { // your custom code here } }
Display Deprecated Constructor Warning on Frontend
Show a warning on the frontend when a deprecated constructor is called (for debugging purposes).
add_action('deprecated_constructor_run', 'frontend_deprecated_constructor_warning', 10, 3); function frontend_deprecated_constructor_warning($class_name, $version, $parent_class) { add_action('wp_footer', function() use ($class_name, $version, $parent_class) { echo "<div class='deprecated-constructor-warning'>Deprecated constructor {$class_name} called in version {$version} from parent class {$parent_class}.</div>"; }); }