Recently I have written few articles/tips for wordpress. So here is one more article on this series. In this tutorial we will see how we can activate wordpress plugins programatically.
This would be useful when you don’t want some of your plugin to be disabled. Using below code your those plugins will always remain activated even if some one has deactivated form the admin panel. :)
How let’s have a look at below code block for the same. You just need to place below code in functions.php file of your active theme.
$current_plugin = get_option("active_plugins");
if(count($current_plugin)>0)
{
//Array of plugin which you want to remain active
$always_active_plugin = array("plugin_x", "plugin_y", "plugin_z");
// Looping through active plugins
foreach ($always_active_plugin as $plugin_name)
{
// If plugin is not active then add to list
if(!in_array($plugin_name, $current_plugin))
{
array_push($current_plugin ,$plugin_name);
}
}
// Finally update plugins.
update_option('active_plugins',$current_plugin );
}
Hope this will be useful when you need this. Subscribe to our RSS Feed to get updates via email.
Pingback: Activate WordPress Plugin Using Code | PHP | Syngu