Skip to content

Instantly share code, notes, and snippets.

@wokamoto
Last active October 9, 2015 05:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wokamoto/3445482 to your computer and use it in GitHub Desktop.
Save wokamoto/3445482 to your computer and use it in GitHub Desktop.
特定のプラグインを有効にするプラグイン
<?php
/*
Plugin Name: Just do it !
Plugin URI:
Description:
Version: 0.1
Author:
Author URI:
*/
new just_do_it();
class just_do_it {
private $must_plugins = array(
'WP Multibyte Patch' => 'wp-multibyte-patch/wp-multibyte-patch.php',
);
function __construct() {
add_action('shutdown', array($this, 'plugins_loaded'));
}
public function plugins_loaded() {
$activePlugins = get_option('active_plugins');
foreach ($this->must_plugins as $key => $plugin) {
if ( !array_search($plugin, $activePlugins) ) {
activate_plugin( $plugin, '', $this->is_multisite() );
}
}
}
private function is_multisite() {
return function_exists('is_multisite') && is_multisite();
}
}
@wokamoto
Copy link
Author

13行目の $must_plugins という連想配列で、有効にしておきたいプラグインを指定します。
上の例は、"WP Multibyte Patch" を必ず有効にするための設定です。
他にも有効にしたいプラグインがある場合は、この連想配列に同じようにして追加してください。

こいつを wp-content/mu-plugins に入れておけば、指定されたプラグインが必ず有効になります。

@wokamoto
Copy link
Author

WordPress がマルチサイトインストールされている場合、プラグインはネットワークで有効になります。
そこだけ、注意してください。

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