Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've successfully added admin notices to display on register_activation_hook, and when the plugin updates, but I'm not seeing any way to display admin_notices after the uninstall or deactivation hooks. Is this at all possible? Alternatively can use javascript at this stage? (yes sort of).


EDIT:

To answer @G. M. I've already read the docs and @kaiser I've already seen your great writeup on these hooks, but unless I've been sloppy and missed something these two hooks seem to operate differently then the activation hook. Here is what I've tested:

This does not display a notice on the admin page, on deactivation or uninstall (though with deactivation only , you will see the message displayed briefly on a white screen after the hook runs, but just before the plugin admin page reloads):

register_deactivation_hook(__FILE__, "gfahp_deactivate");
function gfahp_deactivate(){
    $notices = sprintf('%sSome notice%s', '<div class="error fade"><p>', '</p></div>');
echo $notices;
 }

This also does not work (on either):

register_deactivation_hook(__FILE__, "gfahp_deactivate");

function gfahp_deactivate(){  
    add_action( 'admin_notices', 'gfahp_checks', 0 );
 }
function gfahp_checks(){
    $notices = sprintf('%sSome notice%s', '<div class="error fade"><p>', '</p></div>');
    echo = $notices; // return does not work either
 }

Javascript DOES work on deactivation but NOT uninstall:

register_deactivation_hook(__FILE__, "gfahp_deactivate");
function gfahp_deactivate(){
    $notices = 'Some notice';
    echo "<script>window.alert('$notices');</script>";
 }
share|improve this question
    
for deactivation for unistall –  G. M. Jul 31 '13 at 20:59
    
Seen this answer already? And please show us your code. –  kaiser Jul 31 '13 at 21:52
    
@kaiser Yes I've seen all the docs and that answer - but none allow a notice to the admin due (i believe) to the page refresh after they occur. Will update question in a moment. –  orionrush Jul 31 '13 at 22:01
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.