7 * @since 3.1.0 |
7 * @since 3.1.0 |
8 * @access private |
8 * @access private |
9 */ |
9 */ |
10 class WP_MS_Sites_List_Table extends WP_List_Table { |
10 class WP_MS_Sites_List_Table extends WP_List_Table { |
11 |
11 |
12 function __construct( $args = array() ) { |
12 /** |
|
13 * Constructor. |
|
14 * |
|
15 * @since 3.1.0 |
|
16 * @access public |
|
17 * |
|
18 * @see WP_List_Table::__construct() for more information on default arguments. |
|
19 * |
|
20 * @param array $args An associative array of arguments. |
|
21 */ |
|
22 public function __construct( $args = array() ) { |
13 parent::__construct( array( |
23 parent::__construct( array( |
14 'plural' => 'sites', |
24 'plural' => 'sites', |
15 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
25 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
16 ) ); |
26 ) ); |
17 } |
27 } |
18 |
28 |
19 function ajax_user_can() { |
29 public function ajax_user_can() { |
20 return current_user_can( 'manage_sites' ); |
30 return current_user_can( 'manage_sites' ); |
21 } |
31 } |
22 |
32 |
23 function prepare_items() { |
33 public function prepare_items() { |
24 global $s, $mode, $wpdb, $current_site; |
34 global $s, $mode, $wpdb; |
|
35 |
|
36 $current_site = get_current_site(); |
25 |
37 |
26 $mode = ( empty( $_REQUEST['mode'] ) ) ? 'list' : $_REQUEST['mode']; |
38 $mode = ( empty( $_REQUEST['mode'] ) ) ? 'list' : $_REQUEST['mode']; |
27 |
39 |
28 $per_page = $this->get_items_per_page( 'sites_network_per_page' ); |
40 $per_page = $this->get_items_per_page( 'sites_network_per_page' ); |
29 |
41 |
34 if ( false !== strpos($s, '*') ) { |
46 if ( false !== strpos($s, '*') ) { |
35 $wild = '%'; |
47 $wild = '%'; |
36 $s = trim($s, '*'); |
48 $s = trim($s, '*'); |
37 } |
49 } |
38 |
50 |
39 $like_s = esc_sql( like_escape( $s ) ); |
51 /* |
40 |
52 * If the network is large and a search is not being performed, show only |
41 // If the network is large and a search is not being performed, show only the latest blogs with no paging in order |
53 * the latest blogs with no paging in order to avoid expensive count queries. |
42 // to avoid expensive count queries. |
54 */ |
43 if ( !$s && wp_is_large_network() ) { |
55 if ( !$s && wp_is_large_network() ) { |
44 if ( !isset($_REQUEST['orderby']) ) |
56 if ( !isset($_REQUEST['orderby']) ) |
45 $_GET['orderby'] = $_REQUEST['orderby'] = ''; |
57 $_GET['orderby'] = $_REQUEST['orderby'] = ''; |
46 if ( !isset($_REQUEST['order']) ) |
58 if ( !isset($_REQUEST['order']) ) |
47 $_GET['order'] = $_REQUEST['order'] = 'DESC'; |
59 $_GET['order'] = $_REQUEST['order'] = 'DESC'; |
54 } elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s ) || |
66 } elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s ) || |
55 preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || |
67 preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || |
56 preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || |
68 preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || |
57 preg_match( '/^[0-9]{1,3}\.$/', $s ) ) { |
69 preg_match( '/^[0-9]{1,3}\.$/', $s ) ) { |
58 // IPv4 address |
70 // IPv4 address |
59 $reg_blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE ( '{$like_s}$wild' )" ); |
71 $sql = $wpdb->prepare( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like( $s ) . $wild ); |
|
72 $reg_blog_ids = $wpdb->get_col( $sql ); |
60 |
73 |
61 if ( !$reg_blog_ids ) |
74 if ( !$reg_blog_ids ) |
62 $reg_blog_ids = array( 0 ); |
75 $reg_blog_ids = array( 0 ); |
63 |
76 |
64 $query = "SELECT * |
77 $query = "SELECT * |
65 FROM {$wpdb->blogs} |
78 FROM {$wpdb->blogs} |
66 WHERE site_id = '{$wpdb->siteid}' |
79 WHERE site_id = '{$wpdb->siteid}' |
67 AND {$wpdb->blogs}.blog_id IN (" . implode( ', ', $reg_blog_ids ) . ")"; |
80 AND {$wpdb->blogs}.blog_id IN (" . implode( ', ', $reg_blog_ids ) . ")"; |
68 } else { |
81 } else { |
69 if ( is_numeric($s) && empty( $wild ) ) { |
82 if ( is_numeric($s) && empty( $wild ) ) { |
70 $query .= " AND ( {$wpdb->blogs}.blog_id = '{$like_s}' )"; |
83 $query .= $wpdb->prepare( " AND ( {$wpdb->blogs}.blog_id = %s )", $s ); |
71 } elseif ( is_subdomain_install() ) { |
84 } elseif ( is_subdomain_install() ) { |
72 $blog_s = str_replace( '.' . $current_site->domain, '', $like_s ); |
85 $blog_s = str_replace( '.' . $current_site->domain, '', $s ); |
73 $blog_s .= $wild . '.' . $current_site->domain; |
86 $blog_s = $wpdb->esc_like( $blog_s ) . $wild . $wpdb->esc_like( '.' . $current_site->domain ); |
74 $query .= " AND ( {$wpdb->blogs}.domain LIKE '$blog_s' ) "; |
87 $query .= $wpdb->prepare( " AND ( {$wpdb->blogs}.domain LIKE %s ) ", $blog_s ); |
75 } else { |
88 } else { |
76 if ( $like_s != trim('/', $current_site->path) ) |
89 if ( $s != trim('/', $current_site->path) ) { |
77 $blog_s = $current_site->path . $like_s . $wild . '/'; |
90 $blog_s = $wpdb->esc_like( $current_site->path . $s ) . $wild . $wpdb->esc_like( '/' ); |
78 else |
91 } else { |
79 $blog_s = $like_s; |
92 $blog_s = $wpdb->esc_like( $s ); |
80 $query .= " AND ( {$wpdb->blogs}.path LIKE '$blog_s' )"; |
93 } |
|
94 $query .= $wpdb->prepare( " AND ( {$wpdb->blogs}.path LIKE %s )", $blog_s ); |
81 } |
95 } |
82 } |
96 } |
83 |
97 |
84 $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : ''; |
98 $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : ''; |
85 if ( $order_by == 'registered' ) { |
99 if ( $order_by == 'registered' ) { |
116 'total_items' => $total, |
130 'total_items' => $total, |
117 'per_page' => $per_page, |
131 'per_page' => $per_page, |
118 ) ); |
132 ) ); |
119 } |
133 } |
120 |
134 |
121 function no_items() { |
135 public function no_items() { |
122 _e( 'No sites found.' ); |
136 _e( 'No sites found.' ); |
123 } |
137 } |
124 |
138 |
125 function get_bulk_actions() { |
139 protected function get_bulk_actions() { |
126 $actions = array(); |
140 $actions = array(); |
127 if ( current_user_can( 'delete_sites' ) ) |
141 if ( current_user_can( 'delete_sites' ) ) |
128 $actions['delete'] = __( 'Delete' ); |
142 $actions['delete'] = __( 'Delete' ); |
129 $actions['spam'] = _x( 'Mark as Spam', 'site' ); |
143 $actions['spam'] = _x( 'Mark as Spam', 'site' ); |
130 $actions['notspam'] = _x( 'Not Spam', 'site' ); |
144 $actions['notspam'] = _x( 'Not Spam', 'site' ); |
131 |
145 |
132 return $actions; |
146 return $actions; |
133 } |
147 } |
134 |
148 |
135 function pagination( $which ) { |
149 /** |
|
150 * @param string $which |
|
151 */ |
|
152 protected function pagination( $which ) { |
136 global $mode; |
153 global $mode; |
137 |
154 |
138 parent::pagination( $which ); |
155 parent::pagination( $which ); |
139 |
156 |
140 if ( 'top' == $which ) |
157 if ( 'top' == $which ) |
141 $this->view_switcher( $mode ); |
158 $this->view_switcher( $mode ); |
142 } |
159 } |
143 |
160 |
144 function get_columns() { |
161 public function get_columns() { |
145 $blogname_columns = ( is_subdomain_install() ) ? __( 'Domain' ) : __( 'Path' ); |
162 $blogname_columns = ( is_subdomain_install() ) ? __( 'Domain' ) : __( 'Path' ); |
146 $sites_columns = array( |
163 $sites_columns = array( |
147 'cb' => '<input type="checkbox" />', |
164 'cb' => '<input type="checkbox" />', |
148 'blogname' => $blogname_columns, |
165 'blogname' => $blogname_columns, |
149 'lastupdated' => __( 'Last Updated' ), |
166 'lastupdated' => __( 'Last Updated' ), |
152 ); |
169 ); |
153 |
170 |
154 if ( has_filter( 'wpmublogsaction' ) ) |
171 if ( has_filter( 'wpmublogsaction' ) ) |
155 $sites_columns['plugins'] = __( 'Actions' ); |
172 $sites_columns['plugins'] = __( 'Actions' ); |
156 |
173 |
|
174 /** |
|
175 * Filter the displayed site columns in Sites list table. |
|
176 * |
|
177 * @since MU |
|
178 * |
|
179 * @param array $sites_columns An array of displayed site columns. Default 'cb', |
|
180 * 'blogname', 'lastupdated', 'registered', 'users'. |
|
181 */ |
157 $sites_columns = apply_filters( 'wpmu_blogs_columns', $sites_columns ); |
182 $sites_columns = apply_filters( 'wpmu_blogs_columns', $sites_columns ); |
158 |
183 |
159 return $sites_columns; |
184 return $sites_columns; |
160 } |
185 } |
161 |
186 |
162 function get_sortable_columns() { |
187 protected function get_sortable_columns() { |
163 return array( |
188 return array( |
164 'blogname' => 'blogname', |
189 'blogname' => 'blogname', |
165 'lastupdated' => 'lastupdated', |
190 'lastupdated' => 'lastupdated', |
166 'registered' => 'blog_id', |
191 'registered' => 'blog_id', |
167 ); |
192 ); |
168 } |
193 } |
169 |
194 |
170 function display_rows() { |
195 public function display_rows() { |
171 global $current_site, $mode; |
196 global $mode; |
172 |
197 |
173 $status_list = array( |
198 $status_list = array( |
174 'archived' => array( 'site-archived', __( 'Archived' ) ), |
199 'archived' => array( 'site-archived', __( 'Archived' ) ), |
175 'spam' => array( 'site-spammed', _x( 'Spam', 'site' ) ), |
200 'spam' => array( 'site-spammed', _x( 'Spam', 'site' ) ), |
176 'deleted' => array( 'site-deleted', __( 'Deleted' ) ), |
201 'deleted' => array( 'site-deleted', __( 'Deleted' ) ), |
177 'mature' => array( 'site-mature', __( 'Mature' ) ) |
202 'mature' => array( 'site-mature', __( 'Mature' ) ) |
178 ); |
203 ); |
179 |
204 |
180 $class = ''; |
205 if ( 'list' == $mode ) { |
|
206 $date = __( 'Y/m/d' ); |
|
207 } else { |
|
208 $date = __( 'Y/m/d g:i:s a' ); |
|
209 } |
|
210 |
181 foreach ( $this->items as $blog ) { |
211 foreach ( $this->items as $blog ) { |
182 $class = ( 'alternate' == $class ) ? '' : 'alternate'; |
212 $class = ''; |
183 reset( $status_list ); |
213 reset( $status_list ); |
184 |
214 |
185 $blog_states = array(); |
215 $blog_states = array(); |
186 foreach ( $status_list as $status => $col ) { |
216 foreach ( $status_list as $status => $col ) { |
187 if ( get_blog_status( $blog['blog_id'], $status ) == 1 ) { |
217 if ( get_blog_status( $blog['blog_id'], $status ) == 1 ) { |
188 $class = $col[0]; |
218 $class = " class='{$col[0]}'"; |
189 $blog_states[] = $col[1]; |
219 $blog_states[] = $col[1]; |
190 } |
220 } |
191 } |
221 } |
192 $blog_state = ''; |
222 $blog_state = ''; |
193 if ( ! empty( $blog_states ) ) { |
223 if ( ! empty( $blog_states ) ) { |
198 ++$i; |
228 ++$i; |
199 ( $i == $state_count ) ? $sep = '' : $sep = ', '; |
229 ( $i == $state_count ) ? $sep = '' : $sep = ', '; |
200 $blog_state .= "<span class='post-state'>$state$sep</span>"; |
230 $blog_state .= "<span class='post-state'>$state$sep</span>"; |
201 } |
231 } |
202 } |
232 } |
203 echo "<tr class='$class'>"; |
233 echo "<tr{$class}>"; |
204 |
234 |
205 $blogname = ( is_subdomain_install() ) ? str_replace( '.'.$current_site->domain, '', $blog['domain'] ) : $blog['path']; |
235 $blogname = ( is_subdomain_install() ) ? str_replace( '.' . get_current_site()->domain, '', $blog['domain'] ) : $blog['path']; |
206 |
236 |
207 list( $columns, $hidden ) = $this->get_column_info(); |
237 list( $columns, $hidden ) = $this->get_column_info(); |
208 |
238 |
209 foreach ( $columns as $column_name => $column_display_name ) { |
239 foreach ( $columns as $column_name => $column_display_name ) { |
210 $style = ''; |
240 $style = ''; |
249 'visit' => '', |
279 'visit' => '', |
250 ); |
280 ); |
251 |
281 |
252 $actions['edit'] = '<span class="edit"><a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a></span>'; |
282 $actions['edit'] = '<span class="edit"><a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a></span>'; |
253 $actions['backend'] = "<span class='backend'><a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a></span>'; |
283 $actions['backend'] = "<span class='backend'><a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a></span>'; |
254 if ( $current_site->blog_id != $blog['blog_id'] ) { |
284 if ( get_current_site()->blog_id != $blog['blog_id'] ) { |
255 if ( get_blog_status( $blog['blog_id'], 'deleted' ) == '1' ) |
285 if ( get_blog_status( $blog['blog_id'], 'deleted' ) == '1' ) |
256 $actions['activate'] = '<span class="activate"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=activateblog&id=' . $blog['blog_id'] . '&msg=' . urlencode( sprintf( __( 'You are about to activate the site %s' ), $blogname ) ) ), 'confirm' ) ) . '">' . __( 'Activate' ) . '</a></span>'; |
286 $actions['activate'] = '<span class="activate"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=activateblog&id=' . $blog['blog_id'] . '&msg=' . urlencode( sprintf( __( 'You are about to activate the site %s' ), $blogname ) ) ), 'confirm' ) ) . '">' . __( 'Activate' ) . '</a></span>'; |
257 else |
287 else |
258 $actions['deactivate'] = '<span class="activate"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=deactivateblog&id=' . $blog['blog_id'] . '&msg=' . urlencode( sprintf( __( 'You are about to deactivate the site %s' ), $blogname ) ) ), 'confirm') ) . '">' . __( 'Deactivate' ) . '</a></span>'; |
288 $actions['deactivate'] = '<span class="activate"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=deactivateblog&id=' . $blog['blog_id'] . '&msg=' . urlencode( sprintf( __( 'You are about to deactivate the site %s' ), $blogname ) ) ), 'confirm') ) . '">' . __( 'Deactivate' ) . '</a></span>'; |
259 |
289 |
271 $actions['delete'] = '<span class="delete"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=deleteblog&id=' . $blog['blog_id'] . '&msg=' . urlencode( sprintf( __( 'You are about to delete the site %s.' ), $blogname ) ) ), 'confirm') ) . '">' . __( 'Delete' ) . '</a></span>'; |
301 $actions['delete'] = '<span class="delete"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=deleteblog&id=' . $blog['blog_id'] . '&msg=' . urlencode( sprintf( __( 'You are about to delete the site %s.' ), $blogname ) ) ), 'confirm') ) . '">' . __( 'Delete' ) . '</a></span>'; |
272 } |
302 } |
273 |
303 |
274 $actions['visit'] = "<span class='view'><a href='" . esc_url( get_home_url( $blog['blog_id'], '/' ) ) . "' rel='permalink'>" . __( 'Visit' ) . '</a></span>'; |
304 $actions['visit'] = "<span class='view'><a href='" . esc_url( get_home_url( $blog['blog_id'], '/' ) ) . "' rel='permalink'>" . __( 'Visit' ) . '</a></span>'; |
275 |
305 |
|
306 /** |
|
307 * Filter the action links displayed for each site in the Sites list table. |
|
308 * |
|
309 * The 'Edit', 'Dashboard', 'Delete', and 'Visit' links are displayed by |
|
310 * default for each site. The site's status determines whether to show the |
|
311 * 'Activate' or 'Deactivate' link, 'Unarchive' or 'Archive' links, and |
|
312 * 'Not Spam' or 'Spam' link for each site. |
|
313 * |
|
314 * @since 3.1.0 |
|
315 * |
|
316 * @param array $actions An array of action links to be displayed. |
|
317 * @param int $blog_id The site ID. |
|
318 * @param string $blogname Site path, formatted depending on whether it is a sub-domain |
|
319 * or subdirectory multisite install. |
|
320 */ |
276 $actions = apply_filters( 'manage_sites_action_links', array_filter( $actions ), $blog['blog_id'], $blogname ); |
321 $actions = apply_filters( 'manage_sites_action_links', array_filter( $actions ), $blog['blog_id'], $blogname ); |
277 echo $this->row_actions( $actions ); |
322 echo $this->row_actions( $actions ); |
278 ?> |
323 ?> |
279 </td> |
324 </td> |
280 <?php |
325 <?php |
281 break; |
326 break; |
282 |
327 |
283 case 'lastupdated': |
328 case 'lastupdated': |
284 echo "<td valign='top' class='$column_name column-$column_name'$style>"; |
329 echo "<td class='$column_name column-$column_name'$style>"; |
285 if ( 'list' == $mode ) |
|
286 $date = 'Y/m/d'; |
|
287 else |
|
288 $date = 'Y/m/d \<\b\r \/\> g:i:s a'; |
|
289 echo ( $blog['last_updated'] == '0000-00-00 00:00:00' ) ? __( 'Never' ) : mysql2date( $date, $blog['last_updated'] ); ?> |
330 echo ( $blog['last_updated'] == '0000-00-00 00:00:00' ) ? __( 'Never' ) : mysql2date( $date, $blog['last_updated'] ); ?> |
290 </td> |
331 </td> |
291 <?php |
332 <?php |
292 break; |
333 break; |
293 case 'registered': |
334 case 'registered': |
294 echo "<td valign='top' class='$column_name column-$column_name'$style>"; |
335 echo "<td class='$column_name column-$column_name'$style>"; |
295 if ( $blog['registered'] == '0000-00-00 00:00:00' ) |
336 if ( $blog['registered'] == '0000-00-00 00:00:00' ) |
296 echo '—'; |
337 echo '—'; |
297 else |
338 else |
298 echo mysql2date( $date, $blog['registered'] ); |
339 echo mysql2date( $date, $blog['registered'] ); |
299 ?> |
340 ?> |
300 </td> |
341 </td> |
301 <?php |
342 <?php |
302 break; |
343 break; |
303 case 'users': |
344 case 'users': |
304 echo "<td valign='top' class='$column_name column-$column_name'$style>"; |
345 echo "<td class='$column_name column-$column_name'$style>"; |
305 $blogusers = get_users( array( 'blog_id' => $blog['blog_id'], 'number' => 6) ); |
346 $blogusers = get_users( array( 'blog_id' => $blog['blog_id'], 'number' => 6) ); |
306 if ( is_array( $blogusers ) ) { |
347 if ( is_array( $blogusers ) ) { |
307 $blogusers_warning = ''; |
348 $blogusers_warning = ''; |
308 if ( count( $blogusers ) > 5 ) { |
349 if ( count( $blogusers ) > 5 ) { |
309 $blogusers = array_slice( $blogusers, 0, 5 ); |
350 $blogusers = array_slice( $blogusers, 0, 5 ); |
323 <?php |
364 <?php |
324 break; |
365 break; |
325 |
366 |
326 case 'plugins': ?> |
367 case 'plugins': ?> |
327 <?php if ( has_filter( 'wpmublogsaction' ) ) { |
368 <?php if ( has_filter( 'wpmublogsaction' ) ) { |
328 echo "<td valign='top' class='$column_name column-$column_name'$style>"; |
369 echo "<td class='$column_name column-$column_name'$style>"; |
|
370 /** |
|
371 * Fires inside the auxiliary 'Actions' column of the Sites list table. |
|
372 * |
|
373 * By default this column is hidden unless something is hooked to the action. |
|
374 * |
|
375 * @since MU |
|
376 * |
|
377 * @param int $blog_id The site ID. |
|
378 */ |
329 do_action( 'wpmublogsaction', $blog['blog_id'] ); ?> |
379 do_action( 'wpmublogsaction', $blog['blog_id'] ); ?> |
330 </td> |
380 </td> |
331 <?php } |
381 <?php } |
332 break; |
382 break; |
333 |
383 |
334 default: |
384 default: |
335 echo "<td class='$column_name column-$column_name'$style>"; |
385 echo "<td class='$column_name column-$column_name'$style>"; |
|
386 /** |
|
387 * Fires for each registered custom column in the Sites list table. |
|
388 * |
|
389 * @since 3.1.0 |
|
390 * |
|
391 * @param string $column_name The name of the column to display. |
|
392 * @param int $blog_id The site ID. |
|
393 */ |
336 do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] ); |
394 do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] ); |
337 echo "</td>"; |
395 echo "</td>"; |
338 break; |
396 break; |
339 } |
397 } |
340 } |
398 } |