Changeset 37736
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-ms-sites-list-table.php
r37488 r37736 68 68 global $s, $mode, $wpdb; 69 69 70 $current_site = get_current_site();71 72 70 if ( ! empty( $_REQUEST['mode'] ) ) { 73 71 $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list'; … … 84 82 $wild = ''; 85 83 if ( false !== strpos($s, '*') ) { 86 $wild = ' %';84 $wild = '*'; 87 85 $s = trim($s, '*'); 88 86 } … … 99 97 } 100 98 101 $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' "; 99 $args = array( 100 'number' => intval( $per_page ), 101 'offset' => intval( ( $pagenum - 1 ) * $per_page ), 102 'network_id' => get_current_network_id(), 103 ); 102 104 103 105 if ( empty($s) ) { … … 108 110 preg_match( '/^[0-9]{1,3}\.$/', $s ) ) { 109 111 // 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);112 $sql = $wpdb->prepare( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like( $s ) . ( ! empty( $wild ) ? '%' : '' ) ); 111 113 $reg_blog_ids = $wpdb->get_col( $sql ); 112 114 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 ) . ")"; 115 if ( $reg_blog_ids ) { 116 $args['site__in'] = $reg_blog_ids; 117 } 118 } elseif ( is_numeric( $s ) && empty( $wild ) ) { 119 $args['ID'] = $s; 120 120 } else { 121 if ( is_numeric($s) && empty( $wild ) ) { 122 $query .= $wpdb->prepare( " AND ( {$wpdb->blogs}.blog_id = %s )", $s ); 123 } 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 ); 121 $args['search'] = $s; 122 123 if ( ! is_subdomain_install() ) { 124 $args['search_columns'] = array( 'path' ); 125 } 126 } 127 128 $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : ''; 129 if ( 'registered' === $order_by ) { 130 // registered is a valid field name. 131 } elseif ( 'lastupdated' === $order_by ) { 132 $order_by = 'last_updated'; 133 } elseif ( 'blogname' === $order_by ) { 134 if ( is_subdomain_install() ) { 135 $order_by = 'domain'; 127 136 } else { 128 if ( $s != trim('/', $current_site->path) ) { 129 $blog_s = $wpdb->esc_like( $current_site->path . $s ) . $wild . $wpdb->esc_like( '/' ); 130 } else { 131 $blog_s = $wpdb->esc_like( $s ); 132 } 133 $query .= $wpdb->prepare( " AND ( {$wpdb->blogs}.path LIKE %s )", $blog_s ); 134 } 135 } 136 137 $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' ) { 143 if ( is_subdomain_install() ) { 144 $query .= ' ORDER BY domain '; 145 } else { 146 $query .= ' ORDER BY path '; 147 } 148 } elseif ( $order_by === 'blog_id' ) { 149 $query .= ' ORDER BY blog_id '; 137 $order_by = 'path'; 138 } 139 } elseif ( 'blog_id' === $order_by ) { 140 $order_by = 'id'; 141 } elseif ( ! $order_by ) { 142 $order_by = false; 143 } 144 145 $args['orderby'] = $order_by; 146 147 if ( $order_by ) { 148 $args['order'] = ( isset( $_REQUEST['order'] ) && 'DESC' === strtoupper( $_REQUEST['order'] ) ) ? "DESC" : "ASC"; 149 } 150 151 if ( wp_is_large_network() ) { 152 $args['no_found_rows'] = true; 150 153 } else { 151 $order_by = null; 152 } 153 154 if ( isset( $order_by ) ) { 155 $order = ( isset( $_REQUEST['order'] ) && 'DESC' === strtoupper( $_REQUEST['order'] ) ) ? "DESC" : "ASC"; 156 $query .= $order; 157 } 158 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 ) ); 162 163 $query .= " LIMIT " . intval( ( $pagenum - 1 ) * $per_page ) . ", " . intval( $per_page ); 164 $this->items = $wpdb->get_results( $query, ARRAY_A ); 165 166 if ( wp_is_large_network() ) 167 $total = count($this->items); 154 $args['no_found_rows'] = false; 155 } 156 157 $_sites = get_sites( $args ); 158 if ( is_array( $_sites ) ) { 159 update_site_cache( $_sites ); 160 161 $this->items = array_slice( $_sites, 0, $per_page ); 162 } 163 164 $total_sites = get_sites( array_merge( $args, array( 165 'count' => true, 166 'offset' => 0, 167 'number' => 0, 168 ) ) ); 168 169 169 170 $this->set_pagination_args( array( 170 'total_items' => $total ,171 'total_items' => $total_sites, 171 172 'per_page' => $per_page, 172 173 ) ); … … 446 447 public function display_rows() { 447 448 foreach ( $this->items as $blog ) { 449 $blog = $blog->to_array(); 448 450 $class = ''; 449 451 reset( $this->status_list ); -
trunk/tests/phpunit/tests/multisite/wpMSSitesListTable.php
r37633 r37736 74 74 $expected = array( 75 75 self::$site_ids['wordpress.org/foo/'], 76 self::$site_ids['wordpress.org/foo/bar/'], 77 self::$site_ids['wordpress.org/afoo/'], 76 78 self::$site_ids['make.wordpress.org/foo/'], 77 79 self::$site_ids['www.w.org/foo/'], 80 self::$site_ids['www.w.org/foo/bar/'], 78 81 ); 79 82 … … 132 135 $expected = array( 133 136 self::$site_ids['test.example.org/'], 137 self::$site_ids['test2.example.org/'], 138 self::$site_ids['test3.example.org/zig/'], 139 self::$site_ids['atest.example.org/'], 134 140 ); 135 141 … … 155 161 self::$site_ids['test2.example.org/'], 156 162 self::$site_ids['test3.example.org/zig/'], 163 self::$site_ids['atest.example.org/'], 157 164 ); 158 165 … … 177 184 self::$site_ids['wordpress.org/foo/'], 178 185 self::$site_ids['wordpress.org/foo/bar/'], 186 self::$site_ids['wordpress.org/afoo/'], 179 187 self::$site_ids['make.wordpress.org/foo/'], 180 188 self::$site_ids['www.w.org/foo/'],
Note: See TracChangeset
for help on using the changeset viewer.