OK I know this has been asked before but I want to know the most efficient and clean way I can do this.
What I have is an auto provision through serverpilot which installs WordPress for a client on a digital ocean server.
The problem I'm having is this:
I want to activate a plugin that helps the client when he first starts out on WordPress. The problem I'm having is I can't have my script access their DB to activate the plugin once the script adds the file to the plugin directory. I want the plugin to be activated through PHP. So far this solution looks good but I want to know if this is the easiest and cleanest way of activating a plugin that I'm dropping into the plugins directory
function MY_toggle_plugins() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
$temp_files1 = glob(WP_PLUGIN_DIR.'/*');
$activated=array();
$already_active=array();
foreach($temp_files1 as $file1){
if(is_dir($file1)) {
$temp_files2 = glob($file1 . '/*');
foreach($temp_files2 as $file2){
if(is_file($file2) && stripos(file_get_contents($file2),'Plugin Name:')!==false) {
$plugin_name_full=basename(dirname($file2)).'/'.basename($file2);
if(is_plugin_active($plugin_name_full)) {
array_push($already_active, $plugin_name_full);
//deactivate_plugins($plugin_name_full);
}
else{
array_push($activated, $plugin_name_full);
//activate_plugin($plugin_name_full);
}
}
}
}
}
echo 'You have activated these plugins:<br/><br/>'.serialize($activated).'<br/><br/>These were already active:<br/><br/>'.serialize($already_active); exit;
}
//execute
MY_toggle_plugins();