WP_Site example

$_wp_switched_stack = array();
$switched           = false;

// Need to init cache again after blog_id is set. wp_start_object_cache();

if ( ! $current_site instanceof WP_Network ) {
    $current_site = new WP_Network( $current_site );
}

if ( ! $current_blog instanceof WP_Site ) {
    $current_blog = new WP_Site( $current_blog );
}

// Define upload directory constants. ms_upload_constants();

/** * Fires after the current site and network have been detected and loaded * in multisite's bootstrap. * * @since 4.6.0 */

function get_site( $site = null ) {
    if ( empty( $site ) ) {
        $site = get_current_blog_id();
    }

    if ( $site instanceof WP_Site ) {
        $_site = $site;
    } elseif ( is_object( $site ) ) {
        $_site = new WP_Site( $site );
    } else {
        $_site = WP_Site::get_instance( $site );
    }

    if ( ! $_site ) {
        return null;
    }

    /** * Fires after a site is retrieved. * * @since 4.6.0 * * @param WP_Site $_site Site data. */
if ( empty( $_site ) || is_wp_error( $_site ) ) {
                $_site = -1;
            }

            wp_cache_add( $site_id$_site, 'sites' );
        }

        if ( is_numeric( $_site ) ) {
            return false;
        }

        return new WP_Site( $_site );
    }

    /** * Creates a new WP_Site object. * * Will populate object properties from the object provided and assign other * default properties based on that information. * * @since 4.5.0 * * @param WP_Site|object $site A site object. */
if ( empty( $details ) ) {
        $details = WP_Site::get_instance( $blog_id );
        if ( ! $details ) {
            // Set the full cache.             wp_cache_set( $blog_id, -1, 'blog-details' );
            return false;
        }
    }

    if ( ! $details instanceof WP_Site ) {
        $details = new WP_Site( $details );
    }

    if ( ! $get_all ) {
        wp_cache_set( $blog_id . $all$details, 'blog-details' );
        return $details;
    }

    $switched_blog = false;

    if ( get_current_blog_id() !== $blog_id ) {
        switch_to_blog( $blog_id );
        

    $pre = apply_filters( 'pre_get_site_by_path', null, $domain$path$segments$paths );
    if ( null !== $pre ) {
        if ( false !== $pre && ! $pre instanceof WP_Site ) {
            $pre = new WP_Site( $pre );
        }
        return $pre;
    }

    /* * @todo * Caching, etc. Consider alternative optimization routes, * perhaps as an opt-in for plugins, rather than using the pre_* filter. * For example: The segments filter can expand or ignore paths. * If persistent caching is enabled, we could query the DB for a path <> '/' * then cache whether we can just always ignore paths. */
Home | Imprint | This part of the site doesn't use cookies.