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 ?
Here is the best way I have found so far: (this was written as of WP 3.5)
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.
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...
There are several ways to check that I can think of:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With