admin_notices after register_uninstall / deactivate_hook

The short answer is no, it is not possible. When you deactivate your plugin, it’s deactivated so doesn’t run your admin_notices action when the admin screen is refreshed. You can confirm it for yourself by using the action in a slightly different way.

In your deactivation function include the following line:

set_transient('my_deactivation_transient', 'My plugin is being deactivated', 100);

Make you admin_notices function look like this:

function my_admin_notices()
{
    $message = get_transient('my_deactivation_transient');

    if (empty($message)) return;

    echo "<div class="error"><p>$message</p></div>";
}

When you deactivate your plugin you will not see any message. When you activate your plugin again, you will see the message. It’s not that the admin_notices function is not called, it’s just that the plugin is not active when the admin screen is refreshed.

Leave a Comment