]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/includes/class-wp-ms-sites-list-table.php
Wordpress 4.6-scripts
[autoinstalls/wordpress.git] / wp-admin / includes / class-wp-ms-sites-list-table.php
index 9dd1d38f2d9dc382db9dd16430da8abce895ae76..9ce3ffee9be6ccdf8f7a3eccf759397088ee1b64 100644 (file)
@@ -59,6 +59,9 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
        }
 
        /**
+        * Prepares the list of sites for display.
+        *
+        * @since 3.1.0
         *
         * @global string $s
         * @global string $mode
@@ -67,8 +70,6 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
        public function prepare_items() {
                global $s, $mode, $wpdb;
 
-               $current_site = get_current_site();
-
                if ( ! empty( $_REQUEST['mode'] ) ) {
                        $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list';
                        set_user_setting( 'sites_list_mode', $mode );
@@ -83,7 +84,7 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
                $s = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST[ 's' ] ) ) : '';
                $wild = '';
                if ( false !== strpos($s, '*') ) {
-                       $wild = '%';
+                       $wild = '*';
                        $s = trim($s, '*');
                }
 
@@ -98,7 +99,11 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
                                $_GET['order'] = $_REQUEST['order'] = 'DESC';
                }
 
-               $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";
+               $args = array(
+                       'number'     => intval( $per_page ),
+                       'offset'     => intval( ( $pagenum - 1 ) * $per_page ),
+                       'network_id' => get_current_network_id(),
+               );
 
                if ( empty($s) ) {
                        // Nothing to do.
@@ -107,67 +112,75 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
                                        preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
                                        preg_match( '/^[0-9]{1,3}\.$/', $s ) ) {
                        // IPv4 address
-                       $sql = $wpdb->prepare( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like( $s ) . $wild );
+                       $sql = $wpdb->prepare( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like( $s ) . ( ! empty( $wild ) ? '%' : '' ) );
                        $reg_blog_ids = $wpdb->get_col( $sql );
 
-                       if ( !$reg_blog_ids )
-                               $reg_blog_ids = array( 0 );
-
-                       $query = "SELECT *
-                               FROM {$wpdb->blogs}
-                               WHERE site_id = '{$wpdb->siteid}'
-                               AND {$wpdb->blogs}.blog_id IN (" . implode( ', ', $reg_blog_ids ) . ")";
+                       if ( $reg_blog_ids ) {
+                               $args['site__in'] = $reg_blog_ids;
+                       }
+               } elseif ( is_numeric( $s ) && empty( $wild ) ) {
+                       $args['ID'] = $s;
                } else {
-                       if ( is_numeric($s) && empty( $wild ) ) {
-                               $query .= $wpdb->prepare( " AND ( {$wpdb->blogs}.blog_id = %s )", $s );
-                       } elseif ( is_subdomain_install() ) {
-                               $blog_s = str_replace( '.' . $current_site->domain, '', $s );
-                               $blog_s = $wpdb->esc_like( $blog_s ) . $wild . $wpdb->esc_like( '.' . $current_site->domain );
-                               $query .= $wpdb->prepare( " AND ( {$wpdb->blogs}.domain LIKE %s ) ", $blog_s );
-                       } else {
-                               if ( $s != trim('/', $current_site->path) ) {
-                                       $blog_s = $wpdb->esc_like( $current_site->path . $s ) . $wild . $wpdb->esc_like( '/' );
-                               } else {
-                                       $blog_s = $wpdb->esc_like( $s );
-                               }
-                               $query .= $wpdb->prepare( " AND  ( {$wpdb->blogs}.path LIKE %s )", $blog_s );
+                       $args['search'] = $s;
+
+                       if ( ! is_subdomain_install() ) {
+                               $args['search_columns'] = array( 'path' );
                        }
                }
 
                $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : '';
-               if ( $order_by === 'registered' ) {
-                       $query .= ' ORDER BY registered ';
-               } elseif ( $order_by === 'lastupdated' ) {
-                       $query .= ' ORDER BY last_updated ';
-               } elseif ( $order_by === 'blogname' ) {
+               if ( 'registered' === $order_by ) {
+                       // registered is a valid field name.
+               } elseif ( 'lastupdated' === $order_by ) {
+                       $order_by = 'last_updated';
+               } elseif ( 'blogname' === $order_by ) {
                        if ( is_subdomain_install() ) {
-                               $query .= ' ORDER BY domain ';
+                               $order_by = 'domain';
                        } else {
-                               $query .= ' ORDER BY path ';
+                               $order_by = 'path';
                        }
-               } elseif ( $order_by === 'blog_id' ) {
-                       $query .= ' ORDER BY blog_id ';
-               } else {
-                       $order_by = null;
+               } elseif ( 'blog_id' === $order_by ) {
+                       $order_by = 'id';
+               } elseif ( ! $order_by ) {
+                       $order_by = false;
                }
 
-               if ( isset( $order_by ) ) {
-                       $order = ( isset( $_REQUEST['order'] ) && 'DESC' === strtoupper( $_REQUEST['order'] ) ) ? "DESC" : "ASC";
-                       $query .= $order;
+               $args['orderby'] = $order_by;
+
+               if ( $order_by ) {
+                       $args['order'] = ( isset( $_REQUEST['order'] ) && 'DESC' === strtoupper( $_REQUEST['order'] ) ) ? "DESC" : "ASC";
                }
 
-               // Don't do an unbounded count on large networks
-               if ( ! wp_is_large_network() )
-                       $total = $wpdb->get_var( str_replace( 'SELECT *', 'SELECT COUNT( blog_id )', $query ) );
+               if ( wp_is_large_network() ) {
+                       $args['no_found_rows'] = true;
+               } else {
+                       $args['no_found_rows'] = false;
+               }
+
+               /**
+                * Filters the arguments for the site query in the sites list table.
+                *
+                * @since 4.6.0
+                *
+                * @param array $args An array of get_sites() arguments.
+                */
+               $args = apply_filters( 'ms_sites_list_table_query_args', $args );
+
+               $_sites = get_sites( $args );
+               if ( is_array( $_sites ) ) {
+                       update_site_cache( $_sites );
 
-               $query .= " LIMIT " . intval( ( $pagenum - 1 ) * $per_page ) . ", " . intval( $per_page );
-               $this->items = $wpdb->get_results( $query, ARRAY_A );
+                       $this->items = array_slice( $_sites, 0, $per_page );
+               }
 
