37 public function __construct( $args = array() ) { |
37 public function __construct( $args = array() ) { |
38 $this->status_list = array( |
38 $this->status_list = array( |
39 'archived' => array( 'site-archived', __( 'Archived' ) ), |
39 'archived' => array( 'site-archived', __( 'Archived' ) ), |
40 'spam' => array( 'site-spammed', _x( 'Spam', 'site' ) ), |
40 'spam' => array( 'site-spammed', _x( 'Spam', 'site' ) ), |
41 'deleted' => array( 'site-deleted', __( 'Deleted' ) ), |
41 'deleted' => array( 'site-deleted', __( 'Deleted' ) ), |
42 'mature' => array( 'site-mature', __( 'Mature' ) ) |
42 'mature' => array( 'site-mature', __( 'Mature' ) ), |
43 ); |
43 ); |
44 |
44 |
45 parent::__construct( array( |
45 parent::__construct( |
46 'plural' => 'sites', |
46 array( |
47 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
47 'plural' => 'sites', |
48 ) ); |
48 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
49 } |
49 ) |
50 |
50 ); |
51 /** |
51 } |
52 * |
52 |
|
53 /** |
53 * @return bool |
54 * @return bool |
54 */ |
55 */ |
55 public function ajax_user_can() { |
56 public function ajax_user_can() { |
56 return current_user_can( 'manage_sites' ); |
57 return current_user_can( 'manage_sites' ); |
57 } |
58 } |
77 |
78 |
78 $per_page = $this->get_items_per_page( 'sites_network_per_page' ); |
79 $per_page = $this->get_items_per_page( 'sites_network_per_page' ); |
79 |
80 |
80 $pagenum = $this->get_pagenum(); |
81 $pagenum = $this->get_pagenum(); |
81 |
82 |
82 $s = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST[ 's' ] ) ) : ''; |
83 $s = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : ''; |
83 $wild = ''; |
84 $wild = ''; |
84 if ( false !== strpos($s, '*') ) { |
85 if ( false !== strpos( $s, '*' ) ) { |
85 $wild = '*'; |
86 $wild = '*'; |
86 $s = trim($s, '*'); |
87 $s = trim( $s, '*' ); |
87 } |
88 } |
88 |
89 |
89 /* |
90 /* |
90 * If the network is large and a search is not being performed, show only |
91 * If the network is large and a search is not being performed, show only |
91 * the latest sites with no paging in order to avoid expensive count queries. |
92 * the latest sites with no paging in order to avoid expensive count queries. |
92 */ |
93 */ |
93 if ( !$s && wp_is_large_network() ) { |
94 if ( ! $s && wp_is_large_network() ) { |
94 if ( !isset($_REQUEST['orderby']) ) |
95 if ( ! isset( $_REQUEST['orderby'] ) ) { |
95 $_GET['orderby'] = $_REQUEST['orderby'] = ''; |
96 $_GET['orderby'] = $_REQUEST['orderby'] = ''; |
96 if ( !isset($_REQUEST['order']) ) |
97 } |
|
98 if ( ! isset( $_REQUEST['order'] ) ) { |
97 $_GET['order'] = $_REQUEST['order'] = 'DESC'; |
99 $_GET['order'] = $_REQUEST['order'] = 'DESC'; |
|
100 } |
98 } |
101 } |
99 |
102 |
100 $args = array( |
103 $args = array( |
101 'number' => intval( $per_page ), |
104 'number' => intval( $per_page ), |
102 'offset' => intval( ( $pagenum - 1 ) * $per_page ), |
105 'offset' => intval( ( $pagenum - 1 ) * $per_page ), |
103 'network_id' => get_current_network_id(), |
106 'network_id' => get_current_network_id(), |
104 ); |
107 ); |
105 |
108 |
106 if ( empty($s) ) { |
109 if ( empty( $s ) ) { |
107 // Nothing to do. |
110 // Nothing to do. |
108 } elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s ) || |
111 } elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s ) || |
109 preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || |
112 preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || |
110 preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || |
113 preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || |
111 preg_match( '/^[0-9]{1,3}\.$/', $s ) ) { |
114 preg_match( '/^[0-9]{1,3}\.$/', $s ) ) { |
112 // IPv4 address |
115 // IPv4 address |
113 $sql = $wpdb->prepare( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like( $s ) . ( ! empty( $wild ) ? '%' : '' ) ); |
116 $sql = $wpdb->prepare( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like( $s ) . ( ! empty( $wild ) ? '%' : '' ) ); |
114 $reg_blog_ids = $wpdb->get_col( $sql ); |
117 $reg_blog_ids = $wpdb->get_col( $sql ); |
115 |
118 |
116 if ( $reg_blog_ids ) { |
119 if ( $reg_blog_ids ) { |
117 $args['site__in'] = $reg_blog_ids; |
120 $args['site__in'] = $reg_blog_ids; |
118 } |
121 } |
169 update_site_cache( $_sites ); |
172 update_site_cache( $_sites ); |
170 |
173 |
171 $this->items = array_slice( $_sites, 0, $per_page ); |
174 $this->items = array_slice( $_sites, 0, $per_page ); |
172 } |
175 } |
173 |
176 |
174 $total_sites = get_sites( array_merge( $args, array( |
177 $total_sites = get_sites( |
175 'count' => true, |
178 array_merge( |
176 'offset' => 0, |
179 $args, |
177 'number' => 0, |
180 array( |
178 ) ) ); |
181 'count' => true, |
179 |
182 'offset' => 0, |
180 $this->set_pagination_args( array( |
183 'number' => 0, |
181 'total_items' => $total_sites, |
184 ) |
182 'per_page' => $per_page, |
185 ) |
183 ) ); |
186 ); |
|
187 |
|
188 $this->set_pagination_args( |
|
189 array( |
|
190 'total_items' => $total_sites, |
|
191 'per_page' => $per_page, |
|
192 ) |
|
193 ); |
184 } |
194 } |
185 |
195 |
186 /** |
196 /** |
187 */ |
197 */ |
188 public function no_items() { |
198 public function no_items() { |
189 _e( 'No sites found.' ); |
199 _e( 'No sites found.' ); |
190 } |
200 } |
191 |
201 |
192 /** |
202 /** |
193 * |
|
194 * @return array |
203 * @return array |
195 */ |
204 */ |
196 protected function get_bulk_actions() { |
205 protected function get_bulk_actions() { |
197 $actions = array(); |
206 $actions = array(); |
198 if ( current_user_can( 'delete_sites' ) ) |
207 if ( current_user_can( 'delete_sites' ) ) { |
199 $actions['delete'] = __( 'Delete' ); |
208 $actions['delete'] = __( 'Delete' ); |
200 $actions['spam'] = _x( 'Mark as Spam', 'site' ); |
209 } |
|
210 $actions['spam'] = _x( 'Mark as Spam', 'site' ); |
201 $actions['notspam'] = _x( 'Not Spam', 'site' ); |
211 $actions['notspam'] = _x( 'Not Spam', 'site' ); |
202 |
212 |
203 return $actions; |
213 return $actions; |
204 } |
214 } |
205 |
215 |
263 * @param array $blog Current site. |
274 * @param array $blog Current site. |
264 */ |
275 */ |
265 public function column_cb( $blog ) { |
276 public function column_cb( $blog ) { |
266 if ( ! is_main_site( $blog['blog_id'] ) ) : |
277 if ( ! is_main_site( $blog['blog_id'] ) ) : |
267 $blogname = untrailingslashit( $blog['domain'] . $blog['path'] ); |
278 $blogname = untrailingslashit( $blog['domain'] . $blog['path'] ); |
268 ?> |
279 ?> |
269 <label class="screen-reader-text" for="blog_<?php echo $blog['blog_id']; ?>"><?php |
280 <label class="screen-reader-text" for="blog_<?php echo $blog['blog_id']; ?>"> |
270 printf( __( 'Select %s' ), $blogname ); |
281 <?php |
271 ?></label> |
282 printf( __( 'Select %s' ), $blogname ); |
272 <input type="checkbox" id="blog_<?php echo $blog['blog_id'] ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ) ?>" /> |
283 ?> |
273 <?php endif; |
284 </label> |
|
285 <input type="checkbox" id="blog_<?php echo $blog['blog_id']; ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ); ?>" /> |
|
286 <?php |
|
287 endif; |
274 } |
288 } |
275 |
289 |
276 /** |
290 /** |
277 * Handles the ID column output. |
291 * Handles the ID column output. |
278 * |
292 * |
391 * @param array $blog Current site. |
405 * @param array $blog Current site. |
392 */ |
406 */ |
393 public function column_users( $blog ) { |
407 public function column_users( $blog ) { |
394 $user_count = wp_cache_get( $blog['blog_id'] . '_user_count', 'blog-details' ); |
408 $user_count = wp_cache_get( $blog['blog_id'] . '_user_count', 'blog-details' ); |
395 if ( ! $user_count ) { |
409 if ( ! $user_count ) { |
396 $blog_users = get_users( array( 'blog_id' => $blog['blog_id'], 'fields' => 'ID' ) ); |
410 $blog_users = new WP_User_Query( |
397 $user_count = count( $blog_users ); |
411 array( |
398 unset( $blog_users ); |
412 'blog_id' => $blog['blog_id'], |
|
413 'fields' => 'ID', |
|
414 'number' => 1, |
|
415 'count_total' => true, |
|
416 ) |
|
417 ); |
|
418 $user_count = $blog_users->get_total(); |
399 wp_cache_set( $blog['blog_id'] . '_user_count', $user_count, 'blog-details', 12 * HOUR_IN_SECONDS ); |
419 wp_cache_set( $blog['blog_id'] . '_user_count', $user_count, 'blog-details', 12 * HOUR_IN_SECONDS ); |
400 } |
420 } |
401 |
421 |
402 printf( |
422 printf( |
403 '<a href="%s">%s</a>', |
423 '<a href="%s">%s</a>', |
447 */ |
467 */ |
448 do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] ); |
468 do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] ); |
449 } |
469 } |
450 |
470 |
451 /** |
471 /** |
452 * |
|
453 * @global string $mode |
472 * @global string $mode |
454 */ |
473 */ |
455 public function display_rows() { |
474 public function display_rows() { |
456 foreach ( $this->items as $blog ) { |
475 foreach ( $this->items as $blog ) { |
457 $blog = $blog->to_array(); |
476 $blog = $blog->to_array(); |
458 $class = ''; |
477 $class = ''; |
459 reset( $this->status_list ); |
478 reset( $this->status_list ); |
460 |
479 |
461 foreach ( $this->status_list as $status => $col ) { |
480 foreach ( $this->status_list as $status => $col ) { |
462 if ( $blog[ $status ] == 1 ) { |
481 if ( $blog[ $status ] == 1 ) { |
500 |
519 |
501 $blogname = untrailingslashit( $blog['domain'] . $blog['path'] ); |
520 $blogname = untrailingslashit( $blog['domain'] . $blog['path'] ); |
502 |
521 |
503 // Preordered. |
522 // Preordered. |
504 $actions = array( |
523 $actions = array( |
505 'edit' => '', 'backend' => '', |
524 'edit' => '', |
506 'activate' => '', 'deactivate' => '', |
525 'backend' => '', |
507 'archive' => '', 'unarchive' => '', |
526 'activate' => '', |
508 'spam' => '', 'unspam' => '', |
527 'deactivate' => '', |
509 'delete' => '', |
528 'archive' => '', |
510 'visit' => '', |
529 'unarchive' => '', |
511 ); |
530 'spam' => '', |
512 |
531 'unspam' => '', |
513 $actions['edit'] = '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a>'; |
532 'delete' => '', |
514 $actions['backend'] = "<a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a>'; |
533 'visit' => '', |
|
534 ); |
|
535 |
|
536 $actions['edit'] = '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a>'; |
|
537 $actions['backend'] = "<a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a>'; |
515 if ( get_network()->site_id != $blog['blog_id'] ) { |
538 if ( get_network()->site_id != $blog['blog_id'] ) { |
516 if ( $blog['deleted'] == '1' ) { |
539 if ( $blog['deleted'] == '1' ) { |
517 $actions['activate'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=activateblog&id=' . $blog['blog_id'] ), 'activateblog_' . $blog['blog_id'] ) ) . '">' . __( 'Activate' ) . '</a>'; |
540 $actions['activate'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=activateblog&id=' . $blog['blog_id'] ), 'activateblog_' . $blog['blog_id'] ) ) . '">' . __( 'Activate' ) . '</a>'; |
518 } else { |
541 } else { |
519 $actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=deactivateblog&id=' . $blog['blog_id'] ), 'deactivateblog_' . $blog['blog_id'] ) ) . '">' . __( 'Deactivate' ) . '</a>'; |
542 $actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=deactivateblog&id=' . $blog['blog_id'] ), 'deactivateblog_' . $blog['blog_id'] ) ) . '">' . __( 'Deactivate' ) . '</a>'; |
520 } |
543 } |
521 |
544 |
522 if ( $blog['archived'] == '1' ) { |
545 if ( $blog['archived'] == '1' ) { |
523 $actions['unarchive'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=unarchiveblog&id=' . $blog['blog_id'] ), 'unarchiveblog_' . $blog['blog_id'] ) ) . '">' . __( 'Unarchive' ) . '</a>'; |
546 $actions['unarchive'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=unarchiveblog&id=' . $blog['blog_id'] ), 'unarchiveblog_' . $blog['blog_id'] ) ) . '">' . __( 'Unarchive' ) . '</a>'; |
524 } else { |
547 } else { |
525 $actions['archive'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=archiveblog&id=' . $blog['blog_id'] ), 'archiveblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Archive', 'verb; site' ) . '</a>'; |
548 $actions['archive'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=archiveblog&id=' . $blog['blog_id'] ), 'archiveblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Archive', 'verb; site' ) . '</a>'; |
526 } |
549 } |
527 |
550 |
528 if ( $blog['spam'] == '1' ) { |
551 if ( $blog['spam'] == '1' ) { |
529 $actions['unspam'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=unspamblog&id=' . $blog['blog_id'] ), 'unspamblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Not Spam', 'site' ) . '</a>'; |
552 $actions['unspam'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=unspamblog&id=' . $blog['blog_id'] ), 'unspamblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Not Spam', 'site' ) . '</a>'; |
530 } else { |
553 } else { |
531 $actions['spam'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=spamblog&id=' . $blog['blog_id'] ), 'spamblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Spam', 'site' ) . '</a>'; |
554 $actions['spam'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=spamblog&id=' . $blog['blog_id'] ), 'spamblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Spam', 'site' ) . '</a>'; |
532 } |
555 } |
533 |
556 |
534 if ( current_user_can( 'delete_site', $blog['blog_id'] ) ) { |
557 if ( current_user_can( 'delete_site', $blog['blog_id'] ) ) { |
535 $actions['delete'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=deleteblog&id=' . $blog['blog_id'] ), 'deleteblog_' . $blog['blog_id'] ) ) . '">' . __( 'Delete' ) . '</a>'; |
558 $actions['delete'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=deleteblog&id=' . $blog['blog_id'] ), 'deleteblog_' . $blog['blog_id'] ) ) . '">' . __( 'Delete' ) . '</a>'; |
536 } |
559 } |
537 } |
560 } |
538 |
561 |
539 $actions['visit'] = "<a href='" . esc_url( get_home_url( $blog['blog_id'], '/' ) ) . "' rel='bookmark'>" . __( 'Visit' ) . '</a>'; |
562 $actions['visit'] = "<a href='" . esc_url( get_home_url( $blog['blog_id'], '/' ) ) . "' rel='bookmark'>" . __( 'Visit' ) . '</a>'; |
540 |
563 |
541 /** |
564 /** |
542 * Filters the action links displayed for each site in the Sites list table. |
565 * Filters the action links displayed for each site in the Sites list table. |
543 * |
566 * |
544 * The 'Edit', 'Dashboard', 'Delete', and 'Visit' links are displayed by |
567 * The 'Edit', 'Dashboard', 'Delete', and 'Visit' links are displayed by |
546 * 'Activate' or 'Deactivate' link, 'Unarchive' or 'Archive' links, and |
569 * 'Activate' or 'Deactivate' link, 'Unarchive' or 'Archive' links, and |
547 * 'Not Spam' or 'Spam' link for each site. |
570 * 'Not Spam' or 'Spam' link for each site. |
548 * |
571 * |
549 * @since 3.1.0 |
572 * @since 3.1.0 |
550 * |
573 * |
551 * @param array $actions An array of action links to be displayed. |
574 * @param string[] $actions An array of action links to be displayed. |
552 * @param int $blog_id The site ID. |
575 * @param int $blog_id The site ID. |
553 * @param string $blogname Site path, formatted depending on whether it is a sub-domain |
576 * @param string $blogname Site path, formatted depending on whether it is a sub-domain |
554 * or subdirectory multisite installation. |
577 * or subdirectory multisite installation. |
555 */ |
578 */ |
556 $actions = apply_filters( 'manage_sites_action_links', array_filter( $actions ), $blog['blog_id'], $blogname ); |
579 $actions = apply_filters( 'manage_sites_action_links', array_filter( $actions ), $blog['blog_id'], $blogname ); |
557 return $this->row_actions( $actions ); |
580 return $this->row_actions( $actions ); |
558 } |
581 } |
559 } |
582 } |