get_sites example

if( is_numeric( $args['limit'] ) ){
        $args['number'] = $args['limit'];
        $args['limit'] = null;
    } elseif ( ! $args['limit'] ) {
        $args['number'] = 0;
        $args['limit'] = null;
    }

    // Make sure count is disabled.     $args['count'] = false;

    $_sites  = get_sites( $args );

    $results = array();

    foreach ( $_sites as $_site ) {
        $_site = get_site( $_site );
        $results[] = $_site->to_array();
    }

    return $results;
}



        /** * Filters the arguments for the site query in the sites list table. * * @since 4.6.0 * * @param array $args An array of get_sites() arguments. */
        $args = apply_filters( 'ms_sites_list_table_query_args', $args );

        $_sites = get_sites( $args );
        if ( is_array( $_sites ) ) {
            update_site_cache( $_sites );

            $this->items = array_slice( $_sites, 0, $per_page );
        }

        $total_sites = get_sites(
            array_merge(
                $args,
                array(
                    'count'  => true,
                    
return (int) $this->blog_id;
            }
        }

        $site = get_site();
        if ( $site->domain === $this->domain && $site->path === $this->path ) {
            $main_site_id = (int) $site->id;
        } else {

            $main_site_id = get_network_option( $this->id, 'main_site' );
            if ( false === $main_site_id ) {
                $_sites       = get_sites(
                    array(
                        'fields'     => 'ids',
                        'number'     => 1,
                        'domain'     => $this->domain,
                        'path'       => $this->path,
                        'network_id' => $this->id,
                    )
                );
                $main_site_id = ! empty( $_sites ) ? array_shift( $_sites ) : 0;

                update_network_option( $this->id, 'main_site', $main_site_id );
            }
 else {
        $args['domain'] = array_shift( $domains );
    }

    if ( count( $paths ) > 1 ) {
        $args['path__in']               = $paths;
        $args['orderby']['path_length'] = 'DESC';
    } else {
        $args['path'] = array_shift( $paths );
    }

    $result = get_sites( $args );
    $site   = array_shift( $result );

    if ( $site ) {
        return $site;
    }

    return false;
}

/** * Identifies the network and site of a requested domain and path and populates the * corresponding network and site global objects as part of the multisite bootstrap process. * * Prior to 4.6.0, this was a procedural block in `ms-settings.php`. It was wrapped into * a function to facilitate unit tests. It should not be used outside of core. * * Usually, it's easier to query the site first, which then declares its network. * In limited situations, we either can or must find the network first. * * If a network and site are found, a `true` response will be returned so that the * request can continue. * * If neither a network or site is found, `false` or a URL string will be returned * so that either an error can be shown or a redirect can occur. * * @since 4.6.0 * @access private * * @global WP_Network $current_site The current network. * @global WP_Site $current_blog The current site. * * @param string $domain The requested domain. * @param string $path The requested path. * @param bool $subdomain Optional. Whether a subdomain (true) or subdirectory (false) configuration. * Default false. * @return bool|string True if bootstrap successfully populated `$current_blog` and `$current_site`. * False if bootstrap could not be properly completed. * Redirect URL if parts exist, but the request as a whole can not be fulfilled. */
// In case of subdirectory configs, set the path.         if ( ! is_subdomain_install() ) {
            $path = explode( '/', ltrim( $url_parts['path'], '/' ) );
            $path = reset( $path );

            if ( $path ) {
                $qv['path'] = get_network()->path . $path . '/';
            }
        }

        $sites = get_sites( $qv );
        $site  = reset( $sites );

        // Do not allow embeds for deleted/archived/spam sites.         if ( ! empty( $site->deleted ) || ! empty( $site->spam ) || ! empty( $site->archived ) ) {
            return false;
        }

        if ( $site && get_current_blog_id() !== (int) $site->blog_id ) {
            switch_to_blog( $site->blog_id );
            $switched_blog = true;
        }
    }

    public function query( $query ) {
        $this->query_vars = wp_parse_args( $query );

        return $this->get_sites();
    }

    /** * Retrieves a list of sites matching the query vars. * * @since 4.6.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @return array|int List of WP_Site objects, a list of site IDs when 'fields' is set to 'ids', * or the number of sites when 'count' is passed as a query var. */
$current_network = get_network();
    $slug            = trim( $slug, '/' );

    if ( is_subdomain_install() ) {
        $domain = $slug . '.' . preg_replace( '|^www\.|', '', $current_network->domain );
        $path   = $current_network->path;
    } else {
        $domain = $current_network->domain;
        $path   = $current_network->path . $slug . '/';
    }

    $site_ids = get_sites(
        array(
            'number'                 => 1,
            'fields'                 => 'ids',
            'domain'                 => $domain,
            'path'                   => $path,
            'update_site_meta_cache' => false,
        )
    );

    if ( empty( $site_ids ) ) {
        return null;
    }
$blog_id = (int) $blog_id;
        } else {
            $blog   = 'http://' . preg_replace( '#^https?://#', '', $blog_id );
            $parsed = parse_url( $blog );
            if ( ! $parsed || empty( $parsed['host'] ) ) {
                fwrite( STDERR, "Error: can not determine blog_id from $blog_id\n" );
                exit;
            }
            if ( empty( $parsed['path'] ) ) {
                $parsed['path'] = '/';
            }
            $blogs = get_sites(
                array(
                    'domain' => $parsed['host'],
                    'number' => 1,
                    'path'   => $parsed['path'],
                )
            );
            if ( ! $blogs ) {
                fwrite( STDERR, "Error: Could not find blog\n" );
                exit;
            }
            $blog    = array_shift( $blogs );
            
 elseif ( $id ) {
        return (int) $id;
    }

    $args   = array(
        'domain'                 => $domain,
        'path'                   => $path,
        'fields'                 => 'ids',
        'number'                 => 1,
        'update_site_meta_cache' => false,
    );
    $result = get_sites( $args );
    $id     = array_shift( $result );

    if ( ! $id ) {
        wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' );
        return 0;
    }

    wp_cache_set( md5( $domain . $path )$id, 'blog-id-cache' );

    return $id;
}

case 'upgrade':
        $n = ( isset( $_GET['n'] ) ) ? (int) $_GET['n'] : 0;

        if ( $n < 5 ) {
            /** * @global int $wp_db_version WordPress database version. */
            global $wp_db_version;
            update_site_option( 'wpmu_upgrade_site', $wp_db_version );
        }

        $site_ids = get_sites(
            array(
                'spam'                   => 0,
                'deleted'                => 0,
                'archived'               => 0,
                'network_id'             => get_current_network_id(),
                'number'                 => 5,
                'offset'                 => $n,
                'fields'                 => 'ids',
                'order'                  => 'DESC',
                'orderby'                => 'id',
                'update_site_meta_cache' => false,
            )
if ( ! empty( $site_ids ) ) {
        $args = array(
            'number'   => '',
            'site__in' => $site_ids,
        );
        if ( ! $all ) {
            $args['archived'] = 0;
            $args['spam']     = 0;
            $args['deleted']  = 0;
        }

        $_sites = get_sites( $args );

        foreach ( $_sites as $site ) {
            $sites[ $site->id ] = (object) array(
                'userblog_id' => $site->id,
                'blogname'    => $site->blogname,
                'domain'      => $site->domain,
                'path'        => $site->path,
                'site_id'     => $site->network_id,
                'siteurl'     => $site->siteurl,
                'archived'    => $site->archived,
                'mature'      => $site->mature,
                
Home | Imprint | This part of the site doesn't use cookies.