From 9542a00c2e53a7c4ad7ea03d65ed5e0a08dc6c0e Mon Sep 17 00:00:00 2001 From: Mike Auteri Date: Sun, 9 Jun 2024 18:54:33 -0400 Subject: [PATCH 1/2] Fix issue with site creation. --- includes/core/classes/class-setup.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/includes/core/classes/class-setup.php b/includes/core/classes/class-setup.php index f43dff8d4..d5d878a13 100644 --- a/includes/core/classes/class-setup.php +++ b/includes/core/classes/class-setup.php @@ -16,6 +16,7 @@ use Exception; use GatherPress\Core\Traits\Singleton; +use WP_Site; /** * Class Setup. @@ -333,12 +334,13 @@ public function add_online_event_term(): void { * * @since 1.0.0 * - * @param int $site_id ID of the newly created site. + * @param WP_Site $new_site the newly created site. + * * @return void */ - public function on_site_create( int $site_id ): void { + public function on_site_create( WP_Site $new_site ): void { if ( is_plugin_active_for_network( 'gatherpress/gatherpress.php' ) ) { - switch_to_blog( $site_id ); + switch_to_blog( $new_site->blog_id ); $this->create_tables(); restore_current_blog(); } From afc2d4dca661da54f5660cfacfd1645927154007 Mon Sep 17 00:00:00 2001 From: Mike Auteri Date: Sun, 9 Jun 2024 19:08:06 -0400 Subject: [PATCH 2/2] Update per Carsten's suggestion. --- includes/core/classes/class-setup.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/includes/core/classes/class-setup.php b/includes/core/classes/class-setup.php index d5d878a13..60234fd51 100644 --- a/includes/core/classes/class-setup.php +++ b/includes/core/classes/class-setup.php @@ -183,14 +183,17 @@ public function filter_plugin_action_links( array $actions ): array { * @return void */ public function activate_gatherpress_plugin( bool $network_wide ): void { - global $wpdb; - if ( is_multisite() && $network_wide ) { - // Get all blogs in the network and activate plugin on each one. - $blog_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT blog_id FROM %i', $wpdb->blogs ) ); // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnsupportedIdentifierPlaceholder, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + // Get all sites in the network and activate plugin on each one. + $site_ids = get_sites( + array( + 'fields' => 'ids', + 'network_id' => get_current_site()->id, + ) + ); - foreach ( $blog_ids as $blog_id ) { - switch_to_blog( $blog_id ); + foreach ( $site_ids as $site_id ) { + switch_to_blog( $site_id ); $this->create_tables(); restore_current_blog(); }