Alex Rivera | Logout

Is there a way to determine if a WordPress plugin is just installed?

Asked 2011-10-12T10:55:41.767
8

I like to know if there is any way to know if a plugin is Just installed. I don't care if that is activated yet, but only if that plugin is installed !

Do you know any good way to do that?

I have to be more specific. I know where to find the plugins and I know how I can see if there are installed. The question is, if there is any programaticly way to check if the plugin is installed.

ie: WordPress provide us with register_activation_hook() to make any operation we like on the plugin activation, but there is no any relevant hook for plugin installation. Is there any way to determine the plugin installation ?

Edit
Report

1 Answer

16

Here is the best way I have found so far: (this was written as of WP 3.5)

Info:

The main thing to keep in mind with register_activation_hook is that it is called as a mediary page between clicking an activate link from wp-admin/plugins.php and seeing the Plugin Activated notice after it has been hooked in. I found this out after I tried using the $_GET variable that are sent from the Activate link. If you take a good look the link you click too and the link you end up at are slightly different. This is why you cannot use add_action(), do_action() or add_filter(), .. within the register_activation_hook() triggers. It instantly redirects once a plugin has been activated.

Solution:

You can however use add_option during the hook processes like so

/* Main Plugin File */
...
register_activation_hook( __FILE__, function() {
  add_option('Activated_Plugin','Plugin-Slug');
  /* activation code here */
});

add_action('admin_init','load_plugin');
function load_plugin() {
    if(is_admin()&&get_option('Activated_Plugin')=='Plugin-Slug') {
     delete_option('Activated_Plugin');
     /* do some stuff once right after activation */
    }
}

That should get you started...

answered 2012-12-18T06:11:17.910

Your Answer