1 <?php |
1 <?php |
2 /** |
2 /** |
3 * Sites List Table class. |
3 * List Table API: WP_MS_Sites_List_Table class |
4 * |
4 * |
5 * @package WordPress |
5 * @package WordPress |
6 * @subpackage List_Table |
6 * @subpackage Administration |
|
7 * @since 3.1.0 |
|
8 */ |
|
9 |
|
10 /** |
|
11 * Core class used to implement displaying sites in a list table for the network admin. |
|
12 * |
7 * @since 3.1.0 |
13 * @since 3.1.0 |
8 * @access private |
14 * @access private |
|
15 * |
|
16 * @see WP_List_Table |
9 */ |
17 */ |
10 class WP_MS_Sites_List_Table extends WP_List_Table { |
18 class WP_MS_Sites_List_Table extends WP_List_Table { |
11 |
19 |
12 /** |
20 /** |
|
21 * Site status list. |
|
22 * |
|
23 * @since 4.3.0 |
|
24 * @var array |
|
25 */ |
|
26 public $status_list; |
|
27 |
|
28 /** |
13 * Constructor. |
29 * Constructor. |
14 * |
30 * |
15 * @since 3.1.0 |
31 * @since 3.1.0 |
16 * @access public |
|
17 * |
32 * |
18 * @see WP_List_Table::__construct() for more information on default arguments. |
33 * @see WP_List_Table::__construct() for more information on default arguments. |
19 * |
34 * |
20 * @param array $args An associative array of arguments. |
35 * @param array $args An associative array of arguments. |
21 */ |
36 */ |
22 public function __construct( $args = array() ) { |
37 public function __construct( $args = array() ) { |
|
38 $this->status_list = array( |
|
39 'archived' => array( 'site-archived', __( 'Archived' ) ), |
|
40 'spam' => array( 'site-spammed', _x( 'Spam', 'site' ) ), |
|
41 'deleted' => array( 'site-deleted', __( 'Deleted' ) ), |
|
42 'mature' => array( 'site-mature', __( 'Mature' ) ) |
|
43 ); |
|
44 |
23 parent::__construct( array( |
45 parent::__construct( array( |
24 'plural' => 'sites', |
46 'plural' => 'sites', |
25 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
47 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
26 ) ); |
48 ) ); |
27 } |
49 } |
28 |
50 |
|
51 /** |
|
52 * |
|
53 * @return bool |
|
54 */ |
29 public function ajax_user_can() { |
55 public function ajax_user_can() { |
30 return current_user_can( 'manage_sites' ); |
56 return current_user_can( 'manage_sites' ); |
31 } |
57 } |
32 |
58 |
|
59 /** |
|
60 * Prepares the list of sites for display. |
|
61 * |
|
62 * @since 3.1.0 |
|
63 * |
|
64 * @global string $s |
|
65 * @global string $mode |
|
66 * @global wpdb $wpdb |
|
67 */ |
33 public function prepare_items() { |
68 public function prepare_items() { |
34 global $s, $mode, $wpdb; |
69 global $s, $mode, $wpdb; |
35 |
70 |
36 $current_site = get_current_site(); |
71 if ( ! empty( $_REQUEST['mode'] ) ) { |
37 |
72 $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list'; |
38 $mode = ( empty( $_REQUEST['mode'] ) ) ? 'list' : $_REQUEST['mode']; |
73 set_user_setting( 'sites_list_mode', $mode ); |
|
74 } else { |
|
75 $mode = get_user_setting( 'sites_list_mode', 'list' ); |
|
76 } |
39 |
77 |
40 $per_page = $this->get_items_per_page( 'sites_network_per_page' ); |
78 $per_page = $this->get_items_per_page( 'sites_network_per_page' ); |
41 |
79 |
42 $pagenum = $this->get_pagenum(); |
80 $pagenum = $this->get_pagenum(); |
43 |
81 |
44 $s = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST[ 's' ] ) ) : ''; |
82 $s = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST[ 's' ] ) ) : ''; |
45 $wild = ''; |
83 $wild = ''; |
46 if ( false !== strpos($s, '*') ) { |
84 if ( false !== strpos($s, '*') ) { |
47 $wild = '%'; |
85 $wild = '*'; |
48 $s = trim($s, '*'); |
86 $s = trim($s, '*'); |
49 } |
87 } |
50 |
88 |
51 /* |
89 /* |
52 * If the network is large and a search is not being performed, show only |
90 * If the network is large and a search is not being performed, show only |
53 * the latest blogs with no paging in order to avoid expensive count queries. |
91 * the latest sites with no paging in order to avoid expensive count queries. |
54 */ |
92 */ |
55 if ( !$s && wp_is_large_network() ) { |
93 if ( !$s && wp_is_large_network() ) { |
56 if ( !isset($_REQUEST['orderby']) ) |
94 if ( !isset($_REQUEST['orderby']) ) |
57 $_GET['orderby'] = $_REQUEST['orderby'] = ''; |
95 $_GET['orderby'] = $_REQUEST['orderby'] = ''; |
58 if ( !isset($_REQUEST['order']) ) |
96 if ( !isset($_REQUEST['order']) ) |
59 $_GET['order'] = $_REQUEST['order'] = 'DESC'; |
97 $_GET['order'] = $_REQUEST['order'] = 'DESC'; |
60 } |
98 } |
61 |
99 |
62 $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' "; |
100 $args = array( |
|
101 'number' => intval( $per_page ), |
|
102 'offset' => intval( ( $pagenum - 1 ) * $per_page ), |
|
103 'network_id' => get_current_network_id(), |
|
104 ); |
63 |
105 |
64 if ( empty($s) ) { |
106 if ( empty($s) ) { |
65 // Nothing to do. |
107 // Nothing to do. |
66 } elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s ) || |
108 } elseif ( preg_match( '/^[0-9]{1,3}\.[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 ) || |
109 preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || |
68 preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || |
110 preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || |
69 preg_match( '/^[0-9]{1,3}\.$/', $s ) ) { |
111 preg_match( '/^[0-9]{1,3}\.$/', $s ) ) { |
70 // IPv4 address |
112 // IPv4 address |
71 $sql = $wpdb->prepare( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like( $s ) . $wild ); |
113 $sql = $wpdb->prepare( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like( $s ) . ( ! empty( $wild ) ? '%' : '' ) ); |
72 $reg_blog_ids = $wpdb->get_col( $sql ); |
114 $reg_blog_ids = $wpdb->get_col( $sql ); |
73 |
115 |
74 if ( !$reg_blog_ids ) |
116 if ( $reg_blog_ids ) { |
75 $reg_blog_ids = array( 0 ); |
117 $args['site__in'] = $reg_blog_ids; |
76 |
118 } |
77 $query = "SELECT * |
119 } elseif ( is_numeric( $s ) && empty( $wild ) ) { |
78 FROM {$wpdb->blogs} |
120 $args['ID'] = $s; |
79 WHERE site_id = '{$wpdb->siteid}' |
|
80 AND {$wpdb->blogs}.blog_id IN (" . implode( ', ', $reg_blog_ids ) . ")"; |
|
81 } else { |
121 } else { |
82 if ( is_numeric($s) && empty( $wild ) ) { |
122 $args['search'] = $s; |
83 $query .= $wpdb->prepare( " AND ( {$wpdb->blogs}.blog_id = %s )", $s ); |
123 |
84 } elseif ( is_subdomain_install() ) { |
124 if ( ! is_subdomain_install() ) { |
85 $blog_s = str_replace( '.' . $current_site->domain, '', $s ); |
125 $args['search_columns'] = array( 'path' ); |
86 $blog_s = $wpdb->esc_like( $blog_s ) . $wild . $wpdb->esc_like( '.' . $current_site->domain ); |
126 } |
87 $query .= $wpdb->prepare( " AND ( {$wpdb->blogs}.domain LIKE %s ) ", $blog_s ); |
127 } |
|
128 |
|
129 $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : ''; |
|
130 if ( 'registered' === $order_by ) { |
|
131 // registered is a valid field name. |
|
132 } elseif ( 'lastupdated' === $order_by ) { |
|
133 $order_by = 'last_updated'; |
|
134 } elseif ( 'blogname' === $order_by ) { |
|
135 if ( is_subdomain_install() ) { |
|
136 $order_by = 'domain'; |
88 } else { |
137 } else { |
89 if ( $s != trim('/', $current_site->path) ) { |
138 $order_by = 'path'; |
90 $blog_s = $wpdb->esc_like( $current_site->path . $s ) . $wild . $wpdb->esc_like( '/' ); |
139 } |
91 } else { |
140 } elseif ( 'blog_id' === $order_by ) { |
92 $blog_s = $wpdb->esc_like( $s ); |
141 $order_by = 'id'; |
93 } |
142 } elseif ( ! $order_by ) { |
94 $query .= $wpdb->prepare( " AND ( {$wpdb->blogs}.path LIKE %s )", $blog_s ); |
143 $order_by = false; |
95 } |
144 } |
96 } |
145 |
97 |
146 $args['orderby'] = $order_by; |
98 $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : ''; |
147 |
99 if ( $order_by == 'registered' ) { |
148 if ( $order_by ) { |
100 $query .= ' ORDER BY registered '; |
149 $args['order'] = ( isset( $_REQUEST['order'] ) && 'DESC' === strtoupper( $_REQUEST['order'] ) ) ? "DESC" : "ASC"; |
101 } elseif ( $order_by == 'lastupdated' ) { |
150 } |
102 $query .= ' ORDER BY last_updated '; |
151 |
103 } elseif ( $order_by == 'blogname' ) { |
152 if ( wp_is_large_network() ) { |
104 if ( is_subdomain_install() ) |
153 $args['no_found_rows'] = true; |
105 $query .= ' ORDER BY domain '; |
|
106 else |
|
107 $query .= ' ORDER BY path '; |
|
108 } elseif ( $order_by == 'blog_id' ) { |
|
109 $query .= ' ORDER BY blog_id '; |
|
110 } else { |
154 } else { |
111 $order_by = null; |
155 $args['no_found_rows'] = false; |
112 } |
156 } |
113 |
157 |
114 if ( isset( $order_by ) ) { |
158 /** |
115 $order = ( isset( $_REQUEST['order'] ) && 'DESC' == strtoupper( $_REQUEST['order'] ) ) ? "DESC" : "ASC"; |
159 * Filters the arguments for the site query in the sites list table. |
116 $query .= $order; |
160 * |
117 } |
161 * @since 4.6.0 |
118 |
162 * |
119 // Don't do an unbounded count on large networks |
163 * @param array $args An array of get_sites() arguments. |
120 if ( ! wp_is_large_network() ) |
164 */ |
121 $total = $wpdb->get_var( str_replace( 'SELECT *', 'SELECT COUNT( blog_id )', $query ) ); |
165 $args = apply_filters( 'ms_sites_list_table_query_args', $args ); |
122 |
166 |
123 $query .= " LIMIT " . intval( ( $pagenum - 1 ) * $per_page ) . ", " . intval( $per_page ); |
167 $_sites = get_sites( $args ); |
124 $this->items = $wpdb->get_results( $query, ARRAY_A ); |
168 if ( is_array( $_sites ) ) { |
125 |
169 update_site_cache( $_sites ); |
126 if ( wp_is_large_network() ) |
170 |
127 $total = count($this->items); |
171 $this->items = array_slice( $_sites, 0, $per_page ); |
|
172 } |
|
173 |
|
174 $total_sites = get_sites( array_merge( $args, array( |
|
175 'count' => true, |
|
176 'offset' => 0, |
|
177 'number' => 0, |
|
178 ) ) ); |
128 |
179 |
129 $this->set_pagination_args( array( |
180 $this->set_pagination_args( array( |
130 'total_items' => $total, |
181 'total_items' => $total_sites, |
131 'per_page' => $per_page, |
182 'per_page' => $per_page, |
132 ) ); |
183 ) ); |
133 } |
184 } |
134 |
185 |
|
186 /** |
|
187 */ |
135 public function no_items() { |
188 public function no_items() { |
136 _e( 'No sites found.' ); |
189 _e( 'No sites found.' ); |
137 } |
190 } |
138 |
191 |
|
192 /** |
|
193 * |
|
194 * @return array |
|
195 */ |
139 protected function get_bulk_actions() { |
196 protected function get_bulk_actions() { |
140 $actions = array(); |
197 $actions = array(); |
141 if ( current_user_can( 'delete_sites' ) ) |
198 if ( current_user_can( 'delete_sites' ) ) |
142 $actions['delete'] = __( 'Delete' ); |
199 $actions['delete'] = __( 'Delete' ); |
143 $actions['spam'] = _x( 'Mark as Spam', 'site' ); |
200 $actions['spam'] = _x( 'Mark as Spam', 'site' ); |
145 |
202 |
146 return $actions; |
203 return $actions; |
147 } |
204 } |
148 |
205 |
149 /** |
206 /** |
|
207 * @global string $mode List table view mode. |
|
208 * |
150 * @param string $which |
209 * @param string $which |
151 */ |
210 */ |
152 protected function pagination( $which ) { |
211 protected function pagination( $which ) { |
153 global $mode; |
212 global $mode; |
154 |
213 |
155 parent::pagination( $which ); |
214 parent::pagination( $which ); |
156 |
215 |
157 if ( 'top' == $which ) |
216 if ( 'top' === $which ) |
158 $this->view_switcher( $mode ); |
217 $this->view_switcher( $mode ); |
159 } |
218 } |
160 |
219 |
|
220 /** |
|
221 * @return array |
|
222 */ |
161 public function get_columns() { |
223 public function get_columns() { |
162 $blogname_columns = ( is_subdomain_install() ) ? __( 'Domain' ) : __( 'Path' ); |
|
163 $sites_columns = array( |
224 $sites_columns = array( |
164 'cb' => '<input type="checkbox" />', |
225 'cb' => '<input type="checkbox" />', |
165 'blogname' => $blogname_columns, |
226 'blogname' => __( 'URL' ), |
166 'lastupdated' => __( 'Last Updated' ), |
227 'lastupdated' => __( 'Last Updated' ), |
167 'registered' => _x( 'Registered', 'site' ), |
228 'registered' => _x( 'Registered', 'site' ), |
168 'users' => __( 'Users' ) |
229 'users' => __( 'Users' ), |
169 ); |
230 ); |
170 |
231 |
171 if ( has_filter( 'wpmublogsaction' ) ) |
232 if ( has_filter( 'wpmublogsaction' ) ) { |
172 $sites_columns['plugins'] = __( 'Actions' ); |
233 $sites_columns['plugins'] = __( 'Actions' ); |
|
234 } |
173 |
235 |
174 /** |
236 /** |
175 * Filter the displayed site columns in Sites list table. |
237 * Filters the displayed site columns in Sites list table. |
176 * |
238 * |
177 * @since MU |
239 * @since MU (3.0.0) |
178 * |
240 * |
179 * @param array $sites_columns An array of displayed site columns. Default 'cb', |
241 * @param array $sites_columns An array of displayed site columns. Default 'cb', |
180 * 'blogname', 'lastupdated', 'registered', 'users'. |
242 * 'blogname', 'lastupdated', 'registered', 'users'. |
181 */ |
243 */ |
182 $sites_columns = apply_filters( 'wpmu_blogs_columns', $sites_columns ); |
244 return apply_filters( 'wpmu_blogs_columns', $sites_columns ); |
183 |
245 } |
184 return $sites_columns; |
246 |
185 } |
247 /** |
186 |
248 * @return array |
|
249 */ |
187 protected function get_sortable_columns() { |
250 protected function get_sortable_columns() { |
188 return array( |
251 return array( |
189 'blogname' => 'blogname', |
252 'blogname' => 'blogname', |
190 'lastupdated' => 'lastupdated', |
253 'lastupdated' => 'lastupdated', |
191 'registered' => 'blog_id', |
254 'registered' => 'blog_id', |
192 ); |
255 ); |
193 } |
256 } |
194 |
257 |
195 public function display_rows() { |
258 /** |
|
259 * Handles the checkbox column output. |
|
260 * |
|
261 * @since 4.3.0 |
|
262 * |
|
263 * @param array $blog Current site. |
|
264 */ |
|
265 public function column_cb( $blog ) { |
|
266 if ( ! is_main_site( $blog['blog_id'] ) ) : |
|
267 $blogname = untrailingslashit( $blog['domain'] . $blog['path'] ); |
|
268 ?> |
|
269 <label class="screen-reader-text" for="blog_<?php echo $blog['blog_id']; ?>"><?php |
|
270 printf( __( 'Select %s' ), $blogname ); |
|
271 ?></label> |
|
272 <input type="checkbox" id="blog_<?php echo $blog['blog_id'] ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ) ?>" /> |
|
273 <?php endif; |
|
274 } |
|
275 |
|
276 /** |
|
277 * Handles the ID column output. |
|
278 * |
|
279 * @since 4.4.0 |
|
280 * |
|
281 * @param array $blog Current site. |
|
282 */ |
|
283 public function column_id( $blog ) { |
|
284 echo $blog['blog_id']; |
|
285 } |
|
286 |
|
287 /** |
|
288 * Handles the site name column output. |
|
289 * |
|
290 * @since 4.3.0 |
|
291 * |
|
292 * @global string $mode List table view mode. |
|
293 * |
|
294 * @param array $blog Current site. |
|
295 */ |
|
296 public function column_blogname( $blog ) { |
196 global $mode; |
297 global $mode; |
197 |
298 |
198 $status_list = array( |
299 $blogname = untrailingslashit( $blog['domain'] . $blog['path'] ); |
199 'archived' => array( 'site-archived', __( 'Archived' ) ), |
300 $blog_states = array(); |
200 'spam' => array( 'site-spammed', _x( 'Spam', 'site' ) ), |
301 reset( $this->status_list ); |
201 'deleted' => array( 'site-deleted', __( 'Deleted' ) ), |
302 |
202 'mature' => array( 'site-mature', __( 'Mature' ) ) |
303 foreach ( $this->status_list as $status => $col ) { |
203 ); |
304 if ( $blog[ $status ] == 1 ) { |
204 |
305 $blog_states[] = $col[1]; |
205 if ( 'list' == $mode ) { |
306 } |
|
307 } |
|
308 $blog_state = ''; |
|
309 if ( ! empty( $blog_states ) ) { |
|
310 $state_count = count( $blog_states ); |
|
311 $i = 0; |
|
312 $blog_state .= ' — '; |
|
313 foreach ( $blog_states as $state ) { |
|
314 ++$i; |
|
315 $sep = ( $i == $state_count ) ? '' : ', '; |
|
316 $blog_state .= "<span class='post-state'>$state$sep</span>"; |
|
317 } |
|
318 } |
|
319 |
|
320 ?> |
|
321 <strong> |
|
322 <a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname; ?></a> |
|
323 <?php echo $blog_state; ?> |
|
324 </strong> |
|
325 <?php |
|
326 if ( 'list' !== $mode ) { |
|
327 switch_to_blog( $blog['blog_id'] ); |
|
328 echo '<p>'; |
|
329 printf( |
|
330 /* translators: 1: site name, 2: site tagline. */ |
|
331 __( '%1$s – %2$s' ), |
|
332 get_option( 'blogname' ), |
|
333 '<em>' . get_option( 'blogdescription ' ) . '</em>' |
|
334 ); |
|
335 echo '</p>'; |
|
336 restore_current_blog(); |
|
337 } |
|
338 } |
|
339 |
|
340 /** |
|
341 * Handles the lastupdated column output. |
|
342 * |
|
343 * @since 4.3.0 |
|
344 * |
|
345 * @global string $mode List table view mode. |
|
346 * |
|
347 * @param array $blog Current site. |
|
348 */ |
|
349 public function column_lastupdated( $blog ) { |
|
350 global $mode; |
|
351 |
|
352 if ( 'list' === $mode ) { |
206 $date = __( 'Y/m/d' ); |
353 $date = __( 'Y/m/d' ); |
207 } else { |
354 } else { |
208 $date = __( 'Y/m/d g:i:s a' ); |
355 $date = __( 'Y/m/d g:i:s a' ); |
209 } |
356 } |
210 |
357 |
|
358 echo ( $blog['last_updated'] === '0000-00-00 00:00:00' ) ? __( 'Never' ) : mysql2date( $date, $blog['last_updated'] ); |
|
359 } |
|
360 |
|
361 /** |
|
362 * Handles the registered column output. |
|
363 * |
|
364 * @since 4.3.0 |
|
365 * |
|
366 * @global string $mode List table view mode. |
|
367 * |
|
368 * @param array $blog Current site. |
|
369 */ |
|
370 public function column_registered( $blog ) { |
|
371 global $mode; |
|
372 |
|
373 if ( 'list' === $mode ) { |
|
374 $date = __( 'Y/m/d' ); |
|
375 } else { |
|
376 $date = __( 'Y/m/d g:i:s a' ); |
|
377 } |
|
378 |
|
379 if ( $blog['registered'] === '0000-00-00 00:00:00' ) { |
|
380 echo '—'; |
|
381 } else { |
|
382 echo mysql2date( $date, $blog['registered'] ); |
|
383 } |
|
384 } |
|
385 |
|
386 /** |
|
387 * Handles the users column output. |
|
388 * |
|
389 * @since 4.3.0 |
|
390 * |
|
391 * @param array $blog Current site. |
|
392 */ |
|
393 public function column_users( $blog ) { |
|
394 $user_count = wp_cache_get( $blog['blog_id'] . '_user_count', 'blog-details' ); |
|
395 if ( ! $user_count ) { |
|
396 $blog_users = get_users( array( 'blog_id' => $blog['blog_id'], 'fields' => 'ID' ) ); |
|
397 $user_count = count( $blog_users ); |
|
398 unset( $blog_users ); |
|
399 wp_cache_set( $blog['blog_id'] . '_user_count', $user_count, 'blog-details', 12 * HOUR_IN_SECONDS ); |
|
400 } |
|
401 |
|
402 printf( |
|
403 '<a href="%s">%s</a>', |
|
404 esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ), |
|
405 number_format_i18n( $user_count ) |
|
406 ); |
|
407 } |
|
408 |
|
409 /** |
|
410 * Handles the plugins column output. |
|
411 * |
|
412 * @since 4.3.0 |
|
413 * |
|
414 * @param array $blog Current site. |
|
415 */ |
|
416 public function column_plugins( $blog ) { |
|
417 if ( has_filter( 'wpmublogsaction' ) ) { |
|
418 /** |
|
419 * Fires inside the auxiliary 'Actions' column of the Sites list table. |
|
420 * |
|
421 * By default this column is hidden unless something is hooked to the action. |
|
422 * |
|
423 * @since MU (3.0.0) |
|
424 * |
|
425 * @param int $blog_id The site ID. |
|
426 */ |
|
427 do_action( 'wpmublogsaction', $blog['blog_id'] ); |
|
428 } |
|
429 } |
|
430 |
|
431 /** |
|
432 * Handles output for the default column. |
|
433 * |
|
434 * @since 4.3.0 |
|
435 * |
|
436 * @param array $blog Current site. |
|
437 * @param string $column_name Current column name. |
|
438 */ |
|
439 public function column_default( $blog, $column_name ) { |
|
440 /** |
|
441 * Fires for each registered custom column in the Sites list table. |
|
442 * |
|
443 * @since 3.1.0 |
|
444 * |
|
445 * @param string $column_name The name of the column to display. |
|
446 * @param int $blog_id The site ID. |
|
447 */ |
|
448 do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] ); |
|
449 } |
|
450 |
|
451 /** |
|
452 * |
|
453 * @global string $mode |
|
454 */ |
|
455 public function display_rows() { |
211 foreach ( $this->items as $blog ) { |
456 foreach ( $this->items as $blog ) { |
|
457 $blog = $blog->to_array(); |
212 $class = ''; |
458 $class = ''; |
213 reset( $status_list ); |
459 reset( $this->status_list ); |
214 |
460 |
215 $blog_states = array(); |
461 foreach ( $this->status_list as $status => $col ) { |
216 foreach ( $status_list as $status => $col ) { |
462 if ( $blog[ $status ] == 1 ) { |
217 if ( get_blog_status( $blog['blog_id'], $status ) == 1 ) { |
|
218 $class = " class='{$col[0]}'"; |
463 $class = " class='{$col[0]}'"; |
219 $blog_states[] = $col[1]; |
|
220 } |
464 } |
221 } |
465 } |
222 $blog_state = ''; |
466 |
223 if ( ! empty( $blog_states ) ) { |
|
224 $state_count = count( $blog_states ); |
|
225 $i = 0; |
|
226 $blog_state .= ' - '; |
|
227 foreach ( $blog_states as $state ) { |
|
228 ++$i; |
|
229 ( $i == $state_count ) ? $sep = '' : $sep = ', '; |
|
230 $blog_state .= "<span class='post-state'>$state$sep</span>"; |
|
231 } |
|
232 } |
|
233 echo "<tr{$class}>"; |
467 echo "<tr{$class}>"; |
234 |
468 |
235 $blogname = ( is_subdomain_install() ) ? str_replace( '.' . get_current_site()->domain, '', $blog['domain'] ) : $blog['path']; |
469 $this->single_row_columns( $blog ); |
236 |
470 |
237 list( $columns, $hidden ) = $this->get_column_info(); |
471 echo '</tr>'; |
238 |
472 } |
239 foreach ( $columns as $column_name => $column_display_name ) { |
473 } |
240 $style = ''; |
474 |
241 if ( in_array( $column_name, $hidden ) ) |
475 /** |
242 $style = ' style="display:none;"'; |
476 * Gets the name of the default primary column. |
243 |
477 * |
244 switch ( $column_name ) { |
478 * @since 4.3.0 |
245 case 'cb': ?> |
479 * |
246 <th scope="row" class="check-column"> |
480 * @return string Name of the default primary column, in this case, 'blogname'. |
247 <?php if ( ! is_main_site( $blog['blog_id'] ) ) : ?> |
481 */ |
248 <label class="screen-reader-text" for="blog_<?php echo $blog['blog_id']; ?>"><?php printf( __( 'Select %s' ), $blogname ); ?></label> |
482 protected function get_default_primary_column_name() { |
249 <input type="checkbox" id="blog_<?php echo $blog['blog_id'] ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ) ?>" /> |
483 return 'blogname'; |
250 <?php endif; ?> |
484 } |
251 </th> |
485 |
252 <?php |
486 /** |
253 break; |
487 * Generates and displays row action links. |
254 |
488 * |
255 case 'id':?> |
489 * @since 4.3.0 |
256 <th scope="row"> |
490 * |
257 <?php echo $blog['blog_id'] ?> |
491 * @param object $blog Site being acted upon. |
258 </th> |
492 * @param string $column_name Current column name. |
259 <?php |
493 * @param string $primary Primary column name. |
260 break; |
494 * @return string Row actions output. |
261 |
495 */ |
262 case 'blogname': |
496 protected function handle_row_actions( $blog, $column_name, $primary ) { |
263 echo "<td class='column-$column_name $column_name'$style>"; ?> |
497 if ( $primary !== $column_name ) { |
264 <a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname . $blog_state; ?></a> |
498 return; |
265 <?php |
499 } |
266 if ( 'list' != $mode ) { |
500 |
267 switch_to_blog( $blog['blog_id'] ); |
501 $blogname = untrailingslashit( $blog['domain'] . $blog['path'] ); |
268 echo '<p>' . sprintf( _x( '%1$s – <em>%2$s</em>', '%1$s: site name. %2$s: site tagline.' ), get_option( 'blogname' ), get_option( 'blogdescription ' ) ) . '</p>'; |
502 |
269 restore_current_blog(); |
503 // Preordered. |
270 } |
504 $actions = array( |
271 |
505 'edit' => '', 'backend' => '', |
272 // Preordered. |
506 'activate' => '', 'deactivate' => '', |
273 $actions = array( |
507 'archive' => '', 'unarchive' => '', |
274 'edit' => '', 'backend' => '', |
508 'spam' => '', 'unspam' => '', |
275 'activate' => '', 'deactivate' => '', |
509 'delete' => '', |
276 'archive' => '', 'unarchive' => '', |
510 'visit' => '', |
277 'spam' => '', 'unspam' => '', |
511 ); |
278 'delete' => '', |
512 |
279 'visit' => '', |
513 $actions['edit'] = '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a>'; |
280 ); |
514 $actions['backend'] = "<a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a>'; |
281 |
515 if ( get_network()->site_id != $blog['blog_id'] ) { |
282 $actions['edit'] = '<span class="edit"><a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a></span>'; |
516 if ( $blog['deleted'] == '1' ) { |
283 $actions['backend'] = "<span class='backend'><a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a></span>'; |
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>'; |
284 if ( get_current_site()->blog_id != $blog['blog_id'] ) { |
518 } else { |
285 if ( get_blog_status( $blog['blog_id'], 'deleted' ) == '1' ) |
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>'; |
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>'; |
520 } |
287 else |
521 |
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>'; |
522 if ( $blog['archived'] == '1' ) { |
289 |
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>'; |
290 if ( get_blog_status( $blog['blog_id'], 'archived' ) == '1' ) |
524 } else { |
291 $actions['unarchive'] = '<span class="archive"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=unarchiveblog&id=' . $blog['blog_id'] . '&msg=' . urlencode( sprintf( __( 'You are about to unarchive the site %s.' ), $blogname ) ) ), 'confirm') ) . '">' . __( 'Unarchive' ) . '</a></span>'; |
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>'; |
292 else |
526 } |
293 $actions['archive'] = '<span class="archive"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=archiveblog&id=' . $blog['blog_id'] . '&msg=' . urlencode( sprintf( __( 'You are about to archive the site %s.' ), $blogname ) ) ), 'confirm') ) . '">' . _x( 'Archive', 'verb; site' ) . '</a></span>'; |
527 |
294 |
528 if ( $blog['spam'] == '1' ) { |
295 if ( get_blog_status( $blog['blog_id'], '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>'; |
296 $actions['unspam'] = '<span class="spam"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=unspamblog&id=' . $blog['blog_id'] . '&msg=' . urlencode( sprintf( __( 'You are about to unspam the site %s.' ), $blogname ) ) ), 'confirm') ) . '">' . _x( 'Not Spam', 'site' ) . '</a></span>'; |
530 } else { |
297 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>'; |
298 $actions['spam'] = '<span class="spam"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=spamblog&id=' . $blog['blog_id'] . '&msg=' . urlencode( sprintf( __( 'You are about to mark the site %s as spam.' ), $blogname ) ) ), 'confirm') ) . '">' . _x( 'Spam', 'site' ) . '</a></span>'; |
532 } |
299 |
533 |
300 if ( current_user_can( 'delete_site', $blog['blog_id'] ) ) |
534 if ( current_user_can( 'delete_site', $blog['blog_id'] ) ) { |
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>'; |
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>'; |
302 } |
536 } |
303 |
537 } |
304 $actions['visit'] = "<span class='view'><a href='" . esc_url( get_home_url( $blog['blog_id'], '/' ) ) . "' rel='permalink'>" . __( 'Visit' ) . '</a></span>'; |
538 |
305 |
539 $actions['visit'] = "<a href='" . esc_url( get_home_url( $blog['blog_id'], '/' ) ) . "' rel='bookmark'>" . __( 'Visit' ) . '</a>'; |
306 /** |
540 |
307 * Filter the action links displayed for each site in the Sites list table. |
541 /** |
308 * |
542 * Filters the action links displayed for each site in the Sites list table. |
309 * The 'Edit', 'Dashboard', 'Delete', and 'Visit' links are displayed by |
543 * |
310 * default for each site. The site's status determines whether to show the |
544 * The 'Edit', 'Dashboard', 'Delete', and 'Visit' links are displayed by |
311 * 'Activate' or 'Deactivate' link, 'Unarchive' or 'Archive' links, and |
545 * default for each site. The site's status determines whether to show the |
312 * 'Not Spam' or 'Spam' link for each site. |
546 * 'Activate' or 'Deactivate' link, 'Unarchive' or 'Archive' links, and |
313 * |
547 * 'Not Spam' or 'Spam' link for each site. |
314 * @since 3.1.0 |
548 * |
315 * |
549 * @since 3.1.0 |
316 * @param array $actions An array of action links to be displayed. |
550 * |
317 * @param int $blog_id The site ID. |
551 * @param array $actions An array of action links to be displayed. |
318 * @param string $blogname Site path, formatted depending on whether it is a sub-domain |
552 * @param int $blog_id The site ID. |
319 * or subdirectory multisite install. |
553 * @param string $blogname Site path, formatted depending on whether it is a sub-domain |
320 */ |
554 * or subdirectory multisite installation. |
321 $actions = apply_filters( 'manage_sites_action_links', array_filter( $actions ), $blog['blog_id'], $blogname ); |
555 */ |
322 echo $this->row_actions( $actions ); |
556 $actions = apply_filters( 'manage_sites_action_links', array_filter( $actions ), $blog['blog_id'], $blogname ); |
323 ?> |
557 return $this->row_actions( $actions ); |
324 </td> |
|
325 <?php |
|
326 break; |
|
327 |
|
328 case 'lastupdated': |
|
329 echo "<td class='$column_name column-$column_name'$style>"; |
|
330 echo ( $blog['last_updated'] == '0000-00-00 00:00:00' ) ? __( 'Never' ) : mysql2date( $date, $blog['last_updated'] ); ?> |
|
331 </td> |
|
332 <?php |
|
333 break; |
|
334 case 'registered': |
|
335 echo "<td class='$column_name column-$column_name'$style>"; |
|
336 if ( $blog['registered'] == '0000-00-00 00:00:00' ) |
|
337 echo '—'; |
|
338 else |
|
339 echo mysql2date( $date, $blog['registered'] ); |
|
340 ?> |
|
341 </td> |
|
342 <?php |
|
343 break; |
|
344 case 'users': |
|
345 echo "<td class='$column_name column-$column_name'$style>"; |
|
346 $blogusers = get_users( array( 'blog_id' => $blog['blog_id'], 'number' => 6) ); |
|
347 if ( is_array( $blogusers ) ) { |
|
348 $blogusers_warning = ''; |
|
349 if ( count( $blogusers ) > 5 ) { |
|
350 $blogusers = array_slice( $blogusers, 0, 5 ); |
|
351 $blogusers_warning = __( 'Only showing first 5 users.' ) . ' <a href="' . esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'More' ) . '</a>'; |
|
352 } |
|
353 foreach ( $blogusers as $user_object ) { |
|
354 echo '<a href="' . esc_url( network_admin_url( 'user-edit.php?user_id=' . $user_object->ID ) ) . '">' . esc_html( $user_object->user_login ) . '</a> '; |
|
355 if ( 'list' != $mode ) |
|
356 echo '( ' . $user_object->user_email . ' )'; |
|
357 echo '<br />'; |
|
358 } |
|
359 if ( $blogusers_warning != '' ) |
|
360 echo '<strong>' . $blogusers_warning . '</strong><br />'; |
|
361 } |
|
362 ?> |
|
363 </td> |
|
364 <?php |
|
365 break; |
|
366 |
|
367 case 'plugins': ?> |
|
368 <?php if ( has_filter( 'wpmublogsaction' ) ) { |
|
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 */ |
|
379 do_action( 'wpmublogsaction', $blog['blog_id'] ); ?> |
|
380 </td> |
|
381 <?php } |
|
382 break; |
|
383 |
|
384 default: |
|
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 */ |
|
394 do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] ); |
|
395 echo "</td>"; |
|
396 break; |
|
397 } |
|
398 } |
|
399 ?> |
|
400 </tr> |
|
401 <?php |
|
402 } |
|
403 } |
558 } |
404 } |
559 } |