From 5af92889b6ce886ab19c4c177b77715f835f7dda Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 11 Mar 2024 10:23:37 +0530 Subject: [PATCH 1/8] Update PluginService.php --- includes/Services/PluginService.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/includes/Services/PluginService.php b/includes/Services/PluginService.php index 34549cdaf..a613d06a0 100644 --- a/includes/Services/PluginService.php +++ b/includes/Services/PluginService.php @@ -3,6 +3,7 @@ use NewfoldLabs\WP\Module\Onboarding\WP_Admin; use NewfoldLabs\WP\Module\Onboarding\Data\Options; +use NewfoldLabs\WP\Module\Onboarding\Data\Config; use NewfoldLabs\WP\Module\Installer\Services\PluginInstaller; use NewfoldLabs\WP\Module\Installer\TaskManagers\PluginActivationTaskManager; use NewfoldLabs\WP\Module\Installer\TaskManagers\PluginInstallTaskManager; @@ -21,6 +22,28 @@ * Class for providing plugin related services. */ class PluginService { + + /** + * Gets the list of plugins based on different enabled Hiive Flags + * + * @return array + */ + public static function initialize_hiive_flag_plugins() { + $init_plugins_extended = array(); + $hiive_flags = Plugins::get_hiive_plugin_flags(); + + foreach ( $hiive_flags as $hiive_flag => $is_enabled ) { + // Check if it is an allowed flag and is enabled on the container + if ( true === $is_enabled && true === Config::get_site_capability( $hiive_flag ) ) { + // Check if there are plugins for the flag. + if ( isset( Plugins::$hiive_flag_plugin_list[ $hiive_flag ] ) ) { + $init_plugins_extended = array_merge( $init_plugins_extended, Plugins::$hiive_flag_plugin_list[ $hiive_flag ] ); + } + } + } + return $init_plugins_extended; + } + /** * Queues the initial list of Plugin Installs for a flow. * @@ -30,6 +53,9 @@ public static function initialize() { $init_plugins = array(); + // Add plugins according to Hiive Flags + $init_plugins = array_merge( $init_plugins, self::initialize_hiive_flag_plugins() ); + $flow = Data::current_flow(); if ( 'sitegen' === $flow && SiteGenService::is_enabled() ) { $init_plugins = SiteGenService::get_plugin_recommendations(); @@ -41,6 +67,8 @@ public static function initialize() { $init_plugins = array_merge( Plugins::get_init(), SiteFeatures::get_init() ); } + return print_r( json_encode( $init_plugins ) ); + foreach ( $init_plugins 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 ); From d8d5d3bcc20585d7e7a99596fbad23bd5ad61a97 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 11 Mar 2024 10:24:13 +0530 Subject: [PATCH 2/8] Update PluginService.php --- includes/Services/PluginService.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/includes/Services/PluginService.php b/includes/Services/PluginService.php index a613d06a0..38041ca6e 100644 --- a/includes/Services/PluginService.php +++ b/includes/Services/PluginService.php @@ -67,8 +67,6 @@ public static function initialize() { $init_plugins = array_merge( Plugins::get_init(), SiteFeatures::get_init() ); } - return print_r( json_encode( $init_plugins ) ); - foreach ( $init_plugins 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 ); From b772d42a9917a08ec228631e1b868ab4f50cfb86 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 11 Mar 2024 10:35:22 +0530 Subject: [PATCH 3/8] Update PluginService.php --- includes/Services/PluginService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/Services/PluginService.php b/includes/Services/PluginService.php index 38041ca6e..1fbe34f00 100644 --- a/includes/Services/PluginService.php +++ b/includes/Services/PluginService.php @@ -53,9 +53,6 @@ public static function initialize() { $init_plugins = array(); - // Add plugins according to Hiive Flags - $init_plugins = array_merge( $init_plugins, self::initialize_hiive_flag_plugins() ); - $flow = Data::current_flow(); if ( 'sitegen' === $flow && SiteGenService::is_enabled() ) { $init_plugins = SiteGenService::get_plugin_recommendations(); @@ -67,6 +64,9 @@ public static function initialize() { $init_plugins = array_merge( Plugins::get_init(), SiteFeatures::get_init() ); } + // Add plugins according to Hiive Flags + $init_plugins = array_merge( $init_plugins, self::initialize_hiive_flag_plugins() ); + foreach ( $init_plugins 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 ); From 5667ec94337855c5493a885aad4b390cbea0716f Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 11 Mar 2024 10:46:53 +0530 Subject: [PATCH 4/8] Update PluginService.php --- includes/Services/PluginService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/Services/PluginService.php b/includes/Services/PluginService.php index 1fbe34f00..0d74da465 100644 --- a/includes/Services/PluginService.php +++ b/includes/Services/PluginService.php @@ -64,7 +64,7 @@ public static function initialize() { $init_plugins = array_merge( Plugins::get_init(), SiteFeatures::get_init() ); } - // Add plugins according to Hiive Flags + // Add plugins enabled by Hiive Flags $init_plugins = array_merge( $init_plugins, self::initialize_hiive_flag_plugins() ); foreach ( $init_plugins as $init_plugin ) { @@ -77,7 +77,7 @@ public static function initialize() { new PluginInstallTask( $init_plugin['slug'], $init_plugin['activate'], - $init_plugin['priority'] + isset( $init_plugin['priority'] ) ? $init_plugin['priority'] : 0 ) ); continue; From 7626b714c6360a63c1a0f170507e57e20690f3ce Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Tue, 12 Mar 2024 17:53:59 +0530 Subject: [PATCH 5/8] Update PluginService.php --- includes/Services/PluginService.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/includes/Services/PluginService.php b/includes/Services/PluginService.php index 0d74da465..918bd332d 100644 --- a/includes/Services/PluginService.php +++ b/includes/Services/PluginService.php @@ -29,15 +29,15 @@ class PluginService { * @return array */ public static function initialize_hiive_flag_plugins() { - $init_plugins_extended = array(); - $hiive_flags = Plugins::get_hiive_plugin_flags(); + $init_plugins_extended = array(); + $plugins_data_for_hiive_capabilities = Plugins::$hiive_flag_plugin_list; - foreach ( $hiive_flags as $hiive_flag => $is_enabled ) { - // Check if it is an allowed flag and is enabled on the container - if ( true === $is_enabled && true === Config::get_site_capability( $hiive_flag ) ) { + foreach ( $plugins_data_for_hiive_capabilities as $hiive_capability => $plugins_data ) { + // Check if the capability is enabled on Hiive + if ( true === Config::get_site_capability( $hiive_capability ) ) { // Check if there are plugins for the flag. - if ( isset( Plugins::$hiive_flag_plugin_list[ $hiive_flag ] ) ) { - $init_plugins_extended = array_merge( $init_plugins_extended, Plugins::$hiive_flag_plugin_list[ $hiive_flag ] ); + if ( ! empty( $plugins_data ) ) { + $init_plugins_extended = array_merge( $init_plugins_extended, $plugins_data ); } } } From 0229eff125169a3e10876fabfe0cc323c6ffe4ea Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Tue, 12 Mar 2024 17:59:18 +0530 Subject: [PATCH 6/8] Update PluginService.php --- includes/Services/PluginService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Services/PluginService.php b/includes/Services/PluginService.php index 918bd332d..c5fe8c26d 100644 --- a/includes/Services/PluginService.php +++ b/includes/Services/PluginService.php @@ -36,7 +36,7 @@ public static function initialize_hiive_flag_plugins() { // Check if the capability is enabled on Hiive if ( true === Config::get_site_capability( $hiive_capability ) ) { // Check if there are plugins for the flag. - if ( ! empty( $plugins_data ) ) { + if ( is_array( $plugins_data ) && ! empty( $plugins_data ) ) { $init_plugins_extended = array_merge( $init_plugins_extended, $plugins_data ); } } From 9125c0479290c7e436051dab25ba46ba89526f98 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Wed, 13 Mar 2024 14:53:01 +0530 Subject: [PATCH 7/8] Update PluginService.php --- includes/Services/PluginService.php | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/includes/Services/PluginService.php b/includes/Services/PluginService.php index c5fe8c26d..90f1c7007 100644 --- a/includes/Services/PluginService.php +++ b/includes/Services/PluginService.php @@ -22,28 +22,6 @@ * Class for providing plugin related services. */ class PluginService { - - /** - * Gets the list of plugins based on different enabled Hiive Flags - * - * @return array - */ - public static function initialize_hiive_flag_plugins() { - $init_plugins_extended = array(); - $plugins_data_for_hiive_capabilities = Plugins::$hiive_flag_plugin_list; - - foreach ( $plugins_data_for_hiive_capabilities as $hiive_capability => $plugins_data ) { - // Check if the capability is enabled on Hiive - if ( true === Config::get_site_capability( $hiive_capability ) ) { - // Check if there are plugins for the flag. - if ( is_array( $plugins_data ) && ! empty( $plugins_data ) ) { - $init_plugins_extended = array_merge( $init_plugins_extended, $plugins_data ); - } - } - } - return $init_plugins_extended; - } - /** * Queues the initial list of Plugin Installs for a flow. * @@ -55,7 +33,7 @@ public static function initialize() { $flow = Data::current_flow(); if ( 'sitegen' === $flow && SiteGenService::is_enabled() ) { - $init_plugins = SiteGenService::get_plugin_recommendations(); + $init_plugins = array_merge( Plugins::get_init(), SiteGenService::get_plugin_recommendations() ); if ( is_wp_error( $init_plugins ) ) { return $init_plugins; } @@ -64,9 +42,6 @@ public static function initialize() { $init_plugins = array_merge( Plugins::get_init(), SiteFeatures::get_init() ); } - // Add plugins enabled by Hiive Flags - $init_plugins = array_merge( $init_plugins, self::initialize_hiive_flag_plugins() ); - foreach ( $init_plugins 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 ); From 6c0c2bd44b8582f1b76d9a07870e4cbb49793737 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Wed, 13 Mar 2024 18:39:43 +0530 Subject: [PATCH 8/8] Remove dups in Sitegen Flow --- includes/Services/PluginService.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/includes/Services/PluginService.php b/includes/Services/PluginService.php index 90f1c7007..1d1280bed 100644 --- a/includes/Services/PluginService.php +++ b/includes/Services/PluginService.php @@ -33,10 +33,21 @@ public static function initialize() { $flow = Data::current_flow(); if ( 'sitegen' === $flow && SiteGenService::is_enabled() ) { - $init_plugins = array_merge( Plugins::get_init(), SiteGenService::get_plugin_recommendations() ); + $init_plugins = SiteGenService::get_plugin_recommendations(); if ( is_wp_error( $init_plugins ) ) { return $init_plugins; } + // Convert { slug->slug } to hash for faster search + // As Php uses array as { [0] -> slug_name } and that won't work with array_key_exists + $plugin_slugs = array_column( $init_plugins, 'slug', 'slug' ); + + // Iterate and ensure no duplicates are added + $default_plugins = Plugins::get_init(); + foreach ( $default_plugins as $default_plugin ) { + if ( ! array_key_exists( $default_plugin['slug'], $plugin_slugs ) ) { + $init_plugins[] = $default_plugin; + } + } } else { // Get the initial list of plugins to be installed based on the plan. $init_plugins = array_merge( Plugins::get_init(), SiteFeatures::get_init() );