Last active
September 27, 2023 19:03
-
-
Save blobaugh/6a6e88b57ec598c31e85 to your computer and use it in GitHub Desktop.
WordPress auto-activate plugins script
This file contains 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 | |
/* | |
* wp-content/install.php | |
* | |
* This file runs automatically when the WordPress installer is run. | |
* Most WordPress functionality will be available to provide the ability | |
* to perform any additional actions on installation you would like. | |
*/ | |
/** | |
* Automatically activates plugins in the list after the WordPress installation | |
* has called the shutdown hook. | |
* | |
* Plugins can be added to the list to auto-activate by using the relative path | |
* from the wp-content/plugins folder. E.G: jetpack/jetpack.php | |
**/ | |
function activate_plugins_after_wordpress_install() { | |
global $pagenow; | |
/* | |
* List of plugins to auto-activate | |
* | |
* Format is relative path from wp-content/plugins. | |
* E.G: jetpack/jetpack.php | |
*/ | |
$plugins = array( | |
'jetpack/jetpack.php', | |
'akismet/akismet.php' | |
); | |
// Make sure we are on the WordPress install page | |
if ( !( 'install.php' == $pagenow && isset( $_REQUEST['step'] ) && 2 == $_REQUEST['step'] ) ) { | |
return; | |
} | |
// Get the list of currently active plugins (Most likely an empty array) | |
$active_plugins = (array) get_option( 'active_plugins', array() ); | |
// Add plugins to auto-activate | |
foreach ( $plugins as $p ) { | |
// Make sure the plugin is not already listed | |
if ( false !== array_search( $p, $active_plugins ) ) { | |
continue; // Whoops, found the plugin already! | |
} | |
$active_plugins[] = $p; | |
} | |
// Set the new plugin list in WordPress | |
update_option( 'active_plugins', $active_plugins ); | |
} | |
add_action( 'shutdown', 'activate_plugins_after_wordpress_install' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment