how to check plugin existence

source : wp-hackers digest # 66,98,5,6,8;107,6.

[ A ] :
<?php
if (is_plugin_active('plugin-directory/plugin-file.php')) {
//plugin is activated
}
?>

[ B ] : Checking for function or class existence is also a solid solution, one I would probably use over is_plugin_active().

[ C ] : If you're building plugins that depend on others, then it is best to attach the initialization of the sub-plugin to a hook in the parent plugin. Then the sub-plugin will noop if the parent plugin is not activated. BuddyPress does this. Of course, that means the parent plugin needs to have hooks in place for that.

[ D ] : Just hook your function to plugins_loaded and check for a function or class name.

function check_for_plugin()
{
if( function_exists('some_function') )
do_something();
}
add_action('plugins_loaded', 'check_for_plugin');
is_plugin_active() requires a folder and a file name, and those might not be the same on all WP installations.

[ E ] : also a great solution is the core fucntion : http://codex.wordpress.org/Function_Reference/is_plugin_active

[ F ] : Is the "master" plugin yours or someone else's ? If you can add code to the master, I would add a do_action hook that loads sub-plugins, and an add_action to the sub-plugin that initializes the plugin. Thus it initializes when the master plugin calls for its sub-plugins.
 
 
Creative Commons License
This work by maniac.vardhan is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
 
 

0 comments :: how to check plugin existence

Post a Comment