• TL;DR I have written a test plugin. All I have added is code which self-deactivates the plugin. So when someone installs my plugin and activates it, the plugin immediately deactivates itself. But when that occurs, the message ‘Plugin activated’ is still displayed on-screen. Is that expected, or am I doing something wrong?
    ___
    I have built a small custom plugin. In it I have added PHP which immediately self-deactivates the plugin (see code below). When a user activates my plugin, what occurs is that plugin immediately deactivates, as desired and as expected. But the page still displays Plugin activated. at the top of the screen (screenshot). This is of course a bit misleading to the end user. My question is: given my code, is this expected? Or have I done something incorrectly/insufficiently?

    I believe I know how to change that message (e.g. this Stack Exchange question/answer). But before I pursue that, I just want to know if I’ve perhaps done something incorrectly to cause this issue.

    The ultimate goal is for my plugin PHP code to first perform a check of the user’s installed version of WordPress. If the user’s WordPress version is too low, my plugin will immediately deactivate. If/when that occurs, I would prefer if ‘Plugin activated’ was not displayed on-screen.

    In my case, do I have to maybe trigger a reload of the page, to clear that message? Just thinking out loud.

    Thanks in advance.

    My Code

    function opn_main() {
            deactivate_plugins( plugin_basename( __FILE__ ) );// Self-deactivate the Outdated Plugin Notifier plugin.
            return;
        }
    add_action( 'load-plugins.php', 'opn_main' );
    • This topic was modified 6 years, 4 months ago by Carl Gross.
    • This topic was modified 6 years, 4 months ago by Carl Gross.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Does a page reload clear the message or problem? It should. I’d just trigger the reload and be done with it but you’ll want to makes sure the user sees something to let them know why the plugin disabled itself.

    Thread Starter Carl Gross

    (@carlgross)

    OK good call on that–refreshing the page does indeed clear the message.

    >> I’d just trigger the reload and be done with it but you’ll want to makes sure the user sees something to let them know why the plugin disabled itself.

    Yep, understood on that.

    Instead of refreshing the page, what about simply changing that message? I can change that message (see this post)–I’ve tested that and can indeed change that message to anything I want. What if, when my plugin auto-self deactivates, I display a custom message there? The big question is: what PHP logic could I use to ensure this custom message always displays, in these situations only? Is there some hook/option/cookie/transient I can use/check that will always let me know when my plugin has immediately self-deactivated after an activation attempt? If so, what do you think of that potential solution? If I can get it working it seems a little more advantageous than adding another page load. Plus, even after adding a second page load, as you mentioned, I’d *still* have to display a custom message somewhere.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘If plugin is self-deactivated, ‘Plugin activated’ is still displayed. Why?’ is closed to new replies.