Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically installing & activating Wordpress plugins

Tags:

php

wordpress

Is it possible, somehow to programmatically install plugins? So I can send my client one file they unpack, go to some installplugins.php file and that installs + activates them? Only way I found for doing that is really rancid lowlevel; I'm hoping someone here knows better methods.

like image 319
CharlesS Avatar asked Jul 10 '10 08:07

CharlesS


People also ask

What is installation process?

Installation is the process of making hardware and/or software ready for use. Obviously, different systems require different types of installations.

How do I know if Composer is installed?

You can check your installed composer version using a command composer -v at the current path. Such as: composer -v.


3 Answers

Update

Today I use a shell loop with wp-cli to install and activate the plugins

Original Answer

For activating, I use some variant of this. suppose I had three plugins i wanted to activate ("cforms", "w3-total-cache", "wordpress-seo"). The convention is that their directory and plugin .php file are the same name:

$wordpress_path = "/path/to/my/wordpress/install";    
require_once( $wordpress_path . "/wp-load.php" ); //not sure if this line is needed
//activate_plugin() is here:
require_once(  $wordpress_path . "/wp-admin/includes/plugin.php");
$plugins = array("cforms",  "w3-total-cache",  "wordpress-seo");
foreach ($plugins as $plugin){
$plugin_path = $wordpress_path."wp-content/plugins/{$plugin}.php";
  activate_plugin($plugin_path);
}
like image 167
yuvilio Avatar answered Sep 20 '22 02:09

yuvilio


  1. Copy plugin to /wp-content/plugins/ (root dir if the plugin is just one file, otherwise a subdir).
  2. Call activate_plugin('/full/path/to/your/plugin/php');
like image 30
ggutenberg Avatar answered Sep 22 '22 02:09

ggutenberg


Here's a complete script; put in wp-admin, give it a .php suffix, and hit it via curl.

<?php

define('WP_ADMIN', TRUE);
define('WP_NETWORK_ADMIN', TRUE);
define('WP_USER_ADMIN', TRUE);

require_once('../wp-load.php');
require_once( '../wp-admin/includes/admin.php' );
require_once( '../wp-admin/includes/plugin.php' );

activate_plugin("/full/path/to/my/plugin.php");
?>
like image 44
Bret Weinraub Avatar answered Sep 23 '22 02:09

Bret Weinraub