Activate WordPress Plugins Automatically via a Function

WordPress stores the active Plugins in the database table options, field activate_plugins, so it is easy to change this value to activate various Plugins by WordPress; either as a Plugin solution after setting up a new installation or because some Plugins need some other Plugins.

I show you as an example a solution. It is important that you don’t use the Plugin names, but the string of the file, which is also required in various hooks. Below you will also find a simple solution to get to this string in your backend.

// example on admin init, control about register_activation_hook() 
add_action( 'admin_init', 'fb_activate_plugins' );
// the exmple function
function fb_activate_plugins() {
	if ( ! current_user_can('activate_plugins') )
		wp_die(__('You do not have sufficient permissions to activate plugins for this site.'));
	$plugins = FALSE;
	$plugins = get_option('active_plugins'); // get active plugins
	if ( $plugins ) {
		// plugins to active
		$pugins_to_active = array(
			'hello.php', // Hello Dolly
			'adminimize/adminimize.php', // Adminimize
			'akismet/akismet.php' // Akismet
		foreach ( $pugins_to_active as $plugin ) {
			if ( ! in_array( $plugin, $plugins ) ) {
				array_push( $plugins, $plugin );
				update_option( 'active_plugins', $plugins );
	} // end if $plugins


The following function and its hook provides a direct output of the string of the Plugin file on the Plugin page in your backend, so please use it only for a quick finding.

add_filter( 'plugin_row_meta', 'fb_get_plugin_string', 10, 4 );
function fb_get_plugin_string( $plugin_meta, $plugin_file, $plugin_data, $status ) {
	// echo plugin file string
	echo '' . $plugin_file . '
'; return $plugin_meta; }





7 responses to “Activate WordPress Plugins Automatically via a Function”

  1. […] individuell gestalten. Bei 24ways lesen wir Optimierungsmethoden für die Nutzung von jQuery. Bei WPEngineer wird eine Funktion vorgestellt, mittels derer man Plugins automatisch aktivieren kann. Im […]

  2. […] You are here: Home > Links > WP Engineer on activating plugins via a function PermalinkWP Engineer on activating plugins via a functionBy Ryan Imel 1 min agoDecember 15, 20110 var addthis_product='wpp-262';var […]

  3. Eric Mann Avatar

    Yes, this would work to immediately activate the plugins, but it’s also incredibly dangerous!

    When WordPress activates a plugin, it does so in a sandbox so you don’t break your site. If the plugin is broken, you see an error rather than a borked website. If, on the otherhand, you manually change the ‘active_plugins’ option to include previously untested plugins, you run the risk of immediately breaking your site.

  4. Mike Schinkel Avatar





  5. Zane Matthew Avatar

    Nice idea, I never thought of doing it that way, but why would you do this?

    If you had dependent plugins you could use:

    or you can take the concept scribu has in work it into your existing plugin.

  6. Mike Schinkel Avatar


    Yes, that is a valid concern for a non-technical end-user running a blog but it’s not incredibly dangerous for all use-cases.

    For example, if you are building a pre-defined collection of plugins to go with WordPress and a theme and you want to test them for future deployment or new clients or customers that don’t require an admin to correctly fiddle with all the settings this would come in handy and be completely appropriate.

    Or if you want to create a setup that you can install automatically so you can run automated unit and/or regression tests then automating settings like this would be critical.

  7. Frank Avatar

    @Mike: not typo, its for careful readers. 😉