PDA

View Full Version : How to enable one Wordpress plugin on multiple/many sites at once via Linux shell



Fli
04-28-2017, 10:49 PM
What i want: add & activate one wordpress plugin to many wordpress sites of mine
What i have: one hosting account/server on which all wordpress sites are hosted

Assuming my domains have their website folders in /home/user/public_html



ls /home/user/public_html
wordpressdomain1.info/
wordpressdomain2.cz/
folder/
file1.php
file2.php


So i add all folders with .info and .cz to the file "/tmp/domains":

ls -A1 /home/user/public_html|egrep ".info|.cz" >> /tmp/domains


I verify domain names are listed properly in "/tmp/domains":

cat /tmp/domains
wordpressdomain1.info/
wordpressdomain2.cz/

(it does not matter how your domain folders are named, it just need to be "something/" and your domain folders should contain wordpress files & folders like wp-content,wp-includes etc.)

I download script that will enable certain wordpress plugin for me from within command line/shell:

wget https://www.packetmischief.ca/files/wp/wp_enable_plugins.php

script source:

<?php
/* $jwk: wp_enable_plugins.php,v 1.2 2011/04/29 14:50:58 jwk Exp $ */

/*
* wp_enable_plugins.php
*
* CLI helper script for WordPress that enables plugins. Run without
* any arguments to display list of plugins that exist in your
* wp-content/plugins/ directory. Specify plugins to enable as
* arguments to the script. Note by default it does not enable plugins
* network-wide (if you're running multi-site). Run it from your WordPress
* directory so it can pick up your wp-config.php file.
*
*
*
* Joel Knight
* www.packetmischief.ca
* 2011.04.29
*/

@include "wp-config.php";
@include_once "wp-includes/functions.php";
@include_once "wp-admin/includes/plugin.php";

if (!defined('DB_NAME'))
die("ERROR: DB_NAME not defined. Are you in the 'wordpress' directory?\n");

$action_plugins = $argv;
array_shift($action_plugins); /* pull the script filename off */

if (sizeof($action_plugins) == 0) {
$installed_plugins = get_plugins();
printf("Inactive plugins:\n");
foreach ($installed_plugins as $pkey => $pval) {
if (!is_plugin_active($pkey))
printf("- %s\n", $pkey);
}
printf("\nSpecify plugin name(s) from above on the command line to enable them.\n");
} else {
$cnt = 0;
foreach ($action_plugins as $akey => $aval) {
if (activate_plugin($aval, '', /* network wide? */ false, /* silent? */ false) == null)
$cnt++;
}
printf("Enabled %d/%d plugins.\n", $cnt, sizeof($action_plugins));
}


I copy this script to all my domain's folders:

for i in $(cat /tmp/domains);do cp -n -rp /home/user/public_html/wp_enable_plugins.php /home/user/public_html/$i;done


Then i run wp_enable_plugins.php script to discover paths of my inactive plugins:

php wp_enable_plugins.php
Inactive plugins:
- anti-spam/anti-spam.php
- comment-notifier/plugin.php
- hello-dolly/hello.php


If your plugin is not found, make sure you install it and keep it inactive(not activated) in the wordpress site which path is indicated when you run command "cmd"


Once done, i want in my case "anti-spam/anti-spam.php" plugin to be enabled on all my wordpres sites


Example when i installed that plugin and keep it inactive in /home/user/public_html/wp-content/plugins/anti-spam/. I copy this plugin folder and contents to all my domains this way:

for i in $(cat /tmp/domains);do cp -n -rp /home/user/public_html/wp-content/plugins/anti-spam /home/user/public_html/$i/wp-content/plugins/;done


Then i should be able to run wp_enable_plugins.php script in all my domains folders and enable my selected plugin on all my domains:

for i in $(cat /tmp/domains);do cd /home/user/public_html/$i;php wp_enable_plugins.php anti-spam/anti-spam.php;done

After plugin enabled, and all complete, delete the plugin enabler script:

find /home/user/public_html -name wp_enable_plugins.php -delete

---------------

Alternatively do it manually via Wordpress.

Trupti42
05-12-2017, 11:36 AM
First create a new text document on your desktop and name it something like "Morning Coffee Sites.txt".
Double click on it so notepad will open it for editing.
Copy paste the following into it and replace the site name/URL with the ones you want to load.