~canonical-sysadmins/wordpress/4.8.1

« back to all changes in this revision

Viewing changes to wp-admin/includes/class-wp-ms-sites-list-table.php

  • Committer: Barry Price
  • Date: 2016-08-17 04:49:28 UTC
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: barry.price@canonical.com-20160817044928-viijiwb4tl8jwzmp
new upstream release 4.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
        }
60
60
 
61
61
        /**
 
62
         * Prepares the list of sites for display.
 
63
         *
 
64
         * @since 3.1.0
62
65
         *
63
66
         * @global string $s
64
67
         * @global string $mode
67
70
        public function prepare_items() {
68
71
                global $s, $mode, $wpdb;
69
72
 
70
 
                $current_site = get_current_site();
71
 
 
72
73
                if ( ! empty( $_REQUEST['mode'] ) ) {
73
74
                        $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list';
74
75
                        set_user_setting( 'sites_list_mode', $mode );
83
84
                $s = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST[ 's' ] ) ) : '';
84
85
                $wild = '';
85
86
                if ( false !== strpos($s, '*') ) {
86
 
                        $wild = '%';
 
87
                        $wild = '*';
87
88
                        $s = trim($s, '*');
88
89
                }
89
90
 
98
99
                                $_GET['order'] = $_REQUEST['order'] = 'DESC';
99
100
                }
100
101
 
101
 
                $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";
 
102
                $args = array(
 
103
                        'number'     => intval( $per_page ),
 
104
                        'offset'     => intval( ( $pagenum - 1 ) * $per_page ),
 
105
                        'network_id' => get_current_network_id(),
 
106
                );
102
107
 
103
108
                if ( empty($s) ) {
104
109
                        // Nothing to do.
107
112
                                        preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
108
113
                                        preg_match( '/^[0-9]{1,3}\.$/', $s ) ) {
109
114
                        // 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 ) ? '%' : '' ) );
111
116
                        $reg_blog_ids = $wpdb->get_col( $sql );
112
117
 
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
                        }
 
121
                } elseif ( is_numeric( $s ) && empty( $wild ) ) {
 
122
                        $args['ID'] = $s;
120
123
                } 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 );
127
 
                        } 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 );
 
124
                        $args['search'] = $s;
 
125
 
 
126
                        if ( ! is_subdomain_install() ) {
 
127
                                $args['search_columns'] = array( 'path' );
134
128
                        }
135
129
                }
136
130
 
137
131
                $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' ) {
 
132
                if ( 'registered' === $order_by ) {
 
133
                        // registered is a valid field name.
 
134
                } elseif ( 'lastupdated' === $order_by ) {
 
135
                        $order_by = 'last_updated';
 
136
                } elseif ( 'blogname' === $order_by ) {
143
137
                        if ( is_subdomain_install() ) {
144
 
                                $query .= ' ORDER BY domain ';
 
138
                                $order_by = 'domain';
145
139
                        } else {
146
 
                                $query .= ' ORDER BY path ';
 
140
                                $order_by = 'path';
147
141
                        }
148
 
                } elseif ( $order_by === 'blog_id' ) {
149
 
                        $query .= ' ORDER BY blog_id ';
 
142
                } elseif ( 'blog_id' === $order_by ) {
 
143
                        $order_by = 'id';
 
144
                } elseif ( ! $order_by ) {
 
145
                        $order_by = false;
 
146
                }
 
147
 
 
148
                $args['orderby'] = $order_by;
 
149
 
 
150
                if ( $order_by ) {
 
151
                        $args['order'] = ( isset( $_REQUEST['order'] ) && 'DESC' === strtoupper( $_REQUEST['order'] ) ) ? "DESC" : "ASC";
 
152
                }
 
153
 
 
154
                if ( wp_is_large_network() ) {
 
155
                        $args['no_found_rows'] = true;
150
156
                } 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);
 
157
                        $args['no_found_rows'] = false;
 
158
                }
 
159
 
 
160
                /**
 
161
                 * Filters the arguments for the site query in the sites list table.
 
162
                 *
 
163
                 * @since 4.6.0
 
164
                 *
 
165
                 * @param array $args An array of get_sites() arguments.
 
166
                 */
 
167
                $args = apply_filters( 'ms_sites_list_table_query_args', $args );
 
168
 
 
169
                $_sites = get_sites( $args );
 
170
                if ( is_array( $_sites ) ) {
 
171
                        update_site_cache( $_sites );
 
172
 
 
173
                        $this->items = array_slice( $_sites, 0, $per_page );
 
174
                }
 
175
 
 
176
                $total_sites = get_sites( array_merge( $args, array(
 
177
                        'count' => true,
 
178
                        'offset' => 0,
 
179
                        'number' => 0,
 
180
                ) ) );
168
181
 
169
182
                $this->set_pagination_args( array(
170
 
                        'total_items' => $total,
 
183
                        'total_items' => $total_sites,
171
184
                        'per_page' => $per_page,
172
185
                ) );
173
186
        }
224
237
                }
225
238
 
226
239
                /**
227
 
                 * Filter the displayed site columns in Sites list table.
 
240
                 * Filters the displayed site columns in Sites list table.
228
241
                 *
229
242
                 * @since MU
230
243
                 *
445
458
         */
446
459
        public function display_rows() {
447
460
                foreach ( $this->items as $blog ) {
 
461
                        $blog = $blog->to_array();
448
462
                        $class = '';
449
463
                        reset( $this->status_list );
450
464
 
531
545
                $actions['visit']       = "<a href='" . esc_url( get_home_url( $blog['blog_id'], '/' ) ) . "' rel='permalink'>" . __( 'Visit' ) . '</a>';
532
546
 
533
547
                /**
534
 
                 * Filter the action links displayed for each site in the Sites list table.
 
548
                 * Filters the action links displayed for each site in the Sites list table.
535
549
                 *
536
550
                 * The 'Edit', 'Dashboard', 'Delete', and 'Visit' links are displayed by
537
551
                 * default for each site. The site's status determines whether to show the