Make WordPress Core

Ticket #35791: 35791i.1.patch

File 35791i.1.patch, 11.8 KB (added by spacedmonkey, 9 years ago)
  • wp-includes/http.php

     
    606606 * @param string $host
    607607 * @return bool
    608608 */
     609
    609610function ms_allowed_http_request_hosts( $is_external, $host ) {
    610611        global $wpdb;
    611612        static $queried = array();
     
    615616                return true;
    616617        if ( isset( $queried[ $host ] ) )
    617618                return $queried[ $host ];
    618         $queried[ $host ] = (bool) $wpdb->get_var( $wpdb->prepare( "SELECT domain FROM $wpdb->blogs WHERE domain = %s LIMIT 1", $host ) );
     619
     620        $result           = get_sites( array( 'domain' => $host, 'count' => true ) );
     621        $queried[ $host ] = (bool) $result;
     622
    619623        return $queried[ $host ];
    620624}
    621625
  • wp-includes/ms-blogs.php

     
    468468}
    469469
    470470/**
     471 *
     472 * Retrieve list of sites matching criteria.
     473 *
     474 * The defaults are as follows:
     475 *
     476 * @since 4.6.0
     477 *
     478 * @see WP_Site_Query::parse_query()
     479 *
     480 * @param string|array $args {
     481 *     Optional. Array or query string of site query parameters. Default empty.
     482 *
     483 * @type array $site__in Array of site IDs to include. Default empty.
     484 * @type array $site__not_in Array of site IDs to exclude. Default empty.
     485 * @type bool $count Whether to return a site count (true) or array of
     486 *                                                   site objects (false). Default false.
     487 * @type array $date_query Date query clauses to limit sites by. See WP_Date_Query.
     488 *                                                   Default null.
     489 * @type string $fields Site fields to return. Accepts 'ids' for site IDs
     490 *                                                   only or empty for all fields. Default empty.
     491 * @type int $ID Currently unused.
     492 * @type int $number Maximum number of sites to retrieve.
     493 *                                                   Default null (no limit).
     494 * @type int $offset Number of sites to offset the query. Used to build
     495 *                                                   LIMIT clause. Default 0.
     496 * @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query.
     497 *                                                   Default: true.
     498 * @type string|array $orderby Site status or array of statuses. To use 'meta_value'
     499 *                                                   or 'meta_value_num', `$meta_key` must also be defined.
     500 *                                                   To sort by a specific `$meta_query` clause, use that
     501 *                                                   clause's array key. Accepts 'site_agent',
     502 *                                                   'site_approved', 'site_author',
     503 *                                                   'site_author_email', 'site_author_IP',
     504 *                                                   'site_author_url', 'site_content', 'site_date',
     505 *                                                   'site_date_gmt', 'blog_id', 'site_karma',
     506 *                                                   'site_parent', 'site_id', 'site_type',
     507 *                                                   'user_id', 'site__in', 'meta_value', 'meta_value_num',
     508 *                                                   the value of $meta_key, and the array keys of
     509 *                                                   `$meta_query`. Also accepts false, an empty array, or
     510 *                                                   'none' to disable `ORDER BY` clause.
     511 *                                                   Default: 'site_date_gmt'.
     512 * @type string $order How to order retrieved sites. Accepts 'ASC', 'DESC'.
     513 *                                                   Default: 'DESC'.
     514 * @type string $domain Limit results to those affiliated with a given network ID.
     515 *                                                   Default current network id.
     516 * @type array $domain__in Array of domains to include affiliated sites for.
     517 *                                                   Default empty.
     518 * @type array $domain__not_in Array of domains to exclude affiliated sites for.
     519 *                                                   Default empty.
     520 * @type string $path Limit results to those affiliated with a given network ID.
     521 *                                                   Default current network id.
     522 * @type array $path__in Array of paths to include affiliated sites for.
     523 *                                                   Default empty.
     524 * @type array $path__not_in Array of paths to exclude affiliated sites for.
     525 *                                                   Default empty.
     526 * @type int $network_id Limit results to those affiliated with a given network ID.
     527 *                                                   Default current network id.
     528 * @type array $network__in Array of network IDs to include affiliated sites for.
     529 *                                                   Default empty.
     530 * @type array $network__not_in Array of network IDs to exclude affiliated sites for.
     531 *                                                   Default empty.
     532 * @type string $search Search term(s) to retrieve matching sites for.
     533 *                                                   Default empty.
     534 * @type bool $update_site_cache Whether to prime the cache for site networks.
     535 *                                                   Default false.
     536 *
     537 * @return array List of sites.
     538 * */
     539function get_sites( $args = array() ) {
     540        $query = new WP_Site_Query();
     541
     542        return $query->query( $args );
     543}
     544
     545
     546/**
    471547 * Retrieve option value for a given blog id based on name of option.
    472548 *
    473549 * If the option does not exist or does not have a value, then the return value
  • wp-includes/ms-functions.php

     
    308308        global $wpdb;
    309309
    310310        $domain = strtolower( $domain );
    311         $path = strtolower( $path );
    312         $id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' );
     311        $path   = strtolower( $path );
     312        $id     = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' );
    313313
    314         if ( $id == -1 ) // blog does not exist
     314        if ( $id == - 1 ) // blog does not exist
     315        {
    315316                return 0;
    316         elseif ( $id )
     317        } elseif ( $id ) {
    317318                return (int) $id;
     319        }
    318320
    319         $id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s and path = %s /* get_blog_id_from_url */", $domain, $path ) );
     321        $args   = array( 'domain' => $domain, 'path' => $path, 'fields' => 'ids' );
     322        $result = get_sites( $args );
     323        $id     = array_shift( $result );
     324        if ( ! $id ) {
     325                wp_cache_set( md5( $domain . $path ), - 1, 'blog-id-cache' );
    320326
    321         if ( ! $id ) {
    322                 wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' );
    323327                return 0;
    324328        }
    325329
     
    12551259 * @return int
    12561260 */
    12571261function domain_exists($domain, $path, $site_id = 1) {
    1258         global $wpdb;
    12591262        $path = trailingslashit( $path );
    1260         $result = $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s AND site_id = %d", $domain, $path, $site_id) );
    12611263
     1264        $args   = array( 'path' => $path, 'domain' => $domain, 'network' => $site_id, 'number' => 1, 'fields' => 'ids' );
     1265        $result = get_sites( $args );
     1266        $site   = array_shift( $result );
     1267
    12621268        /**
    12631269         * Filter whether a blogname is taken.
    12641270         *
    12651271         * @since 3.5.0
    12661272         *
    1267          * @param int|null $result  The blog_id if the blogname exists, null otherwise.
     1273         * @param int|null $site  The blog_id if the blogname exists, null otherwise.
    12681274         * @param string   $domain  Domain to be checked.
    12691275         * @param string   $path    Path to be checked.
    12701276         * @param int      $site_id Site ID. Relevant only on multi-network installs.
    12711277         */
    1272         return apply_filters( 'domain_exists', $result, $domain, $path, $site_id );
     1278        return apply_filters( 'domain_exists', $site, $domain, $path, $site_id );
    12731279}
    12741280
    12751281/**
     
    22522258function wp_update_network_site_counts() {
    22532259        global $wpdb;
    22542260
    2255         $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(blog_id) as c FROM $wpdb->blogs WHERE site_id = %d AND spam = '0' AND deleted = '0' and archived = '0'", $wpdb->siteid) );
     2261        $args  = array( 'network_id' => $wpdb->siteid, 'spam' => 0, 'deleted' => 0, 'archived' => 0, 'count' => true );
     2262        $count = get_sites( $args );
     2263
    22562264        update_site_option( 'blog_count', $count );
    22572265}
    22582266
     
    24322440function wp_get_sites( $args = array() ) {
    24332441        global $wpdb;
    24342442
    2435         if ( wp_is_large_network() )
    2436                 return array();
    2437 
    24382443        $defaults = array(
    24392444                'network_id' => $wpdb->siteid,
    24402445                'public'     => null,
     
    24482453
    24492454        $args = wp_parse_args( $args, $defaults );
    24502455
    2451         $query = "SELECT * FROM $wpdb->blogs WHERE 1=1 ";
     2456        // Make sure count is disabled.
     2457        $args['count'] = false;
    24522458
    2453         if ( isset( $args['network_id'] ) && ( is_array( $args['network_id'] ) || is_numeric( $args['network_id'] ) ) ) {
    2454                 $network_ids = implode( ',', wp_parse_id_list( $args['network_id'] ) );
    2455                 $query .= "AND site_id IN ($network_ids) ";
     2459        $_sites  = get_sites( $args );
     2460        $results = array();
     2461        foreach ( $_sites as $_site ) {
     2462                $results[] = get_site( $_site, ARRAY_A );
    24562463        }
    24572464
    2458         if ( isset( $args['public'] ) )
    2459                 $query .= $wpdb->prepare( "AND public = %d ", $args['public'] );
    2460 
    2461         if ( isset( $args['archived'] ) )
    2462                 $query .= $wpdb->prepare( "AND archived = %d ", $args['archived'] );
    2463 
    2464         if ( isset( $args['mature'] ) )
    2465                 $query .= $wpdb->prepare( "AND mature = %d ", $args['mature'] );
    2466 
    2467         if ( isset( $args['spam'] ) )
    2468                 $query .= $wpdb->prepare( "AND spam = %d ", $args['spam'] );
    2469 
    2470         if ( isset( $args['deleted'] ) )
    2471                 $query .= $wpdb->prepare( "AND deleted = %d ", $args['deleted'] );
    2472 
    2473         if ( isset( $args['limit'] ) && $args['limit'] ) {
    2474                 if ( isset( $args['offset'] ) && $args['offset'] )
    2475                         $query .= $wpdb->prepare( "LIMIT %d , %d ", $args['offset'], $args['limit'] );
    2476                 else
    2477                         $query .= $wpdb->prepare( "LIMIT %d ", $args['limit'] );
    2478         }
    2479 
    2480         $site_results = $wpdb->get_results( $query, ARRAY_A );
    2481 
    2482         return $site_results;
     2465        return $results;
    24832466}
    24842467
    24852468/**
  • wp-includes/ms-load.php

     
    231231        $domains = array( $domain );
    232232        if ( 'www.' === substr( $domain, 0, 4 ) ) {
    233233                $domains[] = substr( $domain, 4 );
    234                 $search_domains = "'" . implode( "', '", $wpdb->_escape( $domains ) ) . "'";
    235234        }
    236235
    237         if ( count( $paths ) > 1 ) {
    238                 $search_paths = "'" . implode( "', '", $wpdb->_escape( $paths ) ) . "'";
    239         }
    240236
     237        $args = array( 'path__in' => $path, 'domain__in' => $domains, 'number' => 1 );
     238
    241239        if ( count( $domains ) > 1 && count( $paths ) > 1 ) {
    242                 $site = $wpdb->get_row( "SELECT * FROM $wpdb->blogs WHERE domain IN ($search_domains) AND path IN ($search_paths) ORDER BY CHAR_LENGTH(domain) DESC, CHAR_LENGTH(path) DESC LIMIT 1" );
     240                $args['orderby'] = 'domain_length path_length';
     241                $args['order']   = 'DESC DESC';
    243242        } elseif ( count( $domains ) > 1 ) {
    244                 $sql = $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE path = %s", $paths[0] );
    245                 $sql .= " AND domain IN ($search_domains) ORDER BY CHAR_LENGTH(domain) DESC LIMIT 1";
    246                 $site = $wpdb->get_row( $sql );
     243                $args['orderby'] = 'domain_length';
     244                $args['order']   = 'DESC';
    247245        } elseif ( count( $paths ) > 1 ) {
    248                 $sql = $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $domains[0] );
    249                 $sql .= " AND path IN ($search_paths) ORDER BY CHAR_LENGTH(path) DESC LIMIT 1";
    250                 $site = $wpdb->get_row( $sql );
    251         } else {
    252                 $site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $domains[0], $paths[0] ) );
     246                $args['orderby'] = 'path_length';
     247                $args['order']   = 'DESC';
    253248        }
    254249
     250        $result = get_sites( $args );
     251        $site   = array_shift( $result );
    255252        if ( $site ) {
    256253                // @todo get_blog_details()
    257254                return $site;