Make WordPress Core

Ticket #36675: 36675.diff

File 36675.diff, 5.5 KB (added by flixos90, 9 years ago)
  • src/wp-admin/includes/class-wp-ms-sites-list-table.php

     
    8383                $s = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST[ 's' ] ) ) : '';
    8484                $wild = '';
    8585                if ( false !== strpos($s, '*') ) {
    86                         $wild = '%';
     86                        $wild = '*';
    8787                        $s = trim($s, '*');
    8888                }
    8989
     
    9898                                $_GET['order'] = $_REQUEST['order'] = 'DESC';
    9999                }
    100100
    101                 $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";
     101                $args = array(
     102                        'fields'     => 'ids',
     103                        'number'     => intval( $per_page ),
     104                        'offset'     => intval( ( $pagenum - 1 ) * $per_page ),
     105                        'network_id' => $current_site->id,
     106                );
    102107
    103                 if ( empty($s) ) {
     108                if ( empty( $s ) ) {
    104109                        // Nothing to do.
    105110                } elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s ) ||
    106111                                        preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
     
    107112                                        preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
    108113                                        preg_match( '/^[0-9]{1,3}\.$/', $s ) ) {
    109114                        // IPv4 address
    110                         $sql = $wpdb->prepare( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like( $s ) . $wild );
     115                        $sql = $wpdb->prepare( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like( $s ) . ( ! empty( $wild ) ? '%' : '' ) );
    111116                        $reg_blog_ids = $wpdb->get_col( $sql );
    112117
    113                         if ( !$reg_blog_ids )
    114                                 $reg_blog_ids = array( 0 );
    115 
    116                         $query = "SELECT *
    117                                 FROM {$wpdb->blogs}
    118                                 WHERE site_id = '{$wpdb->siteid}'
    119                                 AND {$wpdb->blogs}.blog_id IN (" . implode( ', ', $reg_blog_ids ) . ")";
     118                        if ( $reg_blog_ids ) {
     119                                $args['site__in'] = $reg_blog_ids;
     120                        }
    120121                } else {
    121                         if ( is_numeric($s) && empty( $wild ) ) {
    122                                 $query .= $wpdb->prepare( " AND ( {$wpdb->blogs}.blog_id = %s )", $s );
     122                        if ( is_numeric( $s ) && empty( $wild ) ) {
     123                                $args['ID'] = $s;
    123124                        } elseif ( is_subdomain_install() ) {
    124                                 $blog_s = str_replace( '.' . $current_site->domain, '', $s );
    125                                 $blog_s = $wpdb->esc_like( $blog_s ) . $wild . $wpdb->esc_like( '.' . $current_site->domain );
    126                                 $query .= $wpdb->prepare( " AND ( {$wpdb->blogs}.domain LIKE %s ) ", $blog_s );
     125                                $args['search'] = str_replace( '.' . $current_site->domain, '', $s ) . $wild . '.' . $current_site->domain;
    127126                        } else {
    128127                                if ( $s != trim('/', $current_site->path) ) {
    129                                         $blog_s = $wpdb->esc_like( $current_site->path . $s ) . $wild . $wpdb->esc_like( '/' );
     128                                        $args['search'] = $current_site->path . $s . $wild . '/';
    130129                                } else {
    131                                         $blog_s = $wpdb->esc_like( $s );
     130                                        $args['search'] = $s;
    132131                                }
    133                                 $query .= $wpdb->prepare( " AND  ( {$wpdb->blogs}.path LIKE %s )", $blog_s );
    134132                        }
    135133                }
    136134
    137135                $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : '';
    138                 if ( $order_by === 'registered' ) {
    139                         $query .= ' ORDER BY registered ';
    140                 } elseif ( $order_by === 'lastupdated' ) {
    141                         $query .= ' ORDER BY last_updated ';
    142                 } elseif ( $order_by === 'blogname' ) {
     136                if ( 'lastupdated' === $order_by ) {
     137                        $order_by = 'last_updated';
     138                } elseif ( 'blogname' === $order_by ) {
    143139                        if ( is_subdomain_install() ) {
    144                                 $query .= ' ORDER BY domain ';
     140                                $order_by = 'domain';
    145141                        } else {
    146                                 $query .= ' ORDER BY path ';
     142                                $order_by = 'path';
    147143                        }
    148                 } elseif ( $order_by === 'blog_id' ) {
    149                         $query .= ' ORDER BY blog_id ';
    150                 } else {
    151                         $order_by = null;
     144                } elseif ( 'blog_id' === $order_by ) {
     145                        $order_by = 'id';
     146                } elseif ( ! $order_by ) {
     147                        $order_by = false;
    152148                }
    153149
    154                 if ( isset( $order_by ) ) {
    155                         $order = ( isset( $_REQUEST['order'] ) && 'DESC' === strtoupper( $_REQUEST['order'] ) ) ? "DESC" : "ASC";
    156                         $query .= $order;
     150                $args['orderby'] = $order_by;
     151
     152                if ( $order_by ) {
     153                        $args['order'] = ( isset( $_REQUEST['order'] ) && 'DESC' === strtoupper( $_REQUEST['order'] ) ) ? "DESC" : "ASC";
    157154                }
    158155
    159                 // Don't do an unbounded count on large networks
    160                 if ( ! wp_is_large_network() )
    161                         $total = $wpdb->get_var( str_replace( 'SELECT *', 'SELECT COUNT( blog_id )', $query ) );
     156                if ( wp_is_large_network() ) {
     157                        $args['no_found_rows'] = true;
     158                } else {
     159                        $args['no_found_rows'] = false;
     160                }
    162161
    163                 $query .= " LIMIT " . intval( ( $pagenum - 1 ) * $per_page ) . ", " . intval( $per_page );
    164                 $this->items = $wpdb->get_results( $query, ARRAY_A );
     162                $query = new WP_Site_Query();
     163                $ids = $query->query( $args );
    165164
    166                 if ( wp_is_large_network() )
    167                         $total = count($this->items);
     165                if ( ! $args['no_found_rows'] ) {
     166                        $total = $query->found_sites;
     167                } else {
     168                        $total = count( $ids );
     169                }
    168170
     171                $this->items = array();
     172                foreach ( $ids as $id ) {
     173                        $this->items[] = get_site( $id, ARRAY_A );
     174                }
     175
    169176                $this->set_pagination_args( array(
    170177                        'total_items' => $total,
    171178                        'per_page' => $per_page,
  • src/wp-includes/class-wp-site-query.php

     
    563563        protected function get_search_sql( $string, $columns ) {
    564564                global $wpdb;
    565565
    566                 $like = '%' . $wpdb->esc_like( $string ) . '%';
     566                if ( false !== strpos( $string, '*' ) ) {
     567                        $like = implode( '%', array_map( array( $wpdb, 'esc_like' ), explode( '*', $string ) ) );
     568                } else {
     569                        $like = '%' . $wpdb->esc_like( $string ) . '%';
     570                }
    567571
    568572                $searches = array();
    569573                foreach ( $columns as $column ) {