web/wp-admin/includes/class-wp-users-list-table.php
changeset 204 09a1c134465b
parent 194 32102edaa81b
equal deleted inserted replaced
203:f507feede89a 204:09a1c134465b
    10 class WP_Users_List_Table extends WP_List_Table {
    10 class WP_Users_List_Table extends WP_List_Table {
    11 
    11 
    12 	var $site_id;
    12 	var $site_id;
    13 	var $is_site_users;
    13 	var $is_site_users;
    14 
    14 
    15 	function __construct() {
    15 	function __construct( $args = array() ) {
    16 		$screen = get_current_screen();
       
    17 		$this->is_site_users = 'site-users-network' == $screen->id;
       
    18 
       
    19 		if ( $this->is_site_users )
       
    20 			$this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
       
    21 
       
    22 		parent::__construct( array(
    16 		parent::__construct( array(
    23 			'singular' => 'user',
    17 			'singular' => 'user',
    24 			'plural'   => 'users'
    18 			'plural'   => 'users',
       
    19 			'screen'   => isset( $args['screen'] ) ? $args['screen'] : null,
    25 		) );
    20 		) );
       
    21 
       
    22 		$this->is_site_users = 'site-users-network' == $this->screen->id;
       
    23 
       
    24 		if ( $this->is_site_users )
       
    25 			$this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
    26 	}
    26 	}
    27 
    27 
    28 	function ajax_user_can() {
    28 	function ajax_user_can() {
    29 		if ( $this->is_site_users )
    29 		if ( $this->is_site_users )
    30 			return current_user_can( 'manage_sites' );
    30 			return current_user_can( 'manage_sites' );
    33 	}
    33 	}
    34 
    34 
    35 	function prepare_items() {
    35 	function prepare_items() {
    36 		global $role, $usersearch;
    36 		global $role, $usersearch;
    37 
    37 
    38 		$usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
    38 		$usersearch = isset( $_REQUEST['s'] ) ? trim( $_REQUEST['s'] ) : '';
    39 
    39 
    40 		$role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
    40 		$role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
    41 
    41 
    42 		$per_page = ( $this->is_site_users ) ? 'site_users_network_per_page' : 'users_per_page';
    42 		$per_page = ( $this->is_site_users ) ? 'site_users_network_per_page' : 'users_per_page';
    43 		$users_per_page = $this->get_items_per_page( $per_page );
    43 		$users_per_page = $this->get_items_per_page( $per_page );
   134 	}
   134 	}
   135 
   135 
   136 	function extra_tablenav( $which ) {
   136 	function extra_tablenav( $which ) {
   137 		if ( 'top' != $which )
   137 		if ( 'top' != $which )
   138 			return;
   138 			return;
   139 		if ( ! current_user_can( 'promote_users' ) )
   139 	?>
   140 			return;
       
   141 ?>
       
   142 	<div class="alignleft actions">
   140 	<div class="alignleft actions">
       
   141 		<?php if ( current_user_can( 'promote_users' ) ) : ?>
   143 		<label class="screen-reader-text" for="new_role"><?php _e( 'Change role to&hellip;' ) ?></label>
   142 		<label class="screen-reader-text" for="new_role"><?php _e( 'Change role to&hellip;' ) ?></label>
   144 		<select name="new_role" id="new_role">
   143 		<select name="new_role" id="new_role">
   145 			<option value=''><?php _e( 'Change role to&hellip;' ) ?></option>
   144 			<option value=''><?php _e( 'Change role to&hellip;' ) ?></option>
   146 			<?php wp_dropdown_roles(); ?>
   145 			<?php wp_dropdown_roles(); ?>
   147 		</select>
   146 		</select>
   148 		<?php submit_button( __( 'Change' ), 'secondary', 'changeit', false ); ?>
   147 	<?php
   149 	</div>
   148 			submit_button( __( 'Change' ), 'button', 'changeit', false );
   150 <?php
   149 		endif;
       
   150 
       
   151 		do_action( 'restrict_manage_users' );
       
   152 		echo '</div>';
   151 	}
   153 	}
   152 
   154 
   153 	function current_action() {
   155 	function current_action() {
   154 		if ( isset($_REQUEST['changeit']) && !empty($_REQUEST['new_role']) )
   156 		if ( isset($_REQUEST['changeit']) && !empty($_REQUEST['new_role']) )
   155 			return 'promote';
   157 			return 'promote';
   189 	function display_rows() {
   191 	function display_rows() {
   190 		// Query the post counts for this page
   192 		// Query the post counts for this page
   191 		if ( ! $this->is_site_users )
   193 		if ( ! $this->is_site_users )
   192 			$post_counts = count_many_users_posts( array_keys( $this->items ) );
   194 			$post_counts = count_many_users_posts( array_keys( $this->items ) );
   193 
   195 
       
   196 		$editable_roles = array_keys( get_editable_roles() );
       
   197 
   194 		$style = '';
   198 		$style = '';
   195 		foreach ( $this->items as $userid => $user_object ) {
   199 		foreach ( $this->items as $userid => $user_object ) {
   196 			$role = reset( $user_object->roles );
   200 			if ( count( $user_object->roles ) <= 1 ) {
   197 
   201 				$role = reset( $user_object->roles );
   198 			if ( is_multisite() && empty( $role ) )
   202 			} elseif ( $roles = array_intersect( array_values( $user_object->roles ), $editable_roles ) ) {
       
   203 				$role = reset( $roles );
       
   204 			} else {
       
   205 				$role = reset( $user_object->roles );
       
   206 			}
       
   207 
       
   208 			if ( is_multisite() && empty( $user_object->allcaps ) )
   199 				continue;
   209 				continue;
   200 
   210 
   201 			$style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"';
   211 			$style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"';
   202 			echo "\n\t", $this->single_row( $user_object, $style, $role, isset( $post_counts ) ? $post_counts[ $userid ] : 0 );
   212 			echo "\n\t", $this->single_row( $user_object, $style, $role, isset( $post_counts ) ? $post_counts[ $userid ] : 0 );
   203 		}
   213 		}
   216 	 */
   226 	 */
   217 	function single_row( $user_object, $style = '', $role = '', $numposts = 0 ) {
   227 	function single_row( $user_object, $style = '', $role = '', $numposts = 0 ) {
   218 		global $wp_roles;
   228 		global $wp_roles;
   219 
   229 
   220 		if ( !( is_object( $user_object ) && is_a( $user_object, 'WP_User' ) ) )
   230 		if ( !( is_object( $user_object ) && is_a( $user_object, 'WP_User' ) ) )
   221 			$user_object = new WP_User( (int) $user_object );
   231 			$user_object = get_userdata( (int) $user_object );
   222 		$user_object->filter = 'display';
   232 		$user_object->filter = 'display';
   223 		$email = $user_object->user_email;
   233 		$email = $user_object->user_email;
   224 
   234 
   225 		if ( $this->is_site_users )
   235 		if ( $this->is_site_users )
   226 			$url = "site-users.php?id={$this->site_id}&amp;";
   236 			$url = "site-users.php?id={$this->site_id}&amp;";
   229 
   239 
   230 		$checkbox = '';
   240 		$checkbox = '';
   231 		// Check if the user for this row is editable
   241 		// Check if the user for this row is editable
   232 		if ( current_user_can( 'list_users' ) ) {
   242 		if ( current_user_can( 'list_users' ) ) {
   233 			// Set up the user editing link
   243 			// Set up the user editing link
   234 			// TODO: make profile/user-edit determination a separate function
   244 			$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user_object->ID ) ) );
   235 			if ( get_current_user_id() == $user_object->ID ) {
       
   236 				$edit_link = 'profile.php';
       
   237 			} else {
       
   238 				$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), "user-edit.php?user_id=$user_object->ID" ) );
       
   239 			}
       
   240 
   245 
   241 			// Set up the hover actions for this user
   246 			// Set up the hover actions for this user
   242 			$actions = array();
   247 			$actions = array();
   243 
   248 
   244 			if ( current_user_can( 'edit_user',  $user_object->ID ) ) {
   249 			if ( current_user_can( 'edit_user',  $user_object->ID ) ) {
   254 				$actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url( $url."action=remove&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . "</a>";
   259 				$actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url( $url."action=remove&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . "</a>";
   255 			$actions = apply_filters( 'user_row_actions', $actions, $user_object );
   260 			$actions = apply_filters( 'user_row_actions', $actions, $user_object );
   256 			$edit .= $this->row_actions( $actions );
   261 			$edit .= $this->row_actions( $actions );
   257 
   262 
   258 			// Set up the checkbox ( because the user is editable, otherwise its empty )
   263 			// Set up the checkbox ( because the user is editable, otherwise its empty )
   259 			$checkbox = "<input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' />";
   264 			$checkbox = '<label class="screen-reader-text" for="cb-select-' . $user_object->ID . '">' . sprintf( __( 'Select %s' ), $user_object->user_login ) . '</label>'
       
   265 						. "<input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' />";
   260 
   266 
   261 		} else {
   267 		} else {
   262 			$edit = '<strong>' . $user_object->user_login . '</strong>';
   268 			$edit = '<strong>' . $user_object->user_login . '</strong>';
   263 		}
   269 		}
   264 		$role_name = isset( $wp_roles->role_names[$role] ) ? translate_user_role( $wp_roles->role_names[$role] ) : __( 'None' );
   270 		$role_name = isset( $wp_roles->role_names[$role] ) ? translate_user_role( $wp_roles->role_names[$role] ) : __( 'None' );