Using WordPress ‘deactivated_plugins_notice()’ PHP function

The deactivated_plugins_notice() WordPress PHP function displays an admin notice when a plugin has been deactivated during an update. This usually happens due to incompatibility with the current version of WordPress.

Usage

To use the deactivated_plugins_notice() function, simply call it within the appropriate admin area where you wish to display the notice.

deactivated_plugins_notice();

Parameters

The deactivated_plugins_notice() function does not take any parameters.

More information

See WordPress Developer Resources: deactivated_plugins_notice()

This function is particularly useful in troubleshooting and ensuring that site administrators are aware of any plugins that may have been deactivated during an update.

Examples

Displaying notice in Dashboard

Use the function in the dashboard to alert the admin about deactivated plugins.

add_action('admin_notices', 'deactivated_plugins_notice');

Conditional Notice Display

You can conditionally display the notice depending on your own criteria.

if ($some_condition) {
    deactivated_plugins_notice();
}

Hooking into Plugin Deactivation

Use the function when a specific plugin is deactivated.

add_action('deactivate_plugin', 'deactivated_plugins_notice');

Admin Notice Upon Login

Show the notice upon admin login.

add_action('wp_login', 'deactivated_plugins_notice', 10, 2);

Displaying Notice in Custom Admin Page

Display the notice in your own custom admin page.

add_action('admin_menu', function() {
    add_menu_page('My Page', 'My Page', 'manage_options', 'my-page', function() {
        deactivated_plugins_notice();
        // Rest of your page content
    });
});