3 * Sites List Table class.
6 * @subpackage List_Table
10 class WP_MS_Sites_List_Table extends WP_List_Table {
18 * @see WP_List_Table::__construct() for more information on default arguments.
20 * @param array $args An associative array of arguments.
22 public function __construct( $args = array() ) {
23 parent::__construct( array(
25 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
29 public function ajax_user_can() {
30 return current_user_can( 'manage_sites' );
33 public function prepare_items() {
34 global $s, $mode, $wpdb;
36 $current_site = get_current_site();
38 $mode = ( empty( $_REQUEST['mode'] ) ) ? 'list' : $_REQUEST['mode'];
40 $per_page = $this->get_items_per_page( 'sites_network_per_page' );
42 $pagenum = $this->get_pagenum();
44 $s = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST[ 's' ] ) ) : '';
46 if ( false !== strpos($s, '*') ) {
52 * 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.
55 if ( !$s && wp_is_large_network() ) {
56 if ( !isset($_REQUEST['orderby']) )
57 $_GET['orderby'] = $_REQUEST['orderby'] = '';
58 if ( !isset($_REQUEST['order']) )
59 $_GET['order'] = $_REQUEST['order'] = 'DESC';
62 $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";
66 } 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 ) ||
68 preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
69 preg_match( '/^[0-9]{1,3}\.$/', $s ) ) {
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 );
75 $reg_blog_ids = array( 0 );
79 WHERE site_id = '{$wpdb->siteid}'
80 AND {$wpdb->blogs}.blog_id IN (" . implode( ', ', $reg_blog_ids ) . ")";
82 if ( is_numeric($s) && empty( $wild ) ) {
83 $query .= $wpdb->prepare( " AND ( {$wpdb->blogs}.blog_id = %s )", $s );
84 } elseif ( is_subdomain_install() ) {
85 $blog_s = str_replace( '.' . $current_site->domain, '', $s );
86 $blog_s = $wpdb->esc_like( $blog_s ) . $wild . $wpdb->esc_like( '.' . $current_site->domain );
87 $query .= $wpdb->prepare( " AND ( {$wpdb->blogs}.domain LIKE %s ) ", $blog_s );
89 if ( $s != trim('/', $current_site->path) ) {
90 $blog_s = $wpdb->esc_like( $current_site->path . $s ) . $wild . $wpdb->esc_like( '/' );
92 $blog_s = $wpdb->esc_like( $s );
94 $query .= $wpdb->prepare( " AND ( {$wpdb->blogs}.path LIKE %s )", $blog_s );
98 $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : '';
99 if ( $order_by == 'registered' ) {
100 $query .= ' ORDER BY registered ';
101 } elseif ( $order_by == 'lastupdated' ) {
102 $query .= ' ORDER BY last_updated ';
103 } elseif ( $order_by == 'blogname' ) {
104 if ( is_subdomain_install() )
105 $query .= ' ORDER BY domain ';
107 $query .= ' ORDER BY path ';
108 } elseif ( $order_by == 'blog_id' ) {
109 $query .= ' ORDER BY blog_id ';
114 if ( isset( $order_by ) ) {
115 $order = ( isset( $_REQUEST['order'] ) && 'DESC' == strtoupper( $_REQUEST['order'] ) ) ? "DESC" : "ASC";
119 // Don't do an unbounded count on large networks
120 if ( ! wp_is_large_network() )
121 $total = $wpdb->get_var( str_replace( 'SELECT *', 'SELECT COUNT( blog_id )', $query ) );
123 $query .= " LIMIT " . intval( ( $pagenum - 1 ) * $per_page ) . ", " . intval( $per_page );
124 $this->items = $wpdb->get_results( $query, ARRAY_A );
126 if ( wp_is_large_network() )
127 $total = count($this->items);
129 $this->set_pagination_args( array(
130 'total_items' => $total,
131 'per_page' => $per_page,
135 public function no_items() {
136 _e( 'No sites found.' );
139 protected function get_bulk_actions() {
141 if ( current_user_can( 'delete_sites' ) )
142 $actions['delete'] = __( 'Delete' );
143 $actions['spam'] = _x( 'Mark as Spam', 'site' );
144 $actions['notspam'] = _x( 'Not Spam', 'site' );
149 protected function pagination( $which ) {
152 parent::pagination( $which );
154 if ( 'top' == $which )
155 $this->view_switcher( $mode );
158 public function get_columns() {
159 $blogname_columns = ( is_subdomain_install() ) ? __( 'Domain' ) : __( 'Path' );
160 $sites_columns = array(
161 'cb' => '<input type="checkbox" />',
162 'blogname' => $blogname_columns,
163 'lastupdated' => __( 'Last Updated' ),
164 'registered' => _x( 'Registered', 'site' ),
165 'users' => __( 'Users' )
168 if ( has_filter( 'wpmublogsaction' ) )
169 $sites_columns['plugins'] = __( 'Actions' );
172 * Filter the displayed site columns in Sites list table.
176 * @param array $sites_columns An array of displayed site columns. Default 'cb',
177 * 'blogname', 'lastupdated', 'registered', 'users'.
179 $sites_columns = apply_filters( 'wpmu_blogs_columns', $sites_columns );
181 return $sites_columns;
184 protected function get_sortable_columns() {
186 'blogname' => 'blogname',
187 'lastupdated' => 'lastupdated',
188 'registered' => 'blog_id',
192 public function display_rows() {
195 $status_list = array(
196 'archived' => array( 'site-archived', __( 'Archived' ) ),
197 'spam' => array( 'site-spammed', _x( 'Spam', 'site' ) ),
198 'deleted' => array( 'site-deleted', __( 'Deleted' ) ),
199 'mature' => array( 'site-mature', __( 'Mature' ) )
202 if ( 'list' == $mode ) {
205 $date = 'Y/m/d \<\b\r \/\> g:i:s a';
209 foreach ( $this->items as $blog ) {
210 $class = ( 'alternate' == $class ) ? '' : 'alternate';
211 reset( $status_list );
213 $blog_states = array();
214 foreach ( $status_list as $status => $col ) {
215 if ( get_blog_status( $blog['blog_id'], $status ) == 1 ) {
217 $blog_states[] = $col[1];
221 if ( ! empty( $blog_states ) ) {
222 $state_count = count( $blog_states );
224 $blog_state .= ' - ';
225 foreach ( $blog_states as $state ) {
227 ( $i == $state_count ) ? $sep = '' : $sep = ', ';
228 $blog_state .= "<span class='post-state'>$state$sep</span>";
231 echo "<tr class='$class'>";
233 $blogname = ( is_subdomain_install() ) ? str_replace( '.' . get_current_site()->domain, '', $blog['domain'] ) : $blog['path'];
235 list( $columns, $hidden ) = $this->get_column_info();
237 foreach ( $columns as $column_name => $column_display_name ) {
239 if ( in_array( $column_name, $hidden ) )
240 $style = ' style="display:none;"';
242 switch ( $column_name ) {
244 <th scope="row" class="check-column">
245 <?php if ( ! is_main_site( $blog['blog_id'] ) ) : ?>
246 <label class="screen-reader-text" for="blog_<?php echo $blog['blog_id']; ?>"><?php printf( __( 'Select %s' ), $blogname ); ?></label>
247 <input type="checkbox" id="blog_<?php echo $blog['blog_id'] ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ) ?>" />
255 <?php echo $blog['blog_id'] ?>
261 echo "<td class='column-$column_name $column_name'$style>"; ?>
262 <a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname . $blog_state; ?></a>
264 if ( 'list' != $mode ) {
265 switch_to_blog( $blog['blog_id'] );
266 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>';
267 restore_current_blog();
272 'edit' => '', 'backend' => '',
273 'activate' => '', 'deactivate' => '',
274 'archive' => '', 'unarchive' => '',
275 'spam' => '', 'unspam' => '',
280 $actions['edit'] = '<span class="edit"><a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a></span>';
281 $actions['backend'] = "<span class='backend'><a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a></span>';
282 if ( get_current_site()->blog_id != $blog['blog_id'] ) {
283 if ( get_blog_status( $blog['blog_id'], 'deleted' ) == '1' )
284 $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['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 if ( get_blog_status( $blog['blog_id'], 'archived' ) == '1' )
289 $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>';
291 $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>';
293 if ( get_blog_status( $blog['blog_id'], 'spam' ) == '1' )
294 $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>';
296 $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>';
298 if ( current_user_can( 'delete_site', $blog['blog_id'] ) )
299 $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>';
302 $actions['visit'] = "<span class='view'><a href='" . esc_url( get_home_url( $blog['blog_id'], '/' ) ) . "' rel='permalink'>" . __( 'Visit' ) . '</a></span>';
305 * Filter the action links displayed for each site in the Sites list table.
307 * The 'Edit', 'Dashboard', 'Delete', and 'Visit' links are displayed by
308 * default for each site. The site's status determines whether to show the
309 * 'Activate' or 'Deactivate' link, 'Unarchive' or 'Archive' links, and
310 * 'Not Spam' or 'Spam' link for each site.
314 * @param array $actions An array of action links to be displayed.
315 * @param int $blog_id The site ID.
316 * @param string $blogname Site path, formatted depending on whether it is a sub-domain
317 * or subdirectory multisite install.
319 $actions = apply_filters( 'manage_sites_action_links', array_filter( $actions ), $blog['blog_id'], $blogname );
320 echo $this->row_actions( $actions );
327 echo "<td class='$column_name column-$column_name'$style>";
328 echo ( $blog['last_updated'] == '0000-00-00 00:00:00' ) ? __( 'Never' ) : mysql2date( $date, $blog['last_updated'] ); ?>
333 echo "<td class='$column_name column-$column_name'$style>";
334 if ( $blog['registered'] == '0000-00-00 00:00:00' )
337 echo mysql2date( $date, $blog['registered'] );
343 echo "<td class='$column_name column-$column_name'$style>";
344 $blogusers = get_users( array( 'blog_id' => $blog['blog_id'], 'number' => 6) );
345 if ( is_array( $blogusers ) ) {
346 $blogusers_warning = '';
347 if ( count( $blogusers ) > 5 ) {
348 $blogusers = array_slice( $blogusers, 0, 5 );
349 $blogusers_warning = __( 'Only showing first 5 users.' ) . ' <a href="' . esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'More' ) . '</a>';
351 foreach ( $blogusers as $user_object ) {
352 echo '<a href="' . esc_url( network_admin_url( 'user-edit.php?user_id=' . $user_object->ID ) ) . '">' . esc_html( $user_object->user_login ) . '</a> ';
353 if ( 'list' != $mode )
354 echo '( ' . $user_object->user_email . ' )';
357 if ( $blogusers_warning != '' )
358 echo '<strong>' . $blogusers_warning . '</strong><br />';
366 <?php if ( has_filter( 'wpmublogsaction' ) ) {
367 echo "<td class='$column_name column-$column_name'$style>";
369 * Fires inside the auxiliary 'Actions' column of the Sites list table.
371 * By default this column is hidden unless something is hooked to the action.
375 * @param int $blog_id The site ID.
377 do_action( 'wpmublogsaction', $blog['blog_id'] ); ?>
383 echo "<td class='$column_name column-$column_name'$style>";
385 * Fires for each registered custom column in the Sites list table.
389 * @param string $column_name The name of the column to display.
390 * @param int $blog_id The site ID.
392 do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] );