Disable WordPress Plugins From the Shell

Lately I’ve been working with a separate instance of my WordPress site for development and testing of plugins, my theme, etc. I have a helper script that orchestrates the pulling of files and copying of the database from the production server into the dev server. I found that it would be nice to disable certain plugins that I don’t want running in the dev instance (ie, plugins that notify search indexes when new posts are made) from within this script. I whipped up this script for that purpose:

% php wp_disable_plugins.php
Active plugins:
- add-to-feed/add-to-feed.php
- dynamic-categories-widget/dynamic-categories.php
- growmap-anti-spambot-plugin/growmap-anti-spambot-plugin.php
- link-to-post/link-to-post.php
- map-categories-to-pages/map-categories-to-pages.php
- mce-table-buttons/mce_table_buttons.php
- page-tagger/page-tagger.php
- php-enkoder/enkoder.php
- quotes-collection/quotes-collection.php

Specify plugin name(s) from above on the command line to disable them.
% php wp_disable_plugins.php add-to-feed/add-to-feed.php
Disabled 1/1 plugins.

That’s all there is to it.

This script is also helpful if a plugin goes haywire and for some reason prevents you from logging into the admin panel.

Update: Thanks to feedback from Mark Kreyman, I’ve updated the script so it picks up the $table_prefix from wp-config.php. This should prevent errors in a lot of installations.

Download: wp_disable_plugins.php

8 thoughts on “Disable WordPress Plugins From the Shell”

  1. Joel,

    Thank you so much for this script! WordPress lacks command line tools, imo, and your wp_disable_plugin script was a huge time-saver for me yesterday! A lot of pages I googled provided (duplicate) information about how to disable all plugins at once, but I found none, except your blog, that would help to disable a single plugin or two.

    I used your script in combination with the following script:

    http://bash.cyberciti.biz/file-management/read-line-by-line-separate-line-in-fields-2/

    It can read from a file with a list of cpanel usernames, one per line, and now whatever you can do with one account/wp blog, you can do the same with a hundred blogs! Just thought this information could be useful to somebody else as well…

    Thank you again!

  2. I like the idea of that script, however, I didn’t work for me with a plugin which was not parseable anymore after a server upgrade with a new PHP version.

    The script then failed with the same broken plugin.

    And actually, it is perfectly fine, when you’re already on shell level, to just move or delete the folder of the plugin in /wp-content/plugins/ to disable it.

Leave a Reply

Your email address will not be published. Required fields are marked *

Would you like to subscribe to email notification of new comments? You can also subscribe without commenting.