Skip to content

Commit

Permalink
Update PluginService.php
Browse files Browse the repository at this point in the history
  • Loading branch information
officiallygod committed Oct 12, 2023
1 parent c6d0089 commit 3b4fede
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions includes/Services/PluginService.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ public static function initialize() {
* @return boolean
*/
public static function activate_init_plugins() {
$init_plugins = Plugins::get_init();
$filtered_init_plugins = SiteFeatures::filter_selected( $init_plugins );
$site_features_selected = SiteFeatures::get_selected();
$final_init_plugins = array_merge( $filtered_init_plugins, $site_features_selected );
$init_plugins = Plugins::get_init();
$filtered_init_plugins = SiteFeatures::filter_selected( $init_plugins, true );
$site_features_selected = SiteFeatures::get_selected();
$site_features_unselected = SiteFeatures::get_unselected();
$final_init_plugins = array_merge( $filtered_init_plugins, $site_features_selected );

foreach ( $final_init_plugins as $init_plugin ) {
$init_plugin_type = PluginInstaller::get_plugin_type( $init_plugin['slug'] );
Expand All @@ -90,6 +91,29 @@ public static function activate_init_plugins() {
);
}

foreach ( $site_features_unselected as $init_plugin ) {
$init_plugin_type = PluginInstaller::get_plugin_type( $init_plugin['slug'] );
$init_plugin_path = PluginInstaller::get_plugin_path( $init_plugin['slug'], $init_plugin_type );
// Checks if a plugin with the given slug and activation criteria already exists.
if ( PluginInstaller::is_plugin_installed( $init_plugin_path ) ) {
// Add a new PluginDeactivationTask to the Plugin Deactivation queue.
PluginDeactivationTaskManager::add_to_queue(
new PluginDeactivationTask(
$init_plugin['slug']
)
);
continue;
}

PluginInstallTaskManager::add_to_queue(
new PluginInstallTask(
$init_plugin['slug'],
false,
isset( $init_plugin['priority'] ) ? $init_plugin['priority'] : 0
)
);
}

return true;
}

Expand All @@ -106,16 +130,15 @@ public static function configure_activation_transient() {
case 'admin.php':
\do_action( 'qm/debug', 'Here' );
delete_transient( Options::get_option_name( 'active_plugins', true ) );
self::activate_init_plugins();
break;
case 'plugins.php':
delete_transient( Options::get_option_name( 'active_plugins', true ) );
self::activate_init_plugins();
break;
case 'index.php':
// If the page is nfd-onboarding
if ( WP_ADMIN::$slug === $_GET['page'] ) {
if ( empty( get_transient( Options::get_option_name( 'active_plugins', true ) ) ) ) {
self::activate_init_plugins();
set_transient( Options::get_option_name( 'active_plugins', true ), '1', 20 * MINUTE_IN_SECONDS );
}
}
Expand All @@ -131,6 +154,7 @@ function( $plugins ) {
return $plugins;
}
);
\do_action( 'qm/debug', get_option( 'active_plugins' ) );

}
}

0 comments on commit 3b4fede

Please sign in to comment.