Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install Plugins Extended #517

Merged
merged 8 commits into from
Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion includes/Services/PluginService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,6 +37,17 @@ public static function initialize() {
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() );
Expand All @@ -51,7 +63,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;
Expand Down
Loading