2010-10-25 04:57:43 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2010-10-25 06:04:18 +02:00
|
|
|
* Multisite Users List Table class.
|
2010-10-25 04:57:43 +02:00
|
|
|
*
|
|
|
|
* @package WordPress
|
2010-10-25 06:04:18 +02:00
|
|
|
* @subpackage List_Table
|
|
|
|
* @since 3.1.0
|
2011-01-16 22:47:24 +01:00
|
|
|
* @access private
|
2010-10-25 04:57:43 +02:00
|
|
|
*/
|
2010-11-04 09:07:03 +01:00
|
|
|
class WP_MS_Users_List_Table extends WP_List_Table {
|
2010-10-25 04:57:43 +02:00
|
|
|
|
2010-12-16 10:18:28 +01:00
|
|
|
function ajax_user_can() {
|
|
|
|
return current_user_can( 'manage_network_users' );
|
2010-10-25 04:57:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function prepare_items() {
|
2010-11-28 18:39:44 +01:00
|
|
|
global $usersearch, $role, $wpdb, $mode;
|
2010-10-25 04:57:43 +02:00
|
|
|
|
2014-02-02 23:10:12 +01:00
|
|
|
$usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
|
2010-10-25 04:57:43 +02:00
|
|
|
|
|
|
|
$users_per_page = $this->get_items_per_page( 'users_network_per_page' );
|
|
|
|
|
2010-11-10 18:05:20 +01:00
|
|
|
$role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
|
|
|
|
|
2010-10-25 04:57:43 +02:00
|
|
|
$paged = $this->get_pagenum();
|
|
|
|
|
|
|
|
$args = array(
|
|
|
|
'number' => $users_per_page,
|
|
|
|
'offset' => ( $paged-1 ) * $users_per_page,
|
|
|
|
'search' => $usersearch,
|
2010-12-17 01:38:15 +01:00
|
|
|
'blog_id' => 0,
|
|
|
|
'fields' => 'all_with_meta'
|
2010-10-25 04:57:43 +02:00
|
|
|
);
|
|
|
|
|
2011-10-03 18:30:07 +02:00
|
|
|
if ( wp_is_large_network( 'users' ) )
|
|
|
|
$args['search'] = ltrim( $args['search'], '*' );
|
2010-12-31 00:38:21 +01:00
|
|
|
|
2010-11-10 18:05:20 +01:00
|
|
|
if ( $role == 'super' ) {
|
|
|
|
$logins = implode( "', '", get_super_admins() );
|
|
|
|
$args['include'] = $wpdb->get_col( "SELECT ID FROM $wpdb->users WHERE user_login IN ('$logins')" );
|
|
|
|
}
|
|
|
|
|
2010-11-03 14:34:04 +01:00
|
|
|
// If the network is large and a search is not being performed, show only the latest users with no paging in order
|
|
|
|
// to avoid expensive count queries.
|
2011-10-03 18:30:07 +02:00
|
|
|
if ( !$usersearch && wp_is_large_network( 'users' ) ) {
|
2010-11-03 14:34:04 +01:00
|
|
|
if ( !isset($_REQUEST['orderby']) )
|
|
|
|
$_GET['orderby'] = $_REQUEST['orderby'] = 'id';
|
|
|
|
if ( !isset($_REQUEST['order']) )
|
|
|
|
$_GET['order'] = $_REQUEST['order'] = 'DESC';
|
|
|
|
$args['count_total'] = false;
|
|
|
|
}
|
|
|
|
|
2010-10-25 04:57:43 +02:00
|
|
|
if ( isset( $_REQUEST['orderby'] ) )
|
|
|
|
$args['orderby'] = $_REQUEST['orderby'];
|
|
|
|
|
|
|
|
if ( isset( $_REQUEST['order'] ) )
|
|
|
|
$args['order'] = $_REQUEST['order'];
|
|
|
|
|
2010-11-28 18:39:44 +01:00
|
|
|
$mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
|
|
|
|
|
2010-10-25 04:57:43 +02:00
|
|
|
// Query the user IDs for this page
|
|
|
|
$wp_user_search = new WP_User_Query( $args );
|
|
|
|
|
|
|
|
$this->items = $wp_user_search->get_results();
|
|
|
|
|
|
|
|
$this->set_pagination_args( array(
|
|
|
|
'total_items' => $wp_user_search->get_total(),
|
|
|
|
'per_page' => $users_per_page,
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_bulk_actions() {
|
|
|
|
$actions = array();
|
2010-11-12 17:00:41 +01:00
|
|
|
if ( current_user_can( 'delete_users' ) )
|
|
|
|
$actions['delete'] = __( 'Delete' );
|
2010-10-25 04:57:43 +02:00
|
|
|
$actions['spam'] = _x( 'Mark as Spam', 'user' );
|
|
|
|
$actions['notspam'] = _x( 'Not Spam', 'user' );
|
|
|
|
|
|
|
|
return $actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
function no_items() {
|
|
|
|
_e( 'No users found.' );
|
|
|
|
}
|
|
|
|
|
2010-11-10 18:05:20 +01:00
|
|
|
function get_views() {
|
2014-05-06 17:30:14 +02:00
|
|
|
global $role;
|
2010-11-10 18:05:20 +01:00
|
|
|
|
2010-11-24 21:03:28 +01:00
|
|
|
$total_users = get_user_count();
|
2010-11-10 18:05:20 +01:00
|
|
|
$super_admins = get_super_admins();
|
|
|
|
$total_admins = count( $super_admins );
|
|
|
|
|
|
|
|
$class = $role != 'super' ? ' class="current"' : '';
|
|
|
|
$role_links = array();
|
|
|
|
$role_links['all'] = "<a href='" . network_admin_url('users.php') . "'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>';
|
|
|
|
$class = $role == 'super' ? ' class="current"' : '';
|
|
|
|
$role_links['super'] = "<a href='" . network_admin_url('users.php?role=super') . "'$class>" . sprintf( _n( 'Super Admin <span class="count">(%s)</span>', 'Super Admins <span class="count">(%s)</span>', $total_admins ), number_format_i18n( $total_admins ) ) . '</a>';
|
|
|
|
|
|
|
|
return $role_links;
|
|
|
|
}
|
|
|
|
|
2010-10-25 04:57:43 +02:00
|
|
|
function pagination( $which ) {
|
|
|
|
global $mode;
|
|
|
|
|
|
|
|
parent::pagination ( $which );
|
|
|
|
|
|
|
|
if ( 'top' == $which )
|
|
|
|
$this->view_switcher( $mode );
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_columns() {
|
|
|
|
$users_columns = array(
|
|
|
|
'cb' => '<input type="checkbox" />',
|
2010-11-28 18:39:44 +01:00
|
|
|
'username' => __( 'Username' ),
|
2010-10-25 04:57:43 +02:00
|
|
|
'name' => __( 'Name' ),
|
|
|
|
'email' => __( 'E-mail' ),
|
|
|
|
'registered' => _x( 'Registered', 'user' ),
|
|
|
|
'blogs' => __( 'Sites' )
|
|
|
|
);
|
2013-11-23 23:25:10 +01:00
|
|
|
/**
|
|
|
|
* Filter the columns displayed in the Network Admin Users list table.
|
|
|
|
*
|
|
|
|
* @since MU
|
|
|
|
*
|
|
|
|
* @param array $users_columns An array of user columns. Default 'cb', 'username',
|
|
|
|
* 'name', 'email', 'registered', 'blogs'.
|
|
|
|
*/
|
2010-10-25 04:57:43 +02:00
|
|
|
$users_columns = apply_filters( 'wpmu_users_columns', $users_columns );
|
|
|
|
|
|
|
|
return $users_columns;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_sortable_columns() {
|
|
|
|
return array(
|
2010-11-28 18:39:44 +01:00
|
|
|
'username' => 'login',
|
2010-10-25 04:57:43 +02:00
|
|
|
'name' => 'name',
|
|
|
|
'email' => 'email',
|
2010-11-11 12:47:10 +01:00
|
|
|
'registered' => 'id',
|
2010-10-25 04:57:43 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function display_rows() {
|
2013-11-13 04:23:10 +01:00
|
|
|
global $mode;
|
2010-10-25 04:57:43 +02:00
|
|
|
|
2010-11-28 18:39:44 +01:00
|
|
|
$alt = '';
|
2010-10-25 04:57:43 +02:00
|
|
|
$super_admins = get_super_admins();
|
|
|
|
foreach ( $this->items as $user ) {
|
2010-11-28 18:39:44 +01:00
|
|
|
$alt = ( 'alternate' == $alt ) ? '' : 'alternate';
|
2010-10-25 04:57:43 +02:00
|
|
|
|
|
|
|
$status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' );
|
|
|
|
|
|
|
|
foreach ( $status_list as $status => $col ) {
|
|
|
|
if ( $user->$status )
|
2010-12-11 10:40:49 +01:00
|
|
|
$alt .= " $col";
|
2010-10-25 04:57:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
2010-11-28 18:39:44 +01:00
|
|
|
<tr class="<?php echo $alt; ?>">
|
2010-10-25 04:57:43 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
list( $columns, $hidden ) = $this->get_column_info();
|
|
|
|
|
|
|
|
foreach ( $columns as $column_name => $column_display_name ) :
|
2010-11-28 18:39:44 +01:00
|
|
|
$class = "class='$column_name column-$column_name'";
|
|
|
|
|
2010-11-13 21:47:34 +01:00
|
|
|
$style = '';
|
|
|
|
if ( in_array( $column_name, $hidden ) )
|
|
|
|
$style = ' style="display:none;"';
|
|
|
|
|
|
|
|
$attributes = "$class$style";
|
2010-12-13 22:21:50 +01:00
|
|
|
|
2010-10-25 04:57:43 +02:00
|
|
|
switch ( $column_name ) {
|
|
|
|
case 'cb': ?>
|
|
|
|
<th scope="row" class="check-column">
|
2012-07-25 18:18:14 +02:00
|
|
|
<label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>"><?php echo sprintf( __( 'Select %s' ), $user->user_login ); ?></label>
|
2010-10-25 04:57:43 +02:00
|
|
|
<input type="checkbox" id="blog_<?php echo $user->ID ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ) ?>" />
|
|
|
|
</th>
|
|
|
|
<?php
|
|
|
|
break;
|
|
|
|
|
2010-11-28 18:39:44 +01:00
|
|
|
case 'username':
|
2010-10-25 04:57:43 +02:00
|
|
|
$avatar = get_avatar( $user->user_email, 32 );
|
2013-03-01 18:00:25 +01:00
|
|
|
$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
|
2010-11-28 18:39:44 +01:00
|
|
|
|
|
|
|
echo "<td $attributes>"; ?>
|
2013-03-01 18:00:25 +01:00
|
|
|
<?php echo $avatar; ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo $user->user_login; ?></a><?php
|
2010-10-25 04:57:43 +02:00
|
|
|
if ( in_array( $user->user_login, $super_admins ) )
|
2010-11-10 18:05:20 +01:00
|
|
|
echo ' - ' . __( 'Super Admin' );
|
2010-10-25 04:57:43 +02:00
|
|
|
?></strong>
|
|
|
|
<br/>
|
|
|
|
<?php
|
|
|
|
$actions = array();
|
2011-01-01 23:30:46 +01:00
|
|
|
$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
|
2010-10-25 04:57:43 +02:00
|
|
|
|
2011-08-18 04:29:06 +02:00
|
|
|
if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) {
|
2013-03-01 18:00:25 +01:00
|
|
|
$actions['delete'] = '<a href="' . $delete = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&action=deleteuser&id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>';
|
2010-10-25 04:57:43 +02:00
|
|
|
}
|
|
|
|
|
2013-11-23 23:25:10 +01:00
|
|
|
/**
|
|
|
|
* Filter the action links displayed under each user
|
|
|
|
* in the Network Admin Users list table.
|
|
|
|
*
|
|
|
|
* @since 3.2.0
|
|
|
|
*
|
|
|
|
* @param array $actions An array of action links to be displayed.
|
|
|
|
* Default 'Edit', 'Delete'.
|
|
|
|
* @param WP_User $user WP_User object.
|
|
|
|
*/
|
2011-06-11 01:01:45 +02:00
|
|
|
$actions = apply_filters( 'ms_user_row_actions', $actions, $user );
|
2010-10-25 04:57:43 +02:00
|
|
|
echo $this->row_actions( $actions );
|
|
|
|
?>
|
|
|
|
</td>
|
|
|
|
<?php
|
|
|
|
break;
|
|
|
|
|
2010-11-28 18:39:44 +01:00
|
|
|
case 'name':
|
|
|
|
echo "<td $attributes>$user->first_name $user->last_name</td>";
|
2010-10-25 04:57:43 +02:00
|
|
|
break;
|
|
|
|
|
2010-11-28 18:39:44 +01:00
|
|
|
case 'email':
|
|
|
|
echo "<td $attributes><a href='mailto:$user->user_email'>$user->user_email</a></td>";
|
2010-10-25 04:57:43 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'registered':
|
|
|
|
if ( 'list' == $mode )
|
|
|
|
$date = 'Y/m/d';
|
|
|
|
else
|
|
|
|
$date = 'Y/m/d \<\b\r \/\> g:i:s a';
|
2010-11-28 18:39:44 +01:00
|
|
|
|
|
|
|
echo "<td $attributes>" . mysql2date( $date, $user->user_registered ) . "</td>";
|
2010-10-25 04:57:43 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'blogs':
|
|
|
|
$blogs = get_blogs_of_user( $user->ID, true );
|
2010-11-28 18:39:44 +01:00
|
|
|
echo "<td $attributes>";
|
2010-10-25 04:57:43 +02:00
|
|
|
if ( is_array( $blogs ) ) {
|
|
|
|
foreach ( (array) $blogs as $key => $val ) {
|
2010-12-09 13:36:39 +01:00
|
|
|
if ( !can_edit_network( $val->site_id ) )
|
2010-12-07 15:28:40 +01:00
|
|
|
continue;
|
2010-12-13 22:21:50 +01:00
|
|
|
|
2010-12-07 15:28:40 +01:00
|
|
|
$path = ( $val->path == '/' ) ? '' : $val->path;
|
2010-12-07 16:00:30 +01:00
|
|
|
echo '<span class="site-' . $val->site_id . '" >';
|
2013-11-13 04:23:10 +01:00
|
|
|
echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . get_current_site()->domain, '', $val->domain . $path ) . '</a>';
|
2010-12-07 16:00:30 +01:00
|
|
|
echo ' <small class="row-actions">';
|
2010-11-29 14:31:42 +01:00
|
|
|
$actions = array();
|
|
|
|
$actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>';
|
2010-12-13 22:21:50 +01:00
|
|
|
|
2010-11-29 14:31:42 +01:00
|
|
|
$class = '';
|
2010-10-25 04:57:43 +02:00
|
|
|
if ( get_blog_status( $val->userblog_id, 'spam' ) == 1 )
|
2010-11-29 14:31:42 +01:00
|
|
|
$class .= 'site-spammed ';
|
|
|
|
if ( get_blog_status( $val->userblog_id, 'mature' ) == 1 )
|
|
|
|
$class .= 'site-mature ';
|
|
|
|
if ( get_blog_status( $val->userblog_id, 'deleted' ) == 1 )
|
|
|
|
$class .= 'site-deleted ';
|
|
|
|
if ( get_blog_status( $val->userblog_id, 'archived' ) == 1 )
|
|
|
|
$class .= 'site-archived ';
|
2010-12-13 22:21:50 +01:00
|
|
|
|
2011-12-14 00:45:31 +01:00
|
|
|
$actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>';
|
2010-12-13 22:21:50 +01:00
|
|
|
|
2013-11-23 23:25:10 +01:00
|
|
|
/**
|
|
|
|
* Filter the action links displayed next the sites a user belongs to
|
|
|
|
* in the Network Admin Users list table.
|
|
|
|
*
|
|
|
|
* @since 3.1.0
|
|
|
|
*
|
|
|
|
* @param array $actions An array of action links to be displayed.
|
|
|
|
* Default 'Edit', 'View'.
|
|
|
|
* @param int $userblog_id The site ID.
|
|
|
|
*/
|
|
|
|
$actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id );
|
2010-12-13 22:21:50 +01:00
|
|
|
|
2010-11-29 14:31:42 +01:00
|
|
|
$i=0;
|
|
|
|
$action_count = count( $actions );
|
|
|
|
foreach ( $actions as $action => $link ) {
|
|
|
|
++$i;
|
|
|
|
( $i == $action_count ) ? $sep = '' : $sep = ' | ';
|
|
|
|
echo "<span class='$action'>$link$sep</span>";
|
|
|
|
}
|
2010-12-15 19:34:59 +01:00
|
|
|
echo '</small></span><br/>';
|
2010-10-25 04:57:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</td>
|
|
|
|
<?php
|
|
|
|
break;
|
|
|
|
|
2010-11-28 18:39:44 +01:00
|
|
|
default:
|
|
|
|
echo "<td $attributes>";
|
2013-11-23 23:25:10 +01:00
|
|
|
/** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
|
2010-11-28 18:39:44 +01:00
|
|
|
echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );
|
|
|
|
echo "</td>";
|
2010-10-25 04:57:43 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
endforeach
|
|
|
|
?>
|
|
|
|
</tr>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|