If possible, how can installed plugins (meaning the files have been placed in wp-content/plugins directory) be activated from other plugins?
Leave a Reply
You must be logged in to post a comment.
If possible, how can installed plugins (meaning the files have been placed in wp-content/plugins directory) be activated from other plugins?
You must be logged in to post a comment.
This is how I did it in some web apps:
Plugin activation process is coded to work with WP admin interface. It performs some checks to prevent enabling plugins with errors (loading such on start might break WP).
It is handled by
activate_plugin()
function (source) which is documented as unusable elsewhere.So if you want to activate plugin by code the goal itself is relatively easy – to change
active_plugins
option to include that plugin. But you will have to re-create related activation hooks from scratch and will risk breaking site by activating without sandbox step.Plugins are stored in an array in the ‘active_plugins’ option. The array contains the file path to each plugin that is active.
To activate a plugin you need to determine what it’s path will be, then pass that path to
activate_plugin($plugin_path)
.This is easier said than done though, and (at least in 2.9) the core code does not make it easy.
Before you can activate_plugin() you need to include the plugin.php file from wp-admin/includes/. You should also check to make sure your plugin isn’t already active. The result looks something like this (YMMV):
I use this on production in WP 2.9 and have not had any major issues but in my testing it had very unexpected results with WPMU, so beware using this on network installs.
WordPress provides a function for activating plugins, according to WP Codex
You can simply call the WordPress default function.
Please check below link for more detail.
activate plugin