3 * Sites List Table class.
6 * @subpackage List_Table
10 class WP_MS_Sites_List_Table extends WP_List_Table {
12 function __construct( $args = array() ) {
13 parent::__construct( array(
15 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
19 function ajax_user_can() {
20 return current_user_can( 'manage_sites' );
23 function prepare_items() {
24 global $s, $mode, $wpdb;
26 $current_site = get_current_site();
28 $mode = ( empty( $_REQUEST['mode'] ) ) ? 'list' : $_REQUEST['mode'];
30 $per_page = $this->get_items_per_page( 'sites_network_per_page' );
32 $pagenum = $this->get_pagenum();
34 $s = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST[ 's' ] ) ) : '';
36 if ( false !== strpos($s, '*') ) {
41 $like_s = esc_sql( like_escape( $s ) );
43 // If the network is large and a search is not being performed, show only the latest blogs with no paging in order
44 // to avoid expensive count queries.
45 if ( !$s && wp_is_large_network() ) {
46 if ( !isset($_REQUEST['orderby']) )
47 $_GET['orderby'] = $_REQUEST['orderby'] = '';
48 if ( !isset($_REQUEST['order']) )
49 $_GET['order'] = $_REQUEST['order'] = 'DESC';
52 $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";
56 } elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s ) ||
57 preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
58 preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
59 preg_match( '/^[0-9]{1,3}\.$/', $s ) ) {
61 $reg_blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE ( '{$like_s}$wild' )" );
64 $reg_blog_ids = array( 0 );
68 WHERE site_id = '{$wpdb->siteid}'
69 AND {$wpdb->blogs}.blog_id IN (" . implode( ', ', $reg_blog_ids ) . ")";
71 if ( is_numeric($s) && empty( $wild ) ) {
72 $query .= " AND ( {$wpdb->blogs}.blog_id = '{$like_s}' )";
73 } elseif ( is_subdomain_install() ) {
74 $blog_s = str_replace( '.' . $current_site->domain, '', $like_s );
75 $blog_s .= $wild . '.' . $current_site->domain;
76 $query .= " AND ( {$wpdb->blogs}.domain LIKE '$blog_s' ) ";
78 if ( $like_s != trim('/', $current_site->path) )
79 $blog_s = $current_site->path . $like_s . $wild . '/';
82 $query .= " AND ( {$wpdb->blogs}.path LIKE '$blog_s' )";
86 $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : '';
87 if ( $order_by == 'registered' ) {
88 $query .= ' ORDER BY registered ';
89 } elseif ( $order_by == 'lastupdated' ) {
90 $query .= ' ORDER BY last_updated ';
91 } elseif ( $order_by == 'blogname' ) {
92 if ( is_subdomain_install() )
93 $query .= ' ORDER BY domain ';
95 $query .= ' ORDER BY path ';
96 } elseif ( $order_by == 'blog_id' ) {
97 $query .= ' ORDER BY blog_id ';
102 if ( isset( $order_by ) ) {
103 $order = ( isset( $_REQUEST['order'] ) && 'DESC' == strtoupper( $_REQUEST['order'] ) ) ? "DESC" : "ASC";
107 // Don't do an unbounded count on large networks
108 if ( ! wp_is_large_network() )
109 $total = $wpdb->get_var( str_replace( 'SELECT *', 'SELECT COUNT( blog_id )', $query ) );
111 $query .= " LIMIT " . intval( ( $pagenum - 1 ) * $per_page ) . ", " . intval( $per_page );
112 $this->items = $wpdb->get_results( $query, ARRAY_A );
114 if ( wp_is_large_network() )
115 $total = count($this->items);
117 $this->set_pagination_args( array(
118 'total_items' => $total,
119 'per_page' => $per_page,
123 function no_items() {
124 _e( 'No sites found.' );
127 function get_bulk_actions() {
129 if ( current_user_can( 'delete_sites' ) )
130 $actions['delete'] = __( 'Delete' );
131 $actions['spam'] = _x( 'Mark as Spam', 'site' );
132 $actions['notspam'] = _x( 'Not Spam', 'site' );
137 function pagination( $which ) {
140 parent::pagination( $which );
142 if ( 'top' == $which )
143 $this->view_switcher( $mode );
146 function get_columns() {
147 $blogname_columns = ( is_subdomain_install() ) ? __( 'Domain' ) : __( 'Path' );
148 $sites_columns = array(
149 'cb' => '<input type="checkbox" />',
150 'blogname' => $blogname_columns,
151 'lastupdated' => __( 'Last Updated' ),
152 'registered' => _x( 'Registered', 'site' ),
153 'users' => __( 'Users' )
156 if ( has_filter( 'wpmublogsaction' ) )
157 $sites_columns['plugins'] = __( 'Actions' );
160 * Filter the displayed site columns in Sites list table.
164 * @param array $sites_columns An array of displayed site columns. Default 'cb',
165 * 'blogname', 'lastupdated', 'registered', 'users'.
167 $sites_columns = apply_filters( 'wpmu_blogs_columns', $sites_columns );
169 return $sites_columns;
172 function get_sortable_columns() {
174 'blogname' => 'blogname',
175 'lastupdated' => 'lastupdated',
176 'registered' => 'blog_id',
180 function display_rows() {
183 $status_list = array(
184 'archived' => array( 'site-archived', __( 'Archived' ) ),
185 'spam' => array( 'site-spammed', _x( 'Spam', 'site' ) ),
186 'deleted' => array( 'site-deleted', __( 'Deleted' ) ),
187 'mature' => array( 'site-mature', __( 'Mature' ) )
191 foreach ( $this->items as $blog ) {
192 $class = ( 'alternate' == $class ) ? '' : 'alternate';
193 reset( $status_list );
195 $blog_states = array();
196 foreach ( $status_list as $status => $col ) {
197 if ( get_blog_status( $blog['blog_id'], $status ) == 1 ) {
199 $blog_states[] = $col[1];
203 if ( ! empty( $blog_states ) ) {
204 $state_count = count( $blog_states );
206 $blog_state .= ' - ';
207 foreach ( $blog_states as $state ) {
209 ( $i == $state_count ) ? $sep = '' : $sep = ', ';
210 $blog_state .= "<span class='post-state'>$state$sep</span>";
213 echo "<tr class='$class'>";
215 $blogname = ( is_subdomain_install() ) ? str_replace( '.' . get_current_site()->domain, '', $blog['domain'] ) : $blog['path'];
217 list( $columns, $hidden ) = $this->get_column_info();
219 foreach ( $columns as $column_name => $column_display_name ) {
221 if ( in_array( $column_name, $hidden ) )
222 $style = ' style="display:none;"';
224 switch ( $column_name ) {
226 <th scope="row" class="check-column">
227 <?php if ( ! is_main_site( $blog['blog_id'] ) ) : ?>
228 <label class="screen-reader-text" for="blog_<?php echo $blog['blog_id']; ?>"><?php printf( __( 'Select %s' ), $blogname ); ?></label>
229 <input type="checkbox" id="blog_<?php echo $blog['blog_id'] ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ) ?>" />
236 <th valign="top" scope="row">
237 <?php echo $blog['blog_id'] ?>
243 echo "<td class='column-$column_name $column_name'$style>"; ?>
244 <a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname . $blog_state; ?></a>
246 if ( 'list' != $mode ) {
247 switch_to_blog( $blog['blog_id'] );
248 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>';
249 restore_current_blog();
254 'edit' => '', 'backend' => '',
255 'activate' => '', 'deactivate' => '',
256 'archive' => '', 'unarchive' => '',
257 'spam' => '', 'unspam' => '',
262 $actions['edit'] = '<span class="edit"><a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a></span>';
263 $actions['backend'] = "<span class='backend'><a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a></span>';
264 if ( get_current_site()->blog_id != $blog['blog_id'] ) {
265 if ( get_blog_status( $blog['blog_id'], 'deleted' ) == '1' )
266 $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>';
268 $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>';
270 if ( get_blog_status( $blog['blog_id'], 'archived' ) == '1' )
271 $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>';
273 $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>';
275 if ( get_blog_status( $blog['blog_id'], 'spam' ) == '1' )
276 $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>';
278 $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>';
280 if ( current_user_can( 'delete_site', $blog['blog_id'] ) )
281 $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>';
284 $actions['visit'] = "<span class='view'><a href='" . esc_url( get_home_url( $blog['blog_id'], '/' ) ) . "' rel='permalink'>" . __( 'Visit' ) . '</a></span>';
287 * Filter the action links displayed for each site in the Sites list table.
289 * The 'Edit', 'Dashboard', 'Delete', and 'Visit' links are displayed by
290 * default for each site. The site's status determines whether to show the
291 * 'Activate' or 'Deactivate' link, 'Unarchive' or 'Archive' links, and
292 * 'Not Spam' or 'Spam' link for each site.
296 * @param array $actions An array of action links to be displayed.
297 * @param int $blog_id The site ID.
298 * @param string $blogname Site path, formatted depending on whether it is a sub-domain
299 * or subdirectory multisite install.
301 $actions = apply_filters( 'manage_sites_action_links', array_filter( $actions ), $blog['blog_id'], $blogname );
302 echo $this->row_actions( $actions );
309 echo "<td valign='top' class='$column_name column-$column_name'$style>";
310 if ( 'list' == $mode )
313 $date = 'Y/m/d \<\b\r \/\> g:i:s a';
314 echo ( $blog['last_updated'] == '0000-00-00 00:00:00' ) ? __( 'Never' ) : mysql2date( $date, $blog['last_updated'] ); ?>
319 echo "<td valign='top' class='$column_name column-$column_name'$style>";
320 if ( $blog['registered'] == '0000-00-00 00:00:00' )
323 echo mysql2date( $date, $blog['registered'] );
329 echo "<td valign='top' class='$column_name column-$column_name'$style>";
330 $blogusers = get_users( array( 'blog_id' => $blog['blog_id'], 'number' => 6) );
331 if ( is_array( $blogusers ) ) {
332 $blogusers_warning = '';
333 if ( count( $blogusers ) > 5 ) {
334 $blogusers = array_slice( $blogusers, 0, 5 );
335 $blogusers_warning = __( 'Only showing first 5 users.' ) . ' <a href="' . esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'More' ) . '</a>';
337 foreach ( $blogusers as $user_object ) {
338 echo '<a href="' . esc_url( network_admin_url( 'user-edit.php?user_id=' . $user_object->ID ) ) . '">' . esc_html( $user_object->user_login ) . '</a> ';
339 if ( 'list' != $mode )
340 echo '( ' . $user_object->user_email . ' )';
343 if ( $blogusers_warning != '' )
344 echo '<strong>' . $blogusers_warning . '</strong><br />';
352 <?php if ( has_filter( 'wpmublogsaction' ) ) {
353 echo "<td valign='top' class='$column_name column-$column_name'$style>";
355 * Fires inside the auxiliary 'Actions' column of the Sites list table.
357 * By default this column is hidden unless something is hooked to the action.
361 * @param int $blog_id The site ID.
363 do_action( 'wpmublogsaction', $blog['blog_id'] ); ?>
369 echo "<td class='$column_name column-$column_name'$style>";
371 * Fires for each registered custom column in the Sites list table.
375 * @param string $column_name The name of the column to display.
376 * @param int $blog_id The site ID.
378 do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] );