Ticket #35791: 35791-implementation.patch
File 35791-implementation.patch, 12.0 KB (added by , 9 years ago) |
---|
-
src/wp-includes/http.php
598 598 * Attached to the http_request_host_is_external filter. 599 599 * 600 600 * @since 3.6.0 601 * @since 4.6.0 Converted to use get_sites() 601 602 * 602 603 * @global wpdb $wpdb WordPress database abstraction object. 603 604 * @staticvar array $queried … … 615 616 return true; 616 617 if ( isset( $queried[ $host ] ) ) 617 618 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( 621 'domain' => $host, 622 'count' => true 623 ) ); 624 625 $queried[ $host ] = (bool) $result; 626 619 627 return $queried[ $host ]; 620 628 } 621 629 -
src/wp-includes/ms-blogs.php
468 468 } 469 469 470 470 /** 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 site objects. 486 * 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 only or empty 490 * for all fields. Default empty. 491 * @type int $ID Currently unused. 492 * @type int $number Maximum number of sites to retrieve. Default null (no limit). 493 * @type int $offset Number of sites to offset the query. Used to build LIMIT clause. 494 * Default 0. 495 * @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true. 496 * @type string|array $orderby Site status or array of statuses. To use 'meta_value' or 497 * 'meta_value_num', `$meta_key` must also be defined. To sort by a 498 * specific `$meta_query` clause, use that clause's array key. Accepts 499 * 'site_agent', 'site_approved', 'site_author', 'site_author_email', 500 * 'site_author_IP', 'site_author_url', 'site_content', 'site_date', 501 * 'site_date_gmt', 'blog_id', 'site_karma', 'site_parent', 'site_id', 502 * 'site_type', 'user_id', 'site__in', 'meta_value', 'meta_value_num', 503 * the value of $meta_key, and the array keys of `$meta_query`. Also 504 * accepts false, an empty array, or 'none' to disable `ORDER BY` clause. 505 * Default 'site_date_gmt'. 506 * @type string $order How to order retrieved sites. Accepts 'ASC', 'DESC'. Default 'DESC'. 507 * @type string $domain Limit results to those affiliated with a given network ID. 508 * Default current network ID. 509 * @type array $domain__in Array of domains to include affiliated sites for. Default empty. 510 * @type array $domain__not_in Array of domains to exclude affiliated sites for. Default empty. 511 * @type string $path Limit results to those affiliated with a given network ID. 512 * Default current network ID. 513 * @type array $path__in Array of paths to include affiliated sites for. Default empty. 514 * @type array $path__not_in Array of paths to exclude affiliated sites for. Default empty. 515 * @type int $network_id Limit results to those affiliated with a given network ID. 516 * Default current network ID. 517 * @type array $network__in Array of network IDs to include affiliated sites for. Default empty. 518 * @type array $network__not_in Array of network IDs to exclude affiliated sites for. Default empty. 519 * @type string $search Search term(s) to retrieve matching sites for. Default empty. 520 * @type bool $update_site_cache Whether to prime the cache for site networks. Default false. 521 * } 522 * @return array List of sites. 523 */ 524 function get_sites( $args = array() ) { 525 $query = new WP_Site_Query(); 526 527 return $query->query( $args ); 528 } 529 530 531 /** 471 532 * Retrieve option value for a given blog id based on name of option. 472 533 * 473 534 * If the option does not exist or does not have a value, then the return value -
src/wp-includes/ms-functions.php
308 308 global $wpdb; 309 309 310 310 $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' ); 313 313 314 if ( $id == -1 ) // blog does not exist 314 if ( $id == - 1 ) // blog does not exist 315 { 315 316 return 0; 316 elseif ( $id )317 } elseif ( $id ) { 317 318 return (int) $id; 319 } 318 320 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' ); 320 326 321 if ( ! $id ) {322 wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' );323 327 return 0; 324 328 } 325 329 … … 1255 1259 * @return int 1256 1260 */ 1257 1261 function domain_exists($domain, $path, $site_id = 1) { 1258 global $wpdb;1259 1262 $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) );1261 1263 1264 $result = get_sites( array( 1265 'path' => $path, 1266 'domain' => $domain, 1267 'network' => $site_id, 1268 'number' => 1, 1269 'fields' => 'ids' 1270 ) ); 1271 1272 $site = array_shift( $result ); 1273 1262 1274 /** 1263 1275 * Filter whether a blogname is taken. 1264 1276 * 1265 1277 * @since 3.5.0 1266 1278 * 1267 * @param int|null $ resultThe blog_id if the blogname exists, null otherwise.1279 * @param int|null $site The blog_id if the blogname exists, null otherwise. 1268 1280 * @param string $domain Domain to be checked. 1269 1281 * @param string $path Path to be checked. 1270 1282 * @param int $site_id Site ID. Relevant only on multi-network installs. 1271 1283 */ 1272 return apply_filters( 'domain_exists', $ result, $domain, $path, $site_id );1284 return apply_filters( 'domain_exists', $site, $domain, $path, $site_id ); 1273 1285 } 1274 1286 1275 1287 /** … … 2246 2258 * Update the network-wide site count. 2247 2259 * 2248 2260 * @since 3.7.0 2261 * @since 4.6.0 Converted to use get_sites() 2249 2262 * 2250 2263 * @global wpdb $wpdb WordPress database abstraction object. 2251 2264 */ … … 2252 2265 function wp_update_network_site_counts() { 2253 2266 global $wpdb; 2254 2267 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) ); 2268 $count = get_sites( array( 2269 'network_id' => $wpdb->siteid, 2270 'spam' => 0, 2271 'deleted' => 0, 2272 'archived' => 0, 2273 'count' => true 2274 ) ); 2275 2256 2276 update_site_option( 'blog_count', $count ); 2257 2277 } 2258 2278 … … 2408 2428 * Return an array of sites for a network or networks. 2409 2429 * 2410 2430 * @since 3.7.0 2431 * @since 4.6.0 Converted to use get_sites() 2411 2432 * 2412 2433 * @global wpdb $wpdb WordPress database abstraction object. 2413 2434 * … … 2432 2453 function wp_get_sites( $args = array() ) { 2433 2454 global $wpdb; 2434 2455 2435 if ( wp_is_large_network() )2436 return array();2437 2438 2456 $defaults = array( 2439 2457 'network_id' => $wpdb->siteid, 2440 2458 'public' => null, … … 2448 2466 2449 2467 $args = wp_parse_args( $args, $defaults ); 2450 2468 2451 $query = "SELECT * FROM $wpdb->blogs WHERE 1=1 "; 2469 // Make sure count is disabled. 2470 $args['count'] = false; 2452 2471 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) "; 2456 } 2472 $_sites = get_sites( $args ); 2457 2473 2458 if ( isset( $args['public'] ) ) 2459 $query .= $wpdb->prepare( "AND public = %d ", $args['public'] ); 2474 $results = array(); 2460 2475 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'] ); 2476 foreach ( $_sites as $_site ) { 2477 $results[] = get_site( $_site, ARRAY_A ); 2478 2478 } 2479 2479 2480 $site_results = $wpdb->get_results( $query, ARRAY_A ); 2481 2482 return $site_results; 2480 return $results; 2483 2481 } 2484 2482 2485 2483 /** -
src/wp-includes/ms-load.php
154 154 * Retrieve a site object by its domain and path. 155 155 * 156 156 * @since 3.9.0 157 * @since 4.6.0 Converted to use get_sites() 157 158 * 158 159 * @global wpdb $wpdb WordPress database abstraction object. 159 160 * … … 231 232 $domains = array( $domain ); 232 233 if ( 'www.' === substr( $domain, 0, 4 ) ) { 233 234 $domains[] = substr( $domain, 4 ); 234 $search_domains = "'" . implode( "', '", $wpdb->_escape( $domains ) ) . "'";235 235 } 236 236 237 if ( count( $paths ) > 1 ) { 238 $search_paths = "'" . implode( "', '", $wpdb->_escape( $paths ) ) . "'"; 239 } 237 $args = array( 238 'path__in' => $path, 239 'domain__in' => $domains, 240 'number' => 1 241 ); 240 242 241 243 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" ); 244 $args['orderby'] = 'domain_length path_length'; 245 $args['order'] = 'DESC DESC'; 243 246 } 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 ); 247 $args['orderby'] = 'domain_length'; 248 $args['order'] = 'DESC'; 247 249 } 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] ) ); 250 $args['orderby'] = 'path_length'; 251 $args['order'] = 'DESC'; 253 252 } 254 253 254 $result = get_sites( $args ); 255 256 $site = array_shift( $result ); 255 257 if ( $site ) { 256 258 // @todo get_blog_details() 257 259 return $site;