diff --git a/includes/class-freemius.php b/includes/class-freemius.php index fd10929a..f77c0489 100755 --- a/includes/class-freemius.php +++ b/includes/class-freemius.php @@ -15770,46 +15770,31 @@ 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 ), @@ -15817,7 +15802,7 @@ function get_site_info( $site = null, $load_registration = false ) { ); // 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(), @@ -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; } diff --git a/includes/class-fs-hook-snapshot.php b/includes/class-fs-hook-snapshot.php new file mode 100644 index 00000000..f91a6099 --- /dev/null +++ b/includes/class-fs-hook-snapshot.php @@ -0,0 +1,46 @@ +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 ] ); + } + } + } \ No newline at end of file diff --git a/includes/managers/class-fs-permission-manager.php b/includes/managers/class-fs-permission-manager.php index 4fff146a..4ca1c4e5 100644 --- a/includes/managers/class-fs-permission-manager.php +++ b/includes/managers/class-fs-permission-manager.php @@ -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 ); } /** diff --git a/require.php b/require.php index 7fa226a1..5289f11c 100644 --- a/require.php +++ b/require.php @@ -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';