Last active
August 29, 2015 13:58
-
-
Save andrezrv/10032229 to your computer and use it in GitHub Desktop.
A loader for plugins that should run only in local stages. Have a local-plugins folder containing plugins into wp-content, and a local-config.php called from wp-config.php in your local stage. Then declare the relative path of your local plugins and load them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin name: Local Plugins | |
Description: A loader for plugins that should run only in local stages. | |
Author: Andrés Villarreal | |
Author URI: http://about.me/andrezrv | |
Version: 1.0 | |
License: GPL2 | |
*/ | |
function local_plugins_setup() { | |
global $local_plugins; | |
if ( isset( $local_plugins ) && is_dir( $local_plugins_dir = WP_CONTENT_DIR . '/local-plugins' ) ) { | |
// Allow filtering for plugins list. | |
$local_plugins = apply_filters( 'local_plugins', $local_plugins, $local_plugins_dir ); | |
foreach ( $local_plugins as $plugin ) { | |
$file = $local_plugins_dir . '/' . $plugin; | |
// Allow filtering for filepath. | |
$file = apply_filters( 'local_plugin_filepath', $file, $plugin, $local_plugins_dir ); | |
if ( file_exists( $file ) ) { | |
require( $file ); | |
} | |
} | |
} | |
do_action( 'local_plugins_loaded' ); // Do stuff after loading the plugins. | |
} | |
if ( defined( 'WP_STAGE' ) && 'local' == WP_STAGE ) { | |
$local_plugins = array( | |
// The following values should be relative to WP_CONTENT_DIR . '/local-plugins'. | |
'wordpress-beta-tester/wp-beta-tester.php', | |
'wordpress-importer/wordpress-importer.php', | |
); | |
add_action( 'muplugins_loaded', 'local_plugins_setup' ); // Keep this line uncommented if you're using the plugin as MU. | |
// add_action( 'plugins_loaded', 'local_plugins_setup' ); // Uncomment this line to use the plugin as a standard one. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment