Skip to content
Open
Show file tree
Hide file tree
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
52 changes: 18 additions & 34 deletions includes/class-freemius.php
Original file line number Diff line number Diff line change
Expand Up @@ -15770,54 +15770,39 @@ static function get_sites_blog_ids( $sites ) {
* @since 2.0.0
*
* @param array|WP_Site|null $site
* @param bool $load_registration Since 2.5.1 When set to `true` the method will attempt to return the subsite's registration date, regardless of the `$site` type and value. In most calls, the registration date will be returned anyway, even when the value is `false`. This param is purely for performance optimization.
* @param bool $load_registration Deprecated, the site's registration date is always loaded and returned.
*
* @return array
*/
function get_site_info( $site = null, $load_registration = false ) {
function get_site_info( $site = null, $load_registration = true ) {
$this->_logger->entrance();

$switched = false;
$fs_hook_snapshot = new FS_Hook_Snapshot();
// Remove all filters from `switch_blog`
$fs_hook_snapshot->remove( 'switch_blog' );

$registration_date = null;
$blog_id = is_null( $site ) ? null : self::get_site_blog_id( $site );
$blog_details = $site instanceof WP_Site ?
$site :
( is_multisite() ? get_blog_details( $blog_id, true ) : null );

if ( is_null( $site ) ) {
$url = self::get_unfiltered_site_url();
$name = get_bloginfo( 'name' );
$blog_id = null;
if ( ! is_object( $blog_details ) ) {
$name = get_bloginfo( 'name' );
$registration_date = null;
} else {
$blog_id = self::get_site_blog_id( $site );

if ( get_current_blog_id() != $blog_id ) {
switch_to_blog( $blog_id );
$switched = true;
}

if ( $site instanceof WP_Site ) {
$url = $site->siteurl;
$name = $site->blogname;
$registration_date = $site->registered;
} else {
$url = self::get_unfiltered_site_url( $blog_id );
$name = get_bloginfo( 'name' );
}
$name = $blog_details->blogname;
$registration_date = $blog_details->registered;
}

if ( empty( $registration_date ) && $load_registration ) {
$blog_details = get_blog_details( $blog_id, false );

if ( is_object( $blog_details ) && isset( $blog_details->registered ) ) {
$registration_date = $blog_details->registered;
}
}
$url = self::get_unfiltered_site_url( $blog_id );

$info = array(
'uid' => $this->get_anonymous_id( $blog_id ),
'url' => $url,
);

// Add these diagnostic information only if user allowed to track.
if ( FS_Permission_Manager::instance( $this )->is_diagnostic_tracking_allowed() ) {
if ( FS_Permission_Manager::instance( $this )->is_diagnostic_tracking_allowed( true, $blog_id ) ) {
$info = array_merge( $info, array(
'title' => $name,
'language' => self::get_sanitized_language(),
Expand All @@ -15832,9 +15817,8 @@ function get_site_info( $site = null, $load_registration = false ) {
$info[ 'registration_date' ] = $registration_date;
}

if ( $switched ) {
restore_current_blog();
}
// Add the filters back to `switch_blog`
$fs_hook_snapshot->restore( 'switch_blog' );

return $info;
}
Expand Down
46 changes: 46 additions & 0 deletions includes/class-fs-hook-snapshot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* @package Freemius
* @copyright Copyright (c) 2025, Freemius, Inc.
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
* @since 2.5.1
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* Class FS_Hook_Snapshot
*
* This class allows you to take a snapshot of the current actions attached to a WordPress hook,
* remove them, and restore them later.
*/
class FS_Hook_Snapshot {

private $removed_actions = array();

/**
* Remove all actions from a given hook and store them for later restoration.
*/
public function remove( $hook ) {
global $wp_filter;

if ( isset( $wp_filter[ $hook ] ) ) {
$this->removed_actions[ $hook ] = $wp_filter[ $hook ];
unset( $wp_filter[ $hook ] );
}
}

/**
* Restore previously removed actions for a given hook.
*/
public function restore( $hook ) {
global $wp_filter;

if ( isset( $this->removed_actions[ $hook ] ) ) {
$wp_filter[ $hook ] = $this->removed_actions[ $hook ];
unset( $this->removed_actions[ $hook ] );
}
}
}
7 changes: 4 additions & 3 deletions includes/managers/class-fs-permission-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,14 @@ function is_essentials_tracking_allowed( $blog_id = null ) {

/**
* @param bool $default
* @param int|null $blog_id
*
* @return bool
*/
function is_diagnostic_tracking_allowed( $default = true ) {
function is_diagnostic_tracking_allowed( $default = true, $blog_id = null ) {
return $this->is_premium_context() ?
$this->is_permission_allowed( self::PERMISSION_DIAGNOSTIC, $default ) :
$this->is_permission_allowed( self::PERMISSION_SITE, $default );
$this->is_permission_allowed( self::PERMISSION_DIAGNOSTIC, $default, $blog_id ) :
$this->is_permission_allowed( self::PERMISSION_SITE, $default, $blog_id );
}

/**
Expand Down
1 change: 1 addition & 0 deletions require.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@
require_once WP_FS__DIR_INCLUDES . '/class-fs-admin-notices.php';
require_once WP_FS__DIR_INCLUDES . '/class-freemius-abstract.php';
require_once WP_FS__DIR_INCLUDES . '/sdk/Exceptions/Exception.php';
require_once WP_FS__DIR_INCLUDES . '/class-fs-hook-snapshot.php';
require_once WP_FS__DIR_INCLUDES . '/class-freemius.php';