includes/class-freemius.php
function switch_to_blog( $blog_id, FS_Site $install = null ) {
            if ( $blog_id == $this->_context_is_network_or_blog_id ) {
                return;
            }

            switch_to_blog( $blog_id );
            $this->_context_is_network_or_blog_id = $blog_id;

            self::$_accounts->set_site_blog_context( $blog_id );
            $this->_storage->set_site_blog_context( $blog_id );
            $this->_storage->set_network_active( $this->_is_network_active, $this->is_delegated_connection( $blog_id ) );

            $this->_site = is_object( $install ) ?
                $install :
                $this->get_install_by_blog_id( $blog_id );

            $this->_user     = false;
            $this->_licenses = false;
            $this->_license  = null;

            if ( is_object( $this->_site ) ) {
                // Try to fetch user from install.
                $this->_user = self::_get_user_by_id( $this->_site->user_id );

                if ( ! is_object( $this->_user ) &&
                     FS_User::is_valid_id( $this->_storage->prev_user_id )
                ) {
                    // Try to fetch previously saved user.
                    $this->_user = self::_get_user_by_id( $this->_storage->prev_user_id );

                    if ( ! is_object( $this->_user ) ) {
                        // Fallback to network's user.
                        $this->_user = $this->get_network_user();
                    }
                }

                $all_plugin_licenses = self::get_all_licenses( $this->_module_id );

                if ( ! empty( $all_plugin_licenses ) ) {
                    if ( ! FS_Plugin_License::is_valid_id( $this->_site->license_id ) ) {
                        $this->_license = null;
                    } else {
                        $license_found = false;
                        foreach ( $all_plugin_licenses as $license ) {
                            if ( $license->id == $this->_site->license_id ) {
                                // License found.
                                $this->_license = $license;
                                $license_found  = true;
                                break;
                            }
                        }

                        if ( $license_found ) {
                            $this->link_license_2_user( $this->_license->id, $this->_user->id );
                        }
                    }

                    $this->_licenses = $this->get_user_licenses( $this->_user->id );
                }
            }

            unset( $this->_site_api );
            unset( $this->_user_api );
        }
function switch_to_blog( $blog_id, FS_Site $install = null ) {
            if ( $blog_id == $this->_context_is_network_or_blog_id ) {
                return;
            }

            switch_to_blog( $blog_id );
            $this->_context_is_network_or_blog_id = $blog_id;

            self::$_accounts->set_site_blog_context( $blog_id );
            $this->_storage->set_site_blog_context( $blog_id );
            $this->_storage->set_network_active( $this->_is_network_active, $this->is_delegated_connection( $blog_id ) );

            $this->_site = is_object( $install ) ?
                $install :
                $this->get_install_by_blog_id( $blog_id );

            $this->_user     = false;
            $this->_licenses = false;
            $this->_license  = null;

            if ( is_object( $this->_site ) ) {
                // Try to fetch user from install.
                $this->_user = self::_get_user_by_id( $this->_site->user_id );

                if ( ! is_object( $this->_user ) &&
                     FS_User::is_valid_id( $this->_storage->prev_user_id )
                ) {
                    // Try to fetch previously saved user.
                    $this->_user = self::_get_user_by_id( $this->_storage->prev_user_id );

                    if ( ! is_object( $this->_user ) ) {
                        // Fallback to network's user.
                        $this->_user = $this->get_network_user();
                    }
                }

                $all_plugin_licenses = self::get_all_licenses( $this->_module_id );

                if ( ! empty( $all_plugin_licenses ) ) {
                    if ( ! FS_Plugin_License::is_valid_id( $this->_site->license_id ) ) {
                        $this->_license = null;
                    } else {
                        $license_found = false;
                        foreach ( $all_plugin_licenses as $license ) {
                            if ( $license->id == $this->_site->license_id ) {
                                // License found.
                                $this->_license = $license;
                                $license_found  = true;
                                break;
                            }
                        }

                        if ( $license_found ) {
                            $this->link_license_2_user( $this->_license->id, $this->_user->id );
                        }
                    }

                    $this->_licenses = $this->get_user_licenses( $this->_user->id );
                }
            }

            unset( $this->_site_api );
            unset( $this->_user_api );
        }
function switch_to_blog ( $ blog_id , FS_Site $ install = null ) { if ( $ blog_id == $ this -> _context_is_network_or_blog_id ) { return ; } switch_to_blog ( $ blog_id ) ; $ this -> _context_is_network_or_blog_id = $ blog_id ; self :: $ _accounts -> set_site_blog_context ( $ blog_id ) ; $ this -> _storage -> set_site_blog_context ( $ blog_id ) ; $ this -> _storage -> set_network_active ( $ this -> _is_network_active , $ this -> is_delegated_connection ( $ blog_id ) ) ; $ this -> _site = is_object ( $ install ) ? $ install : $ this -> get_install_by_blog_id ( $ blog_id ) ; $ this -> _user = false ; $ this -> _licenses = false ; $ this -> _license = null ; if ( is_object ( $ this -> _site ) ) { // Try to fetch user from install.
 $ this -> _user = self :: _get_user_by_id ( $ this -> _site -> user_id ) ; if ( ! is_object ( $ this -> _user ) && FS_User :: is_valid_id ( $ this -> _storage -> prev_user_id ) ) { // Try to fetch previously saved user.
 $ this -> _user = self :: _get_user_by_id ( $ this -> _storage -> prev_user_id ) ; if ( ! is_object ( $ this -> _user ) ) { // Fallback to network's user.
 $ this -> _user = $ this -> get_network_user ( ) ; } } $ all_plugin_licenses = self :: get_all_licenses ( $ this -> _module_id ) ; if ( ! empty ( $ all_plugin_licenses ) ) { if ( ! FS_Plugin_License :: is_valid_id ( $ this -> _site -> license_id ) ) { $ this -> _license = null ; } else { $ license_found = false ; foreach ( $ all_plugin_licenses as $ license ) { if ( $ license -> id == $ this -> _site -> license_id ) { // License found.
 $ this -> _license = $ license ; $ license_found = true ; break ; } } if ( $ license_found ) { $ this -> link_license_2_user ( $ this -> _license -> id , $ this -> _user -> id ) ; } } $ this -> _licenses = $ this -> get_user_licenses ( $ this -> _user -> id ) ; } } unset ( $ this -> _site_api ) ; unset ( $ this -> _user_api ) ; }
Switches the Freemius site level context to a specified blog.

@author Vova Feldman (@svovaf)
@since  2.0.0

@param int     $blog_id
@param FS_Site $install
Switches the Freemius site level context to a specified blog .