| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * List Table API: WP_MS_Users_List_Table class | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @package WordPress | 
					
						
							|  |  |  |  * @subpackage Administration | 
					
						
							|  |  |  |  * @since 3.1.0 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Core class used to implement displaying users in a list table for the network admin. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @since 3.1.0 | 
					
						
							|  |  |  |  * @access private | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @see WP_List_Table | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class WP_MS_Users_List_Table extends WP_List_Table { | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @return bool | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function ajax_user_can() { | 
					
						
							|  |  |  | 		return current_user_can( 'manage_network_users' ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @global string $usersearch | 
					
						
							|  |  |  | 	 * @global string $role | 
					
						
							|  |  |  | 	 * @global string $mode | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function prepare_items() { | 
					
						
							| 
									
										
										
										
											2019-05-08 08:05:39 +01:00
										 |  |  | 		global $usersearch, $role, $mode; | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		$usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : ''; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$users_per_page = $this->get_items_per_page( 'users_network_per_page' ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : ''; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$paged = $this->get_pagenum(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$args = array( | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 			'number'  => $users_per_page, | 
					
						
							|  |  |  | 			'offset'  => ( $paged - 1 ) * $users_per_page, | 
					
						
							|  |  |  | 			'search'  => $usersearch, | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 			'blog_id' => 0, | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 			'fields'  => 'all_with_meta', | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 		); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ( wp_is_large_network( 'users' ) ) { | 
					
						
							|  |  |  | 			$args['search'] = ltrim( $args['search'], '*' ); | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 		} elseif ( '' !== $args['search'] ) { | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 			$args['search'] = trim( $args['search'], '*' ); | 
					
						
							|  |  |  | 			$args['search'] = '*' . $args['search'] . '*'; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ( $role === 'super' ) { | 
					
						
							| 
									
										
										
										
											2019-05-08 08:05:39 +01:00
										 |  |  | 			$args['login__in'] = get_super_admins(); | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00: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. | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 		if ( ! $usersearch && wp_is_large_network( 'users' ) ) { | 
					
						
							|  |  |  | 			if ( ! isset( $_REQUEST['orderby'] ) ) { | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 				$_GET['orderby'] = $_REQUEST['orderby'] = 'id'; | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if ( ! isset( $_REQUEST['order'] ) ) { | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 				$_GET['order'] = $_REQUEST['order'] = 'DESC'; | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 			$args['count_total'] = false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 		if ( isset( $_REQUEST['orderby'] ) ) { | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 			$args['orderby'] = $_REQUEST['orderby']; | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 		if ( isset( $_REQUEST['order'] ) ) { | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 			$args['order'] = $_REQUEST['order']; | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if ( ! empty( $_REQUEST['mode'] ) ) { | 
					
						
							|  |  |  | 			$mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list'; | 
					
						
							|  |  |  | 			set_user_setting( 'network_users_list_mode', $mode ); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			$mode = get_user_setting( 'network_users_list_mode', 'list' ); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */ | 
					
						
							|  |  |  | 		$args = apply_filters( 'users_list_table_query_args', $args ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Query the user IDs for this page
 | 
					
						
							|  |  |  | 		$wp_user_search = new WP_User_Query( $args ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$this->items = $wp_user_search->get_results(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 		$this->set_pagination_args( | 
					
						
							|  |  |  | 			array( | 
					
						
							|  |  |  | 				'total_items' => $wp_user_search->get_total(), | 
					
						
							|  |  |  | 				'per_page'    => $users_per_page, | 
					
						
							|  |  |  | 			) | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @return array | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	protected function get_bulk_actions() { | 
					
						
							|  |  |  | 		$actions = array(); | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 		if ( current_user_can( 'delete_users' ) ) { | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 			$actions['delete'] = __( 'Delete' ); | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		$actions['spam']    = _x( 'Mark as Spam', 'user' ); | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 		$actions['notspam'] = _x( 'Not Spam', 'user' ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return $actions; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function no_items() { | 
					
						
							|  |  |  | 		_e( 'No users found.' ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @global string $role | 
					
						
							|  |  |  | 	 * @return array | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	protected function get_views() { | 
					
						
							|  |  |  | 		global $role; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 		$total_users  = get_user_count(); | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 		$super_admins = get_super_admins(); | 
					
						
							|  |  |  | 		$total_admins = count( $super_admins ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$current_link_attributes = $role !== 'super' ? ' class="current" aria-current="page"' : ''; | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 		$role_links              = array(); | 
					
						
							|  |  |  | 		$role_links['all']       = "<a href='" . network_admin_url( 'users.php' ) . "'$current_link_attributes>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>'; | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 		$current_link_attributes = $role === 'super' ? ' class="current" aria-current="page"' : ''; | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 		$role_links['super']     = "<a href='" . network_admin_url( 'users.php?role=super' ) . "'$current_link_attributes>" . sprintf( _n( 'Super Admin <span class="count">(%s)</span>', 'Super Admins <span class="count">(%s)</span>', $total_admins ), number_format_i18n( $total_admins ) ) . '</a>'; | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return $role_links; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @global string $mode List table view mode. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param string $which | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	protected function pagination( $which ) { | 
					
						
							|  |  |  | 		global $mode; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 		parent::pagination( $which ); | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if ( 'top' === $which ) { | 
					
						
							|  |  |  | 			$this->view_switcher( $mode ); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @return array | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function get_columns() { | 
					
						
							|  |  |  | 		$users_columns = array( | 
					
						
							|  |  |  | 			'cb'         => '<input type="checkbox" />', | 
					
						
							|  |  |  | 			'username'   => __( 'Username' ), | 
					
						
							|  |  |  | 			'name'       => __( 'Name' ), | 
					
						
							|  |  |  | 			'email'      => __( 'Email' ), | 
					
						
							|  |  |  | 			'registered' => _x( 'Registered', 'user' ), | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 			'blogs'      => __( 'Sites' ), | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 		); | 
					
						
							|  |  |  | 		/** | 
					
						
							|  |  |  | 		 * Filters the columns displayed in the Network Admin Users list table. | 
					
						
							|  |  |  | 		 * | 
					
						
							|  |  |  | 		 * @since MU (3.0.0) | 
					
						
							|  |  |  | 		 * | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 		 * @param string[] $users_columns An array of user columns. Default 'cb', 'username', | 
					
						
							|  |  |  | 		 *                                'name', 'email', 'registered', 'blogs'. | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 		 */ | 
					
						
							|  |  |  | 		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 | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param WP_User $user The current WP_User object. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function column_cb( $user ) { | 
					
						
							|  |  |  | 		if ( is_super_admin( $user->ID ) ) { | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		?>
 | 
					
						
							|  |  |  | 		<label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>"><?php echo sprintf( __( 'Select %s' ), $user->user_login ); ?></label>
 | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 		<input type="checkbox" id="blog_<?php echo $user->ID; ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ); ?>" /> | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 		<?php | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Handles the ID column output. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @since 4.4.0 | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param WP_User $user The current WP_User object. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function column_id( $user ) { | 
					
						
							|  |  |  | 		echo $user->ID; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Handles the username column output. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @since 4.3.0 | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param WP_User $user The current WP_User object. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function column_username( $user ) { | 
					
						
							|  |  |  | 		$super_admins = get_super_admins(); | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 		$avatar       = get_avatar( $user->user_email, 32 ); | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		echo $avatar; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 		if ( current_user_can( 'edit_user', $user->ID ) ) { | 
					
						
							|  |  |  | 			$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) ); | 
					
						
							|  |  |  | 			$edit      = "<a href=\"{$edit_link}\">{$user->user_login}</a>"; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			$edit = $user->user_login; | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		?>
 | 
					
						
							|  |  |  | 		<strong> | 
					
						
							|  |  |  | 			<?php | 
					
						
							|  |  |  | 			echo $edit; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if ( in_array( $user->user_login, $super_admins ) ) { | 
					
						
							|  |  |  | 				echo ' — ' . __( 'Super Admin' ); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			?>
 | 
					
						
							|  |  |  | 		</strong> | 
					
						
							|  |  |  | 		<?php | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Handles the name column output. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @since 4.3.0 | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param WP_User $user The current WP_User object. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function column_name( $user ) { | 
					
						
							|  |  |  | 		if ( $user->first_name && $user->last_name ) { | 
					
						
							|  |  |  | 			echo "$user->first_name $user->last_name"; | 
					
						
							|  |  |  | 		} elseif ( $user->first_name ) { | 
					
						
							|  |  |  | 			echo $user->first_name; | 
					
						
							|  |  |  | 		} elseif ( $user->last_name ) { | 
					
						
							|  |  |  | 			echo $user->last_name; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			echo '<span aria-hidden="true">—</span><span class="screen-reader-text">' . _x( 'Unknown', 'name' ) . '</span>'; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Handles the email column output. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @since 4.3.0 | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param WP_User $user The current WP_User object. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function column_email( $user ) { | 
					
						
							|  |  |  | 		echo "<a href='" . esc_url( "mailto:$user->user_email" ) . "'>$user->user_email</a>"; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Handles the registered date column output. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @since 4.3.0 | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @global string $mode List table view 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 ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @since 4.3.0 | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param WP_User $user | 
					
						
							|  |  |  | 	 * @param string  $classes | 
					
						
							|  |  |  | 	 * @param string  $data | 
					
						
							|  |  |  | 	 * @param string  $primary | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	protected function _column_blogs( $user, $classes, $data, $primary ) { | 
					
						
							|  |  |  | 		echo '<td class="', $classes, ' has-row-actions" ', $data, '>'; | 
					
						
							|  |  |  | 		echo $this->column_blogs( $user ); | 
					
						
							|  |  |  | 		echo $this->handle_row_actions( $user, 'blogs', $primary ); | 
					
						
							|  |  |  | 		echo '</td>'; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Handles the sites column output. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @since 4.3.0 | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @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; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 08:05:39 +01:00
										 |  |  | 			$path         = ( $val->path === '/' ) ? '' : $val->path; | 
					
						
							|  |  |  | 			$site_classes = array( 'site-' . $val->site_id ); | 
					
						
							|  |  |  | 			/** | 
					
						
							|  |  |  | 			 * Filters the span class for a site listing on the mulisite user list table. | 
					
						
							|  |  |  | 			 * | 
					
						
							|  |  |  | 			 * @since 5.2.0 | 
					
						
							|  |  |  | 			 * | 
					
						
							|  |  |  | 			 * @param array  $site_classes Class used within the span tag. Default "site-#" with the site's network ID. | 
					
						
							|  |  |  | 			 * @param int    $site_id      Site ID. | 
					
						
							|  |  |  | 			 * @param int    $network_id   Network ID. | 
					
						
							|  |  |  | 			 * @param object $user         WP_User object. | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			$site_classes = apply_filters( 'ms_user_list_site_class', $site_classes, $val->userblog_id, $val->site_id, $user ); | 
					
						
							|  |  |  | 			if ( is_array( $site_classes ) && ! empty( $site_classes ) ) { | 
					
						
							|  |  |  | 				$site_classes = array_map( 'sanitize_html_class', array_unique( $site_classes ) ); | 
					
						
							|  |  |  | 				echo '<span class="' . esc_attr( implode( ' ', $site_classes ) ) . '">'; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				echo '<span>'; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 			echo '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) . '">' . str_replace( '.' . get_network()->domain, '', $val->domain . $path ) . '</a>'; | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 			echo ' <small class="row-actions">'; | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 			$actions         = array(); | 
					
						
							|  |  |  | 			$actions['edit'] = '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) . '">' . __( 'Edit' ) . '</a>'; | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			$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'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/** | 
					
						
							|  |  |  | 			 * Filters the action links displayed next the sites a user belongs to | 
					
						
							|  |  |  | 			 * in the Network Admin Users list table. | 
					
						
							|  |  |  | 			 * | 
					
						
							|  |  |  | 			 * @since 3.1.0 | 
					
						
							|  |  |  | 			 * | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 			 * @param string[] $actions     An array of action links to be displayed. Default 'Edit', 'View'. | 
					
						
							|  |  |  | 			 * @param int      $userblog_id The site ID. | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 			 */ | 
					
						
							|  |  |  | 			$actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 			$i            = 0; | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 			$action_count = count( $actions ); | 
					
						
							|  |  |  | 			foreach ( $actions as $action => $link ) { | 
					
						
							|  |  |  | 				++$i; | 
					
						
							|  |  |  | 				$sep = ( $i == $action_count ) ? '' : ' | '; | 
					
						
							|  |  |  | 				echo "<span class='$action'>$link$sep</span>"; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			echo '</small></span><br/>'; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Handles the default column output. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @since 4.3.0 | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @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 ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public function display_rows() { | 
					
						
							|  |  |  | 		foreach ( $this->items as $user ) { | 
					
						
							|  |  |  | 			$class = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 			$status_list = array( | 
					
						
							|  |  |  | 				'spam'    => 'site-spammed', | 
					
						
							|  |  |  | 				'deleted' => 'site-deleted', | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			foreach ( $status_list as $status => $col ) { | 
					
						
							|  |  |  | 				if ( $user->$status ) { | 
					
						
							|  |  |  | 					$class .= " $col"; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			?>
 | 
					
						
							|  |  |  | 			<tr class="<?php echo trim( $class ); ?>"> | 
					
						
							|  |  |  | 				<?php $this->single_row_columns( $user ); ?>
 | 
					
						
							|  |  |  | 			</tr> | 
					
						
							|  |  |  | 			<?php | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Gets the name of the default primary column. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @since 4.3.0 | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return string Name of the default primary column, in this case, 'username'. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	protected function get_default_primary_column_name() { | 
					
						
							|  |  |  | 		return 'username'; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Generates and displays row action links. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @since 4.3.0 | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param object $user        User being acted upon. | 
					
						
							|  |  |  | 	 * @param string $column_name Current column name. | 
					
						
							|  |  |  | 	 * @param string $primary     Primary column name. | 
					
						
							|  |  |  | 	 * @return string Row actions output for users in Multisite. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	protected function handle_row_actions( $user, $column_name, $primary ) { | 
					
						
							|  |  |  | 		if ( $primary !== $column_name ) { | 
					
						
							|  |  |  | 			return ''; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$super_admins = get_super_admins(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$actions = array(); | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if ( current_user_can( 'edit_user', $user->ID ) ) { | 
					
						
							|  |  |  | 			$edit_link       = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) ); | 
					
						
							|  |  |  | 			$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) { | 
					
						
							|  |  |  | 			$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>'; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/** | 
					
						
							|  |  |  | 		 * Filters the action links displayed under each user in the Network Admin Users list table. | 
					
						
							|  |  |  | 		 * | 
					
						
							|  |  |  | 		 * @since 3.2.0 | 
					
						
							|  |  |  | 		 * | 
					
						
							| 
									
										
										
										
											2019-04-16 20:56:22 +01:00
										 |  |  | 		 * @param string[] $actions An array of action links to be displayed. Default 'Edit', 'Delete'. | 
					
						
							|  |  |  | 		 * @param WP_User  $user    WP_User object. | 
					
						
							| 
									
										
										
										
											2019-03-12 09:27:46 +00:00
										 |  |  | 		 */ | 
					
						
							|  |  |  | 		$actions = apply_filters( 'ms_user_row_actions', $actions, $user ); | 
					
						
							|  |  |  | 		return $this->row_actions( $actions ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |