From 6c0c2bd44b8582f1b76d9a07870e4cbb49793737 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Wed, 13 Mar 2024 18:39:43 +0530 Subject: [PATCH] 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() );