@@ -7814,9 +7814,9 @@ private function maybe_activate_bundle_license( $license = null, $sites = array(
7814
7814
*
7815
7815
* @param FS_Plugin_License $license
7816
7816
* @param array $sites
7817
- * @param int $blog_id
7817
+ * @param int $current_blog_id
7818
7818
*/
7819
- private function activate_bundle_license( $license, $sites = array(), $blog_id = 0 ) {
7819
+ private function activate_bundle_license( $license, $sites = array(), $current_blog_id = 0 ) {
7820
7820
$is_network_admin = fs_is_network_admin();
7821
7821
7822
7822
$installs_by_blog_map = array();
@@ -7849,16 +7849,16 @@ private function activate_bundle_license( $license, $sites = array(), $blog_id =
7849
7849
continue;
7850
7850
}
7851
7851
7852
- if ( $blog_id > 0 ) {
7853
- $fs->switch_to_blog( $blog_id );
7852
+ if ( $current_blog_id > 0 ) {
7853
+ $fs->switch_to_blog( $current_blog_id );
7854
7854
}
7855
7855
7856
7856
if ( $fs->has_active_valid_license() ) {
7857
7857
continue;
7858
7858
}
7859
7859
7860
- if ( ! $is_network_admin || $blog_id > 0 ) {
7861
- if ( $fs->is_network_active() && ! $fs->is_delegated_connection( $blog_id ) ) {
7860
+ if ( ! $is_network_admin || $current_blog_id > 0 ) {
7861
+ if ( $fs->is_network_active() && ! $fs->is_delegated_connection( $current_blog_id ) ) {
7862
7862
// Do not try to activate the license in the site level if the product is network active and the connection was not delegated.
7863
7863
continue;
7864
7864
}
@@ -7895,20 +7895,18 @@ private function activate_bundle_license( $license, $sites = array(), $blog_id =
7895
7895
}
7896
7896
}
7897
7897
7898
- $current_blog_id = get_current_blog_id();
7899
-
7900
7898
foreach ( $sites as $site ) {
7901
7899
if ( ! isset( $site['blog_id'] ) || ! is_numeric( $site['blog_id'] ) ) {
7902
7900
continue;
7903
7901
}
7904
7902
7905
- $site_blog_id = $site['blog_id'];
7903
+ $blog_id = $site['blog_id'];
7906
7904
7907
- if ( ! isset( $installs_by_blog_map[ $site_blog_id ] ) ) {
7908
- $installs_by_blog_map[ $site_blog_id ] = self::get_all_sites( $fs->get_module_type(), $site_blog_id );
7905
+ if ( ! isset( $installs_by_blog_map[ $blog_id ] ) ) {
7906
+ $installs_by_blog_map[ $blog_id ] = self::get_all_sites( $fs->get_module_type(), $blog_id );
7909
7907
}
7910
7908
7911
- $installs = $installs_by_blog_map[ $site_blog_id ];
7909
+ $installs = $installs_by_blog_map[ $blog_id ];
7912
7910
$install = null;
7913
7911
7914
7912
if ( isset( $installs[ $fs->get_slug() ] ) ) {
@@ -7934,20 +7932,18 @@ private function activate_bundle_license( $license, $sites = array(), $blog_id =
7934
7932
break;
7935
7933
}
7936
7934
7937
- if ( $fs->is_site_delegated_connection( $site_blog_id ) ) {
7935
+ if ( $fs->is_site_delegated_connection( $blog_id ) ) {
7938
7936
// Site activation delegated, don't activate bundle license on the site in the network admin.
7939
7937
continue;
7940
7938
}
7941
7939
7942
- if ( ! isset( $site_info_by_blog_map[ $site_blog_id ] ) ) {
7943
- $site_info_by_blog_map[ $site_blog_id ] = $fs->get_site_info( $site );
7940
+ if ( ! isset( $site_info_by_blog_map[ $blog_id ] ) ) {
7941
+ $site_info_by_blog_map[ $blog_id ] = $fs->get_site_info( $site );
7944
7942
}
7945
7943
7946
- $filtered_sites[] = $site_info_by_blog_map[ $site_blog_id ];
7944
+ $filtered_sites[] = $site_info_by_blog_map[ $blog_id ];
7947
7945
}
7948
7946
7949
- $fs->switch_to_blog( $current_blog_id );
7950
-
7951
7947
if ( $has_install_with_license || empty( $filtered_sites ) ) {
7952
7948
// Do not try to activate the license at the network level if there's any install with a license or there's no site to activate the license on.
7953
7949
continue;
@@ -7961,7 +7957,7 @@ private function activate_bundle_license( $license, $sites = array(), $blog_id =
7961
7957
null,
7962
7958
null,
7963
7959
$sites,
7964
- ( $blog_id > 0 ? $blog_id : null ),
7960
+ ( $current_blog_id > 0 ? $current_blog_id : null ),
7965
7961
$license->user_id
7966
7962
);
7967
7963
}
@@ -8045,8 +8041,6 @@ function get_sites_for_network_level_optin() {
8045
8041
$sites = array();
8046
8042
$all_sites = self::get_sites();
8047
8043
8048
- $current_blog_id = get_current_blog_id();
8049
-
8050
8044
foreach ( $all_sites as $site ) {
8051
8045
$blog_id = self::get_site_blog_id( $site );
8052
8046
@@ -8057,8 +8051,6 @@ function get_sites_for_network_level_optin() {
8057
8051
}
8058
8052
}
8059
8053
8060
- $this->switch_to_blog( $current_blog_id );
8061
-
8062
8054
return $sites;
8063
8055
}
8064
8056
@@ -9185,16 +9177,13 @@ private function get_installs_data_for_api(
9185
9177
$install_url_by_install_id = array();
9186
9178
$subsite_registration_date_by_install_id = array();
9187
9179
9188
- $current_blog_id = get_current_blog_id();
9189
- $user = $this->_user;
9190
-
9191
9180
foreach ( $sites as $site ) {
9192
9181
$blog_id = self::get_site_blog_id( $site );
9193
9182
9194
9183
$install = $this->get_install_by_blog_id( $blog_id );
9195
9184
9196
9185
if ( is_object( $install ) ) {
9197
- if ( $install->user_id != $user ->id ) {
9186
+ if ( $install->user_id != $this->_user ->id ) {
9198
9187
// Install belongs to a different owner.
9199
9188
continue;
9200
9189
}
@@ -9292,7 +9281,7 @@ private function get_installs_data_for_api(
9292
9281
}
9293
9282
}
9294
9283
9295
- $this->switch_to_blog( $current_blog_id );
9284
+ restore_current_blog( );
9296
9285
9297
9286
$installs_data = array_merge(
9298
9287
$installs_data,
@@ -12279,15 +12268,11 @@ private function activate_license_on_many_sites(
12279
12268
$license_key,
12280
12269
array $site_ids = array()
12281
12270
) {
12282
- $current_blog_id = get_current_blog_id();
12283
-
12284
12271
$sites = array();
12285
12272
foreach ( $site_ids as $site_id ) {
12286
12273
$sites[] = $this->get_site_info( array( 'blog_id' => $site_id ) );
12287
12274
}
12288
12275
12289
- $this->switch_to_blog( $current_blog_id );
12290
-
12291
12276
// Install the plugin.
12292
12277
$result = $this->create_installs_with_user(
12293
12278
$user,
@@ -12603,8 +12588,6 @@ function is_whitelabeled( $ignore_data_debug_mode = false, $blog_id = null ) {
12603
12588
) {
12604
12589
$sites = self::get_sites();
12605
12590
12606
- $current_blog_id = get_current_blog_id();
12607
-
12608
12591
/**
12609
12592
* If in network admin area and the add-on was not network-activated or network-activated
12610
12593
* and network-delegated, find any add-on whose is_whitelabeled flag is true.
@@ -12618,8 +12601,6 @@ function is_whitelabeled( $ignore_data_debug_mode = false, $blog_id = null ) {
12618
12601
}
12619
12602
}
12620
12603
12621
- $this->switch_to_blog( $current_blog_id );
12622
-
12623
12604
if ( $is_whitelabeled ) {
12624
12605
break;
12625
12606
}
@@ -15793,10 +15774,12 @@ static function get_sites_blog_ids( $sites ) {
15793
15774
*
15794
15775
* @return array
15795
15776
*/
15796
- function get_site_info( $site = null, $load_registration = false, $restore_current_blog = false ) {
15777
+ function get_site_info( $site = null, $load_registration = false ) {
15797
15778
$this->_logger->entrance();
15798
15779
15799
- $switched = false;
15780
+ $fs_hook_snapshot = new FS_Hook_Snapshot();
15781
+ // Remove all filters from `switch_blog`.
15782
+ $fs_hook_snapshot->remove( 'switch_blog' );
15800
15783
15801
15784
$registration_date = null;
15802
15785
@@ -15809,7 +15792,6 @@ function get_site_info( $site = null, $load_registration = false, $restore_curre
15809
15792
15810
15793
if ( get_current_blog_id() != $blog_id ) {
15811
15794
switch_to_blog( $blog_id );
15812
- $switched = true;
15813
15795
}
15814
15796
15815
15797
if ( $site instanceof WP_Site ) {
@@ -15851,9 +15833,8 @@ function get_site_info( $site = null, $load_registration = false, $restore_curre
15851
15833
$info[ 'registration_date' ] = $registration_date;
15852
15834
}
15853
15835
15854
- if ( $switched && $restore_current_blog ) {
15855
- restore_current_blog();
15856
- }
15836
+ // Add the filters back to `switch_blog`.
15837
+ $fs_hook_snapshot->restore( 'switch_blog' );
15857
15838
15858
15839
return $info;
15859
15840
}
@@ -17038,7 +17019,7 @@ function get_opt_in_params( $override_with = array(), $network_level_or_blog_id
17038
17019
array( 'blog_id' => $network_level_or_blog_id ) :
17039
17020
null;
17040
17021
17041
- $site = $this->get_site_info( $site, false, true );
17022
+ $site = $this->get_site_info( $site );
17042
17023
17043
17024
$diagnostic_info = array();
17044
17025
if ( FS_Permission_Manager::instance( $this )->is_diagnostic_tracking_allowed() ) {
@@ -17780,15 +17761,11 @@ private function install_many_pending_with_user(
17780
17761
FS_Permission_Manager::PERMISSION_EXTENSIONS => $is_extensions_tracking_allowed,
17781
17762
) );
17782
17763
17783
- $current_blog_id = get_current_blog_id();
17784
-
17785
17764
$sites = array();
17786
17765
foreach ( $site_ids as $site_id ) {
17787
17766
$sites[] = $this->get_site_info( array( 'blog_id' => $site_id ) );
17788
17767
}
17789
17768
17790
- $this->switch_to_blog( $current_blog_id );
17791
-
17792
17769
$this->install_with_user( $user, $license_key, $trial_plan_id, $redirect, true, $sites );
17793
17770
}
17794
17771
0 commit comments