get_items_per_page( 'users_network_per_page' );
$role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
$paged = $this->get_pagenum();
$args = array(
'number' => $users_per_page,
'offset' => ( $paged-1 ) * $users_per_page,
'search' => $usersearch,
'blog_id' => 0,
'fields' => 'all_with_meta'
);
if ( wp_is_large_network( 'users' ) )
$args['search'] = ltrim( $args['search'], '*' );
if ( $role == 'super' ) {
$logins = implode( "', '", get_super_admins() );
$args['include'] = $wpdb->get_col( "SELECT ID FROM $wpdb->users WHERE user_login IN ('$logins')" );
}
/*
* 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 && wp_is_large_network( 'users' ) ) {
if ( !isset($_REQUEST['orderby']) )
$_GET['orderby'] = $_REQUEST['orderby'] = 'id';
if ( !isset($_REQUEST['order']) )
$_GET['order'] = $_REQUEST['order'] = 'DESC';
$args['count_total'] = false;
}
if ( isset( $_REQUEST['orderby'] ) )
$args['orderby'] = $_REQUEST['orderby'];
if ( isset( $_REQUEST['order'] ) )
$args['order'] = $_REQUEST['order'];
$mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
// 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,
) );
}
/**
*
* @return array
*/
protected function get_bulk_actions() {
$actions = array();
if ( current_user_can( 'delete_users' ) )
$actions['delete'] = __( 'Delete' );
$actions['spam'] = _x( 'Mark as Spam', 'user' );
$actions['notspam'] = _x( 'Not Spam', 'user' );
return $actions;
}
/**
* @access public
*/
public function no_items() {
_e( 'No users found.' );
}
/**
*
* @global string $role
* @return array
*/
protected function get_views() {
global $role;
$total_users = get_user_count();
$super_admins = get_super_admins();
$total_admins = count( $super_admins );
$class = $role != 'super' ? ' class="current"' : '';
$role_links = array();
$role_links['all'] = "" . sprintf( _nx( 'All (%s)', 'All (%s)', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '';
$class = $role == 'super' ? ' class="current"' : '';
$role_links['super'] = "" . sprintf( _n( 'Super Admin (%s)', 'Super Admins (%s)', $total_admins ), number_format_i18n( $total_admins ) ) . '';
return $role_links;
}
/**
* @global string $mode
* @param string $which
*/
protected function pagination( $which ) {
global $mode;
parent::pagination ( $which );
if ( 'top' == $which )
$this->view_switcher( $mode );
}
/**
*
* @return array
*/
public function get_columns() {
$users_columns = array(
'cb' => '',
'username' => __( 'Username' ),
'name' => __( 'Name' ),
'email' => __( 'E-mail' ),
'registered' => _x( 'Registered', 'user' ),
'blogs' => __( 'Sites' )
);
/**
* 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'.
*/
return apply_filters( 'wpmu_users_columns', $users_columns );
}
/**
*
* @return array
*/
protected function get_sortable_columns() {
return array(
'username' => 'login',
'name' => 'name',
'email' => 'email',
'registered' => 'id',
);
}
/**
* Handles the checkbox column output.
*
* @since 4.3.0
* @access public
*
* @param WP_User $user The current WP_User object.
*/
public function column_cb( $user ) {
?>
user_email, 32 );
$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
echo $avatar;
?>user_login; ?>user_login, $super_admins ) ) {
echo ' - ' . __( 'Super Admin' );
}
?>
first_name $user->last_name";
}
/**
* Handles the email column output.
*
* @since 4.3.0
* @access public
*
* @param WP_User $user The current WP_User object.
*/
public function column_email( $user ) {
echo "$user->user_email";
}
/**
* Handles the registered date column output.
*
* @since 4.3.0
* @access public
*
* @global string $mode
*
* @param WP_User $user The current WP_User object.
*/
public function column_registered( $user ) {
global $mode;
if ( 'list' == $mode ) {
$date = __( 'Y/m/d' );
} else {
$date = __( 'Y/m/d g:i:s a' );
}
echo mysql2date( $date, $user->user_registered );
}
/**
* Handles the blogs/sites column output.
*
* @since 4.3.0
* @access public
*
* @param WP_User $user The current WP_User object.
*/
public function column_blogs( $user ) {
$blogs = get_blogs_of_user( $user->ID, true );
if ( ! is_array( $blogs ) ) {
return;
}
foreach ( $blogs as $val ) {
if ( ! can_edit_network( $val->site_id ) ) {
continue;
}
$path = ( $val->path == '/' ) ? '' : $val->path;
echo '';
echo '' . str_replace( '.' . get_current_site()->domain, '', $val->domain . $path ) . '';
echo ' ';
$actions = array();
$actions['edit'] = '' . __( 'Edit' ) . '';
$class = '';
if ( $val->spam == 1 ) {
$class .= 'site-spammed ';
}
if ( $val->mature == 1 ) {
$class .= 'site-mature ';
}
if ( $val->deleted == 1 ) {
$class .= 'site-deleted ';
}
if ( $val->archived == 1 ) {
$class .= 'site-archived ';
}
$actions['view'] = '' . __( 'View' ) . '';
/**
* 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 );
$i=0;
$action_count = count( $actions );
foreach ( $actions as $action => $link ) {
++$i;
$sep = ( $i == $action_count ) ? '' : ' | ';
echo "$link$sep";
}
echo '
';
}
}
/**
* Handles the default column output.
*
* @since 4.3.0
* @access public
*
* @param WP_User $user The current WP_User object.
* @param string $column_name The current column name.
*/
public function column_default( $user, $column_name ) {
/** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );
}
/**
* Handles columns output for a single row in the table.
*
* @since 4.3.0
* @access public
*
* @param WP_User $item The current WP_User object.
*/
public function single_row_columns( $item ) {
list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
foreach ( $columns as $column_name => $column_display_name ) {
$classes = "$column_name column-$column_name";
if ( $primary === $column_name || 'blogs' === $column_name ) {
$classes .= ' has-row-actions';
}
if ( $primary === $column_name ) {
$classes .= ' column-primary';
}
if ( in_array( $column_name, $hidden ) ) {
$classes .= ' hidden';
}
$data = 'data-colname="' . wp_strip_all_tags( $column_display_name ) . '"';
$attributes = "class='$classes' $data";
if ( 'cb' === $column_name ) {
echo '