get_networks example

/** * Sets up the WordPress query for retrieving networks. * * @since 4.6.0 * * @param string|array $query Array or URL query string of parameters. * @return array|int List of WP_Network objects, a list of network IDs when 'fields' is set to 'ids', * or the number of networks when 'count' is passed as a query var. */
    public function query( $query ) {
        $this->query_vars = wp_parse_args( $query );
        return $this->get_networks();
    }

    /** * Gets a list of networks matching the query vars. * * @since 4.6.0 * * @return array|int List of WP_Network objects, a list of network IDs when 'fields' is set to 'ids', * or the number of networks when 'count' is passed as a query var. */
    public function get_networks() {
        
return 1;
    }

    $current_network = get_network();

    if ( defined( 'PRIMARY_NETWORK_ID' ) ) {
        $main_network_id = PRIMARY_NETWORK_ID;
    } elseif ( isset( $current_network->id ) && 1 === (int) $current_network->id ) {
        // If the current network has an ID of 1, assume it is the main network.         $main_network_id = 1;
    } else {
        $_networks       = get_networks(
            array(
                'fields' => 'ids',
                'number' => 1,
            )
        );
        $main_network_id = array_shift( $_networks );
    }

    /** * Filters the main network ID. * * @since 4.3.0 * * @param int $main_network_id The ID of the main network. */
            $current_blog = get_site_by_path( $domain$path, 1 );
        }
    } elseif ( ! $subdomain ) {
        /* * A "subdomain" installation can be re-interpreted to mean "can support any domain". * If we're not dealing with one of these installations, then the important part is determining * the network first, because we need the network's path to identify any sites. */
        $current_site = wp_cache_get( 'current_network', 'site-options' );
        if ( ! $current_site ) {
            // Are there even two networks installed?             $networks = get_networks( array( 'number' => 2 ) );
            if ( count( $networks ) === 1 ) {
                $current_site = array_shift( $networks );
                wp_cache_add( 'current_network', $current_site, 'site-options' );
            } elseif ( empty( $networks ) ) {
                // A network not found hook should fire here.                 return false;
            }
        }

        if ( empty( $current_site ) ) {
            $current_site = WP_Network::get_by_path( $domain$path, 1 );
        }

function get_admin_users_for_domain( $domain = '', $path = '' ) {
    _deprecated_function( __FUNCTION__, '4.4.0' );

    global $wpdb;

    if ( ! $domain ) {
        $network_id = get_current_network_id();
    } else {
        $_networks  = get_networks( array(
            'fields' => 'ids',
            'number' => 1,
            'domain' => $domain,
            'path'   => $path,
        ) );
        $network_id = ! empty( $_networks ) ? array_shift( $_networks ) : 0;
    }

    if ( $network_id )
        return $wpdb->get_results( $wpdb->prepare( "SELECT u.ID, u.user_login, u.user_pass FROM $wpdb->users AS u, $wpdb->sitemeta AS sm WHERE sm.meta_key = 'admin_user_id' AND u.ID = sm.meta_value AND sm.site_id = %d", $network_id ), ARRAY_A );

    
/* * If we've gotten to this function during normal execution, there is * more than one network installed. At this point, who knows how many * we have. Attempt to optimize for the situation where networks are * only domains, thus meaning paths never need to be considered. * * This is a very basic optimization; anything further could have * drawbacks depending on the setup, so this is best done per-installation. */
        $using_paths = true;
        if ( wp_using_ext_object_cache() ) {
            $using_paths = get_networks(
                array(
                    'number'       => 1,
                    'count'        => true,
                    'path__not_in' => '/',
                )
            );
        }

        $paths = array();
        if ( $using_paths ) {
            $path_segments = array_filter( explode( '/', trim( $path, '/' ) ) );

            
Home | Imprint | This part of the site doesn't use cookies.