-               if ( wp_is_large_network() )
-                       $total = count($this->items);
+               $total_sites = get_sites( array_merge( $args, array(
+                       'count' => true,
+                       'offset' => 0,
+                       'number' => 0,
+               ) ) );
 
                $this->set_pagination_args( array(
-                       'total_items' => $total,
+                       'total_items' => $total_sites,
                        'per_page' => $per_page,
                ) );
        }
@@ -224,7 +237,7 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
                }
 
                /**
-                * Filter the displayed site columns in Sites list table.
+                * Filters the displayed site columns in Sites list table.
                 *
                 * @since MU
                 *
@@ -445,6 +458,7 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
         */
        public function display_rows() {
                foreach ( $this->items as $blog ) {
+                       $blog = $blog->to_array();
                        $class = '';
                        reset( $this->status_list );
 
@@ -531,7 +545,7 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
                $actions['visit']       = "<a href='" . esc_url( get_home_url( $blog['blog_id'], '/' ) ) . "' rel='permalink'>" . __( 'Visit' ) . '</a>';
 
                /**
-                * Filter the action links displayed for each site in the Sites list table.
+                * Filters the action links displayed for each site in the Sites list table.
                 *
                 * The 'Edit', 'Dashboard', 'Delete', and 'Visit' links are displayed by
                 * default for each site. The site's status determines whether to show the