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, $current_site;
26 $mode = ( empty( $_REQUEST['mode'] ) ) ? 'list' : $_REQUEST['mode'];
28 $per_page = $this->get_items_per_page( 'sites_network_per_page' );
30 $pagenum = $this->get_pagenum();
32 $s = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST[ 's' ] ) ) : '';
34 if ( false !== strpos($s, '*') ) {
39 $like_s = esc_sql( like_escape( $s ) );
41 // If the network is large and a search is not being performed, show only the latest blogs with no paging in order
42 // to avoid expensive count queries.
43 if ( !$s && wp_is_large_network() ) {
44 if ( !isset($_REQUEST['orderby']) )
45 $_GET['orderby'] = $_REQUEST['orderby'] = '';
46 if ( !isset($_REQUEST['order']) )
47 $_GET['order'] = $_REQUEST['order'] = 'DESC';
50 $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";
54 } 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 ) ||
56 preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
57 preg_match( '/^[0-9]{1,3}\.$/', $s ) ) {
59 $reg_blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE ( '{$like_s}$wild' )" );
62 $reg_blog_ids = array( 0 );
66 WHERE site_id = '{$wpdb->siteid}'
67 AND {$wpdb->blogs}.blog_id IN (" . implode( ', ', $reg_blog_ids ) . ")";
69 if ( is_numeric($s) && empty( $wild ) ) {
70 $query .= " AND ( {$wpdb->blogs}.blog_id = '{$like_s}' )";
71 } elseif ( is_subdomain_install() ) {
72 $blog_s = str_replace( '.' . $current_site->domain, '', $like_s );
73 $blog_s .= $wild . '.' . $current_site->domain;
74 $query .= " AND ( {$wpdb->blogs}.domain LIKE '$blog_s' ) ";
76 if ( $like_s != trim('/', $current_site->path) )
77 $blog_s = $current_site->path . $like_s . $wild . '/';
80 $query .= " AND ( {$wpdb->blogs}.path LIKE '$blog_s' )";
84 $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : '';
85 if ( $order_by == 'registered' ) {
86 $query .= ' ORDER BY registered ';
87 } elseif ( $order_by == 'lastupdated' ) {
88 $query .= ' ORDER BY last_updated ';
89 } elseif ( $order_by == 'blogname' ) {
90 if ( is_subdomain_install() )
91 $query .= ' ORDER BY domain ';
93 $query .= ' ORDER BY path ';
94 } elseif ( $order_by == 'blog_id' ) {
95 $query .= ' ORDER BY blog_id ';
100 if ( isset( $order_by ) ) {
101 $order = ( isset( $_REQUEST['order'] ) && 'DESC' == strtoupper( $_REQUEST['order'] ) ) ? "DESC" : "ASC";
105 // Don't do an unbounded count on large networks
106 if ( ! wp_is_large_network() )
107 $total = $wpdb->get_var( str_replace( 'SELECT *', 'SELECT COUNT( blog_id )', $query ) );
109 $query .= " LIMIT " . intval( ( $pagenum - 1 ) * $per_page ) . ", " . intval( $per_page );
110 $this->items = $wpdb->get_results( $query, ARRAY_A );
112 if ( wp_is_large_network() )
113 $total = count($this->items);
115 $this->set_pagination_args( array(
116 'total_items' => $total,
117 'per_page' => $per_page,
121 function no_items() {
122 _e( 'No sites found.' );
125 function get_bulk_actions() {
127 if ( current_user_can( 'delete_sites' ) )
128 $actions['delete'] = __( 'Delete' );
129 $actions['spam'] = _x( 'Mark as Spam', 'site' );
130 $actions['notspam'] = _x( 'Not Spam', 'site' );
135 function pagination( $which ) {
138 parent::pagination( $which );
140 if ( 'top' == $which )
141 $this->view_switcher( $mode );
144 function get_columns() {
145 $blogname_columns = ( is_subdomain_install() ) ? __( 'Domain' ) : __( 'Path' );
146 $sites_columns = array(
147 'cb' => '<input type="checkbox" />',
148 'blogname' => $blogname_columns,
149 'lastupdated' => __( 'Last Updated' ),
150 'registered' => _x( 'Registered', 'site' ),
151 'users' => __( 'Users' )
154 if ( has_filter( 'wpmublogsaction' ) )
155 $sites_columns['plugins'] = __( 'Actions' );
157 $sites_columns = apply_filters( 'wpmu_blogs_columns', $sites_columns );
159 return $sites_columns;
162 function get_sortable_columns() {
164 'blogname' => 'blogname',
165 'lastupdated' => 'lastupdated',
166 'registered' => 'blog_id',
170 function display_rows() {
171 global $current_site, $mode;
173 $status_list = array(
174 'archived' => array( 'site-archived', __( 'Archived' ) ),
175 'spam' => array( 'site-spammed', _x( 'Spam', 'site' ) ),
176 'deleted' => array( 'site-deleted', __( 'Deleted' ) ),
177 'mature' => array( 'site-mature', __( 'Mature' ) )
181 foreach ( $this->items as $blog ) {
182 $class = ( 'alternate' == $class ) ? '' : 'alternate';
183 reset( $status_list );
185 $blog_states = array();
186 foreach ( $status_list as $status => $col ) {
187 if ( get_blog_status( $blog['blog_id'], $status ) == 1 ) {
189 $blog_states[] = $col[1];
193 if ( ! empty( $blog_states ) ) {
194 $state_count = count( $blog_states );
196 $blog_state .= ' - ';
197 foreach ( $blog_states as $state ) {
199 ( $i == $state_count ) ? $sep = '' : $sep = ', ';
200 $blog_state .= "<span class='post-state'>$state$sep</span>";
203 echo "<tr class='$class'>";
205 $blogname = ( is_subdomain_install() ) ? str_replace( '.'.$current_site->domain, '', $blog['domain'] ) : $blog['path'];
207 list( $columns, $hidden ) = $this->get_column_info();
209 foreach ( $columns as $column_name => $column_display_name ) {
211 if ( in_array( $column_name, $hidden ) )
212 $style = ' style="display:none;"';
214 switch ( $column_name ) {
216 <th scope="row" class="check-column">
217 <label class="screen-reader-text" for="blog_<?php echo $blog['blog_id']; ?>"><?php printf( __( 'Select %s' ), $blogname ); ?></label>
218 <input type="checkbox" id="blog_<?php echo $blog['blog_id'] ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ) ?>" />
224 <th valign="top" scope="row">
225 <?php echo $blog['blog_id'] ?>
231 echo "<td class='column-$column_name $column_name'$style>"; ?>
232 <a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname . $blog_state; ?></a>
234 if ( 'list' != $mode ) {
235 switch_to_blog( $blog['blog_id'] );
236 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>';
237 restore_current_blog();
242 'edit' => '', 'backend' => '',
243 'activate' => '', 'deactivate' => '',
244 'archive' => '', 'unarchive' => '',
245 'spam' => '', 'unspam' => '',
250 $actions['edit'] = '<span class="edit"><a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a></span>';
251 $actions['backend'] = "<span class='backend'><a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a></span>';
252 if ( $current_site->blog_id != $blog['blog_id'] ) {
253 if ( get_blog_status( $blog['blog_id'], 'deleted' ) == '1' )
254 $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>';
256 $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>';
258 if ( get_blog_status( $blog['blog_id'], 'archived' ) == '1' )
259 $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>';
261 $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>';
263 if ( get_blog_status( $blog['blog_id'], 'spam' ) == '1' )
264 $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>';
266 $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>';
268 if ( current_user_can( 'delete_site', $blog['blog_id'] ) )
269 $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 $actions['visit'] = "<span class='view'><a href='" . esc_url( get_home_url( $blog['blog_id'], '/' ) ) . "' rel='permalink'>" . __( 'Visit' ) . '</a></span>';
274 $actions = apply_filters( 'manage_sites_action_links', array_filter( $actions ), $blog['blog_id'], $blogname );
275 echo $this->row_actions( $actions );
282 echo "<td valign='top' class='$column_name column-$column_name'$style>";
283 if ( 'list' == $mode )
286 $date = 'Y/m/d \<\b\r \/\> g:i:s a';
287 echo ( $blog['last_updated'] == '0000-00-00 00:00:00' ) ? __( 'Never' ) : mysql2date( $date, $blog['last_updated'] ); ?>
292 echo "<td valign='top' class='$column_name column-$column_name'$style>";
293 if ( $blog['registered'] == '0000-00-00 00:00:00' )
296 echo mysql2date( $date, $blog['registered'] );
302 echo "<td valign='top' class='$column_name column-$column_name'$style>";
303 $blogusers = get_users( array( 'blog_id' => $blog['blog_id'], 'number' => 6) );
304 if ( is_array( $blogusers ) ) {
305 $blogusers_warning = '';
306 if ( count( $blogusers ) > 5 ) {
307 $blogusers = array_slice( $blogusers, 0, 5 );
308 $blogusers_warning = __( 'Only showing first 5 users.' ) . ' <a href="' . esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'More' ) . '</a>';
310 foreach ( $blogusers as $user_object ) {
311 echo '<a href="' . esc_url( network_admin_url( 'user-edit.php?user_id=' . $user_object->ID ) ) . '">' . esc_html( $user_object->user_login ) . '</a> ';
312 if ( 'list' != $mode )
313 echo '( ' . $user_object->user_email . ' )';
316 if ( $blogusers_warning != '' )
317 echo '<strong>' . $blogusers_warning . '</strong><br />';
325 <?php if ( has_filter( 'wpmublogsaction' ) ) {
326 echo "<td valign='top' class='$column_name column-$column_name'$style>";
327 do_action( 'wpmublogsaction', $blog['blog_id'] ); ?>
333 echo "<td class='$column_name column-$column_name'$style>";
334 do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] );