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
|
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
|
|
|
|
|
|
|
function check_permissions() {
|
|
|
|
if ( !is_multisite() )
|
|
|
|
wp_die( __( 'Multisite support is not enabled.' ) );
|
|
|
|
|
|
|
|
if ( ! current_user_can( 'manage_network_users' ) )
|
|
|
|
wp_die( __( 'You do not have permission to access this page.' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
function prepare_items() {
|
2010-11-28 18:39:44 +01:00
|
|
|
global $usersearch, $role, $wpdb, $mode;
|
2010-10-25 04:57:43 +02:00
|
|
|
|
|
|
|
$usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
|
|
|
|
|
|
|
|
$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,
|
|
|
|
'blog_id' => 0
|
|
|
|
);
|
|
|
|
|
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.
|
|
|
|
if ( !$usersearch && ( get_blog_count() >= 10000 ) ) {
|
|
|
|
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() {
|
|
|
|
global $wp_roles, $role;
|
|
|
|
|
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 );
|
|
|
|
|
|
|
|
$current_role = false;
|
|
|
|
$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' )
|
|
|
|
);
|
|
|
|
$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() {
|
|
|
|
global $current_site, $mode;
|
|
|
|
|
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-11-28 18:39:44 +01:00
|
|
|
|
2010-11-13 21:47:34 +01:00
|
|
|
|
2010-10-25 04:57:43 +02:00
|
|
|
switch ( $column_name ) {
|
|
|
|
case 'cb': ?>
|
|
|
|
<th scope="row" class="check-column">
|
|
|
|
<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 );
|
|
|
|
$edit_link = ( get_current_user_id() == $user->ID ) ? 'profile.php' : 'user-edit.php?user_id=' . $user->ID;
|
2010-11-28 18:39:44 +01:00
|
|
|
|
|
|
|
echo "<td $attributes>"; ?>
|
2010-10-25 04:57:43 +02:00
|
|
|
<?php echo $avatar; ?><strong><a href="<?php echo esc_url( self_admin_url( $edit_link ) ); ?>" class="edit"><?php echo stripslashes( $user->user_login ); ?></a><?php
|
|
|
|
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();
|
|
|
|
$actions['edit'] = '<a href="' . esc_url( self_admin_url( $edit_link ) ) . '">' . __( 'Edit' ) . '</a>';
|
|
|
|
|
2010-11-12 17:00:41 +01:00
|
|
|
if ( current_user_can( 'delete_user', $user->ID) && ! in_array( $user->user_login, $super_admins ) ) {
|
2010-10-25 04:57:43 +02:00
|
|
|
$actions['delete'] = '<a href="' . $delete = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'edit.php', 'deleteuser' ) . '&action=deleteuser&id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo $this->row_actions( $actions );
|
|
|
|
?>
|
|
|
|
</div>
|
|
|
|
</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-11-29 14:31:42 +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 . '" >';
|
2010-10-25 04:57:43 +02:00
|
|
|
echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . $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>';
|
|
|
|
|
|
|
|
$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 ';
|
|
|
|
|
|
|
|
$actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>';
|
|
|
|
|
|
|
|
$actions = apply_filters('ms_user_list_site_actions', $actions, $val->userblog_id);
|
|
|
|
|
|
|
|
$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-07 16:00:30 +01:00
|
|
|
echo '</span></small><br/>';
|
2010-10-25 04:57:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</td>
|
|
|
|
<?php
|
|
|
|
break;
|
|
|
|
|
2010-11-28 18:39:44 +01:00
|
|
|
default:
|
|
|
|
echo "<td $attributes>";
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-04 16:00:55 +01:00
|
|
|
?>
|