Ticket #35697: 35697.diff
File 35697.diff, 2.2 KB (added by , 9 years ago) |
---|
-
src/wp-includes/ms-functions.php
2444 2444 'deleted' => null, 2445 2445 'limit' => 100, 2446 2446 'offset' => 0, 2447 'fields' => 'all', 2447 2448 ); 2448 2449 2449 2450 $args = wp_parse_args( $args, $defaults ); 2450 2451 2451 $query = "SELECT * FROM $wpdb->blogs WHERE 1=1 "; 2452 $selects = array(); 2453 switch ( $args['fields'] ) { 2454 case 'all': 2455 $selects = array( '*' ); 2456 break; 2457 case 'ids': 2458 $selects = array( 'blog_id' ); 2459 break; 2460 case 'count': 2461 $selects = array( 'COUNT(*)' ); 2462 break; 2463 case 'id=>domain': 2464 $selects = array( 'blog_id', 'domain' ); 2465 break; 2466 case 'id=>path': 2467 $selects = array( 'blog_id', 'path' ); 2468 break; 2469 case 'id=>network_id': 2470 $selects = array( 'blog_id', 'site_id' ); 2471 break; 2472 } 2452 2473 2474 $fields = implode( ', ', $selects ); 2475 2476 $query = "SELECT $fields FROM $wpdb->blogs WHERE 1=1 "; 2477 2453 2478 if ( isset( $args['network_id'] ) && ( is_array( $args['network_id'] ) || is_numeric( $args['network_id'] ) ) ) { 2454 2479 $network_ids = implode( ',', wp_parse_id_list( $args['network_id'] ) ); 2455 2480 $query .= "AND site_id IN ($network_ids) "; … … 2477 2502 $query .= $wpdb->prepare( "LIMIT %d ", $args['limit'] ); 2478 2503 } 2479 2504 2505 if ( 'count' === $args['fields'] ) { 2506 return $wpdb->get_var( $query ); 2507 } 2508 2480 2509 $site_results = $wpdb->get_results( $query, ARRAY_A ); 2481 2510 2511 $_site_results = array(); 2512 if ( 'id=>domain' === $args['fields'] ) { 2513 foreach ( $site_results as $site ) { 2514 $_site_results[ $site['blog_id'] ] = $site['domain']; 2515 } 2516 } elseif ( 'id=>path' === $args['fields'] ) { 2517 foreach ( $site_results as $site ) { 2518 $_site_results[ $site['blog_id'] ] = $site['path']; 2519 } 2520 } elseif ( 'id=>network_id' === $args['fields'] ) { 2521 foreach ( $site_results as $site ) { 2522 $_site_results[ $site['blog_id'] ] = $site['site_id']; 2523 } 2524 } elseif ( 'ids' === $args['fields'] ) { 2525 foreach ( $site_results as $site ) { 2526 $_site_results[] = $site['blog_id']; 2527 } 2528 } 2529 2530 if ( ! empty( $_site_results ) ) { 2531 $site_results = $_site_results; 2532 } 2533 2482 2534 return $site_results; 2483 2535 } 2484 2536