Programmatically Install WordPress Plugins

Have you ever wondered if you could programmatically install WordPress plugins? Well of course you can, and it’s easier than you might think.

Here is a shortcut to the solution, use WP core function activate_plugin().

Here is an example that could be helpful if you want to do the activation from outside WP:

Is Plugin Install and Activation the Same Thing?

No, plugin activation only handles activation of a plugin that is already installed. In WP “installed” means the plugin already exists in the wp-content/plugins/ folder. If you manually drop a plugin there, it is installed but not active and will appear on your list of plugins… presuming it isn’t broken or invalid. In other words “plugin install” alone doesn’t really do much, WP becomes aware of the plugin, lists it, but doesn’t include it or run it.

What matters about this is that a full external WP plugin install service/platform has to handle putting the plugin into the plugins directory (install) then handle the activation. But when we talk about programmatically installing WordPress plugins, it’s usually the activation we’re concerned with.

Potential Use Cases for Programmatically Installing WordPress Plugins

  • External (outside WP site) service that installs plugins to a given site. In this use case the service would need to deliver the plugin (zipped) to the wp-content/plugins/ folder, unzip it, then run the activate_plugins() function.
  • Bundled plugin installation for suite of plugins. If you’re building a collection or suite of plugins that work together and require each other, you may want to have them installed together. You could build a central or main plugin, which has the other plugins in the suite contained within it. When the main plugin is installed, the suite plugins are moved/unzipped and then activate_plugins() is run. With this use case you might also have an interface where the admin user can select optional plugins within the suite to install.
  • Custom WordPress installs. After installing WordPress, deliver/install plugins. This use case could be used to create deployable packages, such as a WooCommerce deployment where WC is automatically installed.