Skip to content

Instantly share code, notes, and snippets.

@mattneal-stafflink
Last active November 15, 2024 00:15
Show Gist options
  • Save mattneal-stafflink/93a270be2cc32b828d3c425da723c361 to your computer and use it in GitHub Desktop.
Save mattneal-stafflink/93a270be2cc32b828d3c425da723c361 to your computer and use it in GitHub Desktop.
Plugin Manager Documentation

Plugin Manager MU-Plugin

The Plugin Manager is designed to enforce the activation and deactivation of specific plugins based on the environment in which your WordPress site is running. It allows you to specify:

  • Plugins to activate per environment.
  • Plugins to deactivate per environment.

Installation

  1. Add the plugin to your mu-plugins directory. Get it here.

    • Create a file named env-plugin-manager.php.
  2. Ensure Plugin Files Exist:

    • Verify that all plugins specified in the activation and deactivation arrays are installed in the wp-content/plugins/ directory.
    • Remove the example plugins from the arrays $plugins_to_activate and $plugins_to_deactivate

Configuration

  • Define WP_ENV: Must be defined in wp-config.php or via server environment variables.
  • Possible Values: 'local', 'staging', 'production'

Specify Plugins to Activate

Edit the $plugins_to_activate array in the plugin-manager.php file:

$plugins_to_activate = array(
    'local' => array(
        'query-monitor/query-monitor.php',
        'debug-bar/debug-bar.php',
    ),
    'staging' => array(
        'maintenance-mode/maintenance-mode.php',
    ),
    'production' => array(
        'cache-plugin/cache-plugin.php',
        'seo-plugin/seo-plugin.php',
    ),
);

Specify Plugins to Deactivate

Edit the $plugins_to_deactivate array:

$plugins_to_deactivate = array(
    'local' => array(
        'cache-plugin/cache-plugin.php', // Disable caching on local
    ),
    'staging' => array(
        'seo-plugin/seo-plugin.php', // Disable SEO plugin on staging
    ),
    'production' => array(
        'query-monitor/query-monitor.php', // Disable development plugins on production
    ),
);

Multisite Support

For WordPress Multisite installations, the plugin manages network-activated plugins:

  • Function: manage_network_plugins( $plugins )
  • Hook: site_option_active_sitewide_plugins

Plugin Paths

  • Format: Paths should be relative to the wp-content/plugins/ directory. This will also work with Bedrock based sites, etc.
  • Example: 'plugin-folder/plugin-main-file.php'
  • Ensure Correct Paths: Incorrect paths will prevent the plugin from being activated or deactivated as intended.

Notes

  • Changes must be made directly in the plugin-manager.php file.
  • This plugin has no dependencies. Ensure there is a very very valid reason you will not allow specific plugins to be activated/deactivated before using this plugin.
  • Missing plugins will be skipped silently. (so copy this plugin and load it up with your settings. You can then deploy it across all of your websites).
  • Administrators cannot override the activation/deactivation settings via the WordPress admin interface. Any manual changes will be reset on the next page load.

License

This plugin is released under the GNU General Public License v2 or later.


Support: None. You're on your own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment