Skip to content

Commit a75b873

Browse files
authored
[multisite] Improve retrieval of individual‑site info in a multisite … (#802)
* [multisite] Adapt a simplified version of the approach from the `feature/swas/restore_blog_fix_alt_exploration` branch.
1 parent fddb9ac commit a75b873

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

includes/class-freemius.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15777,6 +15777,10 @@ static function get_sites_blog_ids( $sites ) {
1577715777
function get_site_info( $site = null, $load_registration = false ) {
1577815778
$this->_logger->entrance();
1577915779

15780+
$fs_hook_snapshot = new FS_Hook_Snapshot();
15781+
// Remove all filters from `switch_blog`.
15782+
$fs_hook_snapshot->remove( 'switch_blog' );
15783+
1578015784
$switched = false;
1578115785

1578215786
$registration_date = null;
@@ -15836,6 +15840,9 @@ function get_site_info( $site = null, $load_registration = false ) {
1583615840
restore_current_blog();
1583715841
}
1583815842

15843+
// Add the filters back to `switch_blog`.
15844+
$fs_hook_snapshot->restore( 'switch_blog' );
15845+
1583915846
return $info;
1584015847
}
1584115848

includes/class-fs-hook-snapshot.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* @package Freemius
4+
* @copyright Copyright (c) 2025, Freemius, Inc.
5+
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6+
* @since 2.12.2
7+
*/
8+
9+
if ( ! defined( 'ABSPATH' ) ) {
10+
exit;
11+
}
12+
13+
/**
14+
* Class FS_Hook_Snapshot
15+
*
16+
* This class allows you to take a snapshot of the current actions attached to a WordPress hook, remove them, and restore them later.
17+
*/
18+
class FS_Hook_Snapshot {
19+
20+
private $removed_actions = array();
21+
22+
/**
23+
* Remove all actions from a given hook and store them for later restoration.
24+
*/
25+
public function remove( $hook ) {
26+
global $wp_filter;
27+
28+
if ( ! empty( $wp_filter ) && isset( $wp_filter[ $hook ] ) ) {
29+
$this->removed_actions[ $hook ] = $wp_filter[ $hook ];
30+
unset( $wp_filter[ $hook ] );
31+
}
32+
}
33+
34+
/**
35+
* Restore previously removed actions for a given hook.
36+
*/
37+
public function restore( $hook ) {
38+
global $wp_filter;
39+
40+
if ( ! empty( $wp_filter ) && isset( $this->removed_actions[ $hook ] ) ) {
41+
$wp_filter[ $hook ] = $this->removed_actions[ $hook ];
42+
unset( $this->removed_actions[ $hook ] );
43+
}
44+
}
45+
}

require.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@
5858
require_once WP_FS__DIR_INCLUDES . '/class-fs-admin-notices.php';
5959
require_once WP_FS__DIR_INCLUDES . '/class-freemius-abstract.php';
6060
require_once WP_FS__DIR_INCLUDES . '/sdk/Exceptions/Exception.php';
61+
require_once WP_FS__DIR_INCLUDES . '/class-fs-hook-snapshot.php';
6162
require_once WP_FS__DIR_INCLUDES . '/class-freemius.php';

0 commit comments

Comments
 (0)