wp/wp-admin/network/users.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
     8  */
     8  */
     9 
     9 
    10 /** Load WordPress Administration Bootstrap */
    10 /** Load WordPress Administration Bootstrap */
    11 require_once( dirname( __FILE__ ) . '/admin.php' );
    11 require_once( dirname( __FILE__ ) . '/admin.php' );
    12 
    12 
    13 if ( ! current_user_can( 'manage_network_users' ) )
    13 if ( ! current_user_can( 'manage_network_users' ) ) {
    14 	wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
    14 	wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
       
    15 }
    15 
    16 
    16 if ( isset( $_GET['action'] ) ) {
    17 if ( isset( $_GET['action'] ) ) {
    17 	/** This action is documented in wp-admin/network/edit.php */
    18 	/** This action is documented in wp-admin/network/edit.php */
    18 	do_action( 'wpmuadminedit' );
    19 	do_action( 'wpmuadminedit' );
    19 
    20 
    20 	switch ( $_GET['action'] ) {
    21 	switch ( $_GET['action'] ) {
    21 		case 'deleteuser':
    22 		case 'deleteuser':
    22 			if ( ! current_user_can( 'manage_network_users' ) )
    23 			if ( ! current_user_can( 'manage_network_users' ) ) {
    23 				wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
    24 				wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
       
    25 			}
    24 
    26 
    25 			check_admin_referer( 'deleteuser' );
    27 			check_admin_referer( 'deleteuser' );
    26 
    28 
    27 			$id = intval( $_GET['id'] );
    29 			$id = intval( $_GET['id'] );
    28 			if ( $id != '0' && $id != '1' ) {
    30 			if ( $id != '0' && $id != '1' ) {
    29 				$_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle with arrays
    31 				$_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle with arrays
    30 				$title = __( 'Users' );
    32 				$title             = __( 'Users' );
    31 				$parent_file = 'users.php';
    33 				$parent_file       = 'users.php';
    32 				require_once( ABSPATH . 'wp-admin/admin-header.php' );
    34 				require_once( ABSPATH . 'wp-admin/admin-header.php' );
    33 				echo '<div class="wrap">';
    35 				echo '<div class="wrap">';
    34 				confirm_delete_users( $_POST['allusers'] );
    36 				confirm_delete_users( $_POST['allusers'] );
    35 				echo '</div>';
    37 				echo '</div>';
    36 				require_once( ABSPATH . 'wp-admin/admin-footer.php' );
    38 				require_once( ABSPATH . 'wp-admin/admin-footer.php' );
    38 				wp_redirect( network_admin_url( 'users.php' ) );
    40 				wp_redirect( network_admin_url( 'users.php' ) );
    39 			}
    41 			}
    40 			exit();
    42 			exit();
    41 
    43 
    42 		case 'allusers':
    44 		case 'allusers':
    43 			if ( !current_user_can( 'manage_network_users' ) )
    45 			if ( ! current_user_can( 'manage_network_users' ) ) {
    44 				wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
    46 				wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
    45 
    47 			}
    46 			if ( ( isset( $_POST['action']) || isset($_POST['action2'] ) ) && isset( $_POST['allusers'] ) ) {
    48 
       
    49 			if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allusers'] ) ) {
    47 				check_admin_referer( 'bulk-users-network' );
    50 				check_admin_referer( 'bulk-users-network' );
    48 
    51 
    49 				$doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
    52 				$doaction     = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
    50 				$userfunction = '';
    53 				$userfunction = '';
    51 
    54 
    52 				foreach ( (array) $_POST['allusers'] as $user_id ) {
    55 				foreach ( (array) $_POST['allusers'] as $user_id ) {
    53 					if ( !empty( $user_id ) ) {
    56 					if ( ! empty( $user_id ) ) {
    54 						switch ( $doaction ) {
    57 						switch ( $doaction ) {
    55 							case 'delete':
    58 							case 'delete':
    56 								if ( ! current_user_can( 'delete_users' ) )
    59 								if ( ! current_user_can( 'delete_users' ) ) {
    57 									wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
    60 									wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
    58 								$title = __( 'Users' );
    61 								}
       
    62 								$title       = __( 'Users' );
    59 								$parent_file = 'users.php';
    63 								$parent_file = 'users.php';
    60 								require_once( ABSPATH . 'wp-admin/admin-header.php' );
    64 								require_once( ABSPATH . 'wp-admin/admin-header.php' );
    61 								echo '<div class="wrap">';
    65 								echo '<div class="wrap">';
    62 								confirm_delete_users( $_POST['allusers'] );
    66 								confirm_delete_users( $_POST['allusers'] );
    63 								echo '</div>';
    67 								echo '</div>';
    64 								require_once( ABSPATH . 'wp-admin/admin-footer.php' );
    68 								require_once( ABSPATH . 'wp-admin/admin-footer.php' );
    65 								exit();
    69 								exit();
    66 
    70 
    67 							case 'spam':
    71 							case 'spam':
    68 								$user = get_userdata( $user_id );
    72 								$user = get_userdata( $user_id );
    69 								if ( is_super_admin( $user->ID ) )
    73 								if ( is_super_admin( $user->ID ) ) {
    70 									wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), esc_html( $user->user_login ) ) );
    74 									wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), esc_html( $user->user_login ) ) );
       
    75 								}
    71 
    76 
    72 								$userfunction = 'all_spam';
    77 								$userfunction = 'all_spam';
    73 								$blogs = get_blogs_of_user( $user_id, true );
    78 								$blogs        = get_blogs_of_user( $user_id, true );
    74 								foreach ( (array) $blogs as $details ) {
    79 								foreach ( (array) $blogs as $details ) {
    75 									if ( $details->userblog_id != get_network()->site_id ) // main blog not a spam !
    80 									if ( $details->userblog_id != get_network()->site_id ) { // main blog not a spam !
    76 										update_blog_status( $details->userblog_id, 'spam', '1' );
    81 										update_blog_status( $details->userblog_id, 'spam', '1' );
       
    82 									}
    77 								}
    83 								}
    78 								update_user_status( $user_id, 'spam', '1' );
    84 								update_user_status( $user_id, 'spam', '1' );
    79 							break;
    85 								break;
    80 
    86 
    81 							case 'notspam':
    87 							case 'notspam':
    82 								$userfunction = 'all_notspam';
    88 								$userfunction = 'all_notspam';
    83 								$blogs = get_blogs_of_user( $user_id, true );
    89 								$blogs        = get_blogs_of_user( $user_id, true );
    84 								foreach ( (array) $blogs as $details )
    90 								foreach ( (array) $blogs as $details ) {
    85 									update_blog_status( $details->userblog_id, 'spam', '0' );
    91 									update_blog_status( $details->userblog_id, 'spam', '0' );
       
    92 								}
    86 
    93 
    87 								update_user_status( $user_id, 'spam', '0' );
    94 								update_user_status( $user_id, 'spam', '0' );
    88 							break;
    95 								break;
    89 						}
    96 						}
    90 					}
    97 					}
    91 				}
    98 				}
    92 
    99 
    93 				if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) {
   100 				if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) {
    99 
   106 
   100 					wp_safe_redirect( $sendback );
   107 					wp_safe_redirect( $sendback );
   101 					exit();
   108 					exit();
   102 				}
   109 				}
   103 
   110 
   104 				wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $userfunction ), wp_get_referer() ) );
   111 				wp_safe_redirect(
       
   112 					add_query_arg(
       
   113 						array(
       
   114 							'updated' => 'true',
       
   115 							'action'  => $userfunction,
       
   116 						),
       
   117 						wp_get_referer()
       
   118 					)
       
   119 				);
   105 			} else {
   120 			} else {
   106 				$location = network_admin_url( 'users.php' );
   121 				$location = network_admin_url( 'users.php' );
   107 
   122 
   108 				if ( ! empty( $_REQUEST['paged'] ) )
   123 				if ( ! empty( $_REQUEST['paged'] ) ) {
   109 					$location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
   124 					$location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
       
   125 				}
   110 				wp_redirect( $location );
   126 				wp_redirect( $location );
   111 			}
   127 			}
   112 			exit();
   128 			exit();
   113 
   129 
   114 		case 'dodelete':
   130 		case 'dodelete':
   115 			check_admin_referer( 'ms-users-delete' );
   131 			check_admin_referer( 'ms-users-delete' );
   116 			if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) )
   132 			if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) ) {
   117 				wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
   133 				wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
       
   134 			}
   118 
   135 
   119 			if ( ! empty( $_POST['blog'] ) && is_array( $_POST['blog'] ) ) {
   136 			if ( ! empty( $_POST['blog'] ) && is_array( $_POST['blog'] ) ) {
   120 				foreach ( $_POST['blog'] as $id => $users ) {
   137 				foreach ( $_POST['blog'] as $id => $users ) {
   121 					foreach ( $users as $blogid => $user_id ) {
   138 					foreach ( $users as $blogid => $user_id ) {
   122 						if ( ! current_user_can( 'delete_user', $id ) )
   139 						if ( ! current_user_can( 'delete_user', $id ) ) {
   123 							continue;
   140 							continue;
   124 
   141 						}
   125 						if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][$blogid][$id] )
   142 
       
   143 						if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][ $blogid ][ $id ] ) {
   126 							remove_user_from_blog( $id, $blogid, $user_id );
   144 							remove_user_from_blog( $id, $blogid, $user_id );
   127 						else
   145 						} else {
   128 							remove_user_from_blog( $id, $blogid );
   146 							remove_user_from_blog( $id, $blogid );
       
   147 						}
   129 					}
   148 					}
   130 				}
   149 				}
   131 			}
   150 			}
   132 			$i = 0;
   151 			$i = 0;
   133 			if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) )
   152 			if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) ) {
   134 				foreach ( $_POST['user'] as $id ) {
   153 				foreach ( $_POST['user'] as $id ) {
   135 					if ( ! current_user_can( 'delete_user', $id ) )
   154 					if ( ! current_user_can( 'delete_user', $id ) ) {
   136 						continue;
   155 						continue;
       
   156 					}
   137 					wpmu_delete_user( $id );
   157 					wpmu_delete_user( $id );
   138 					$i++;
   158 					$i++;
   139 				}
   159 				}
   140 
   160 			}
   141 			if ( $i == 1 )
   161 
       
   162 			if ( $i == 1 ) {
   142 				$deletefunction = 'delete';
   163 				$deletefunction = 'delete';
   143 			else
   164 			} else {
   144 				$deletefunction = 'all_delete';
   165 				$deletefunction = 'all_delete';
   145 
   166 			}
   146 			wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $deletefunction ), network_admin_url( 'users.php' ) ) );
   167 
       
   168 			wp_redirect(
       
   169 				add_query_arg(
       
   170 					array(
       
   171 						'updated' => 'true',
       
   172 						'action'  => $deletefunction,
       
   173 					),
       
   174 					network_admin_url( 'users.php' )
       
   175 				)
       
   176 			);
   147 			exit();
   177 			exit();
   148 	}
   178 	}
   149 }
   179 }
   150 
   180 
   151 $wp_list_table = _get_list_table('WP_MS_Users_List_Table');
   181 $wp_list_table = _get_list_table( 'WP_MS_Users_List_Table' );
   152 $pagenum = $wp_list_table->get_pagenum();
   182 $pagenum       = $wp_list_table->get_pagenum();
   153 $wp_list_table->prepare_items();
   183 $wp_list_table->prepare_items();
   154 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
   184 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
   155 
   185 
   156 if ( $pagenum > $total_pages && $total_pages > 0 ) {
   186 if ( $pagenum > $total_pages && $total_pages > 0 ) {
   157 	wp_redirect( add_query_arg( 'paged', $total_pages ) );
   187 	wp_redirect( add_query_arg( 'paged', $total_pages ) );
   158 	exit;
   188 	exit;
   159 }
   189 }
   160 $title = __( 'Users' );
   190 $title       = __( 'Users' );
   161 $parent_file = 'users.php';
   191 $parent_file = 'users.php';
   162 
   192 
   163 add_screen_option( 'per_page' );
   193 add_screen_option( 'per_page' );
   164 
   194 
   165 get_current_screen()->add_help_tab( array(
   195 get_current_screen()->add_help_tab(
   166 	'id'      => 'overview',
   196 	array(
   167 	'title'   => __('Overview'),
   197 		'id'      => 'overview',
   168 	'content' =>
   198 		'title'   => __( 'Overview' ),
   169 		'<p>' . __('This table shows all users across the network and the sites to which they are assigned.') . '</p>' .
   199 		'content' =>
   170 		'<p>' . __('Hover over any user on the list to make the edit links appear. The Edit link on the left will take you to their Edit User profile page; the Edit link on the right by any site name goes to an Edit Site screen for that site.') . '</p>' .
   200 			'<p>' . __( 'This table shows all users across the network and the sites to which they are assigned.' ) . '</p>' .
   171 		'<p>' . __('You can also go to the user&#8217;s profile page by clicking on the individual username.') . '</p>' .
   201 			'<p>' . __( 'Hover over any user on the list to make the edit links appear. The Edit link on the left will take you to their Edit User profile page; the Edit link on the right by any site name goes to an Edit Site screen for that site.' ) . '</p>' .
   172 		'<p>' . __( 'You can sort the table by clicking on any of the table headings and switch between list and excerpt views by using the icons above the users list.' ) . '</p>' .
   202 			'<p>' . __( 'You can also go to the user&#8217;s profile page by clicking on the individual username.' ) . '</p>' .
   173 		'<p>' . __('The bulk action will permanently delete selected users, or mark/unmark those selected as spam. Spam users will have posts removed and will be unable to sign up again with the same email addresses.') . '</p>' .
   203 			'<p>' . __( 'You can sort the table by clicking on any of the table headings and switch between list and excerpt views by using the icons above the users list.' ) . '</p>' .
   174 		'<p>' . __('You can make an existing user an additional super admin by going to the Edit User profile page and checking the box to grant that privilege.') . '</p>'
   204 			'<p>' . __( 'The bulk action will permanently delete selected users, or mark/unmark those selected as spam. Spam users will have posts removed and will be unable to sign up again with the same email addresses.' ) . '</p>' .
   175 ) );
   205 			'<p>' . __( 'You can make an existing user an additional super admin by going to the Edit User profile page and checking the box to grant that privilege.' ) . '</p>',
       
   206 	)
       
   207 );
   176 
   208 
   177 get_current_screen()->set_help_sidebar(
   209 get_current_screen()->set_help_sidebar(
   178 	'<p><strong>' . __('For more information:') . '</strong></p>' .
   210 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
   179 	'<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Users_Screen">Documentation on Network Users</a>') . '</p>' .
   211 	'<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Users_Screen">Documentation on Network Users</a>' ) . '</p>' .
   180 	'<p>' . __('<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>') . '</p>'
   212 	'<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>' ) . '</p>'
   181 );
   213 );
   182 
   214 
   183 get_current_screen()->set_screen_reader_content( array(
   215 get_current_screen()->set_screen_reader_content(
   184 	'heading_views'      => __( 'Filter users list' ),
   216 	array(
   185 	'heading_pagination' => __( 'Users list navigation' ),
   217 		'heading_views'      => __( 'Filter users list' ),
   186 	'heading_list'       => __( 'Users list' ),
   218 		'heading_pagination' => __( 'Users list navigation' ),
   187 ) );
   219 		'heading_list'       => __( 'Users list' ),
       
   220 	)
       
   221 );
   188 
   222 
   189 require_once( ABSPATH . 'wp-admin/admin-header.php' );
   223 require_once( ABSPATH . 'wp-admin/admin-header.php' );
   190 
   224 
   191 if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty( $_REQUEST['action'] ) ) {
   225 if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty( $_REQUEST['action'] ) ) {
   192 	?>
   226 	?>
   193 	<div id="message" class="updated notice is-dismissible"><p>
   227 	<div id="message" class="updated notice is-dismissible"><p>
   194 		<?php
   228 		<?php
   195 		switch ( $_REQUEST['action'] ) {
   229 		switch ( $_REQUEST['action'] ) {
   196 			case 'delete':
   230 			case 'delete':
   197 				_e( 'User deleted.' );
   231 				_e( 'User deleted.' );
   198 			break;
   232 				break;
   199 			case 'all_spam':
   233 			case 'all_spam':
   200 				_e( 'Users marked as spam.' );
   234 				_e( 'Users marked as spam.' );
   201 			break;
   235 				break;
   202 			case 'all_notspam':
   236 			case 'all_notspam':
   203 				_e( 'Users removed from spam.' );
   237 				_e( 'Users removed from spam.' );
   204 			break;
   238 				break;
   205 			case 'all_delete':
   239 			case 'all_delete':
   206 				_e( 'Users deleted.' );
   240 				_e( 'Users deleted.' );
   207 			break;
   241 				break;
   208 			case 'add':
   242 			case 'add':
   209 				_e( 'User added.' );
   243 				_e( 'User added.' );
   210 			break;
   244 				break;
   211 		}
   245 		}
   212 		?>
   246 		?>
   213 	</p></div>
   247 	</p></div>
   214 	<?php
   248 	<?php
   215 }
   249 }
   216 	?>
   250 ?>
   217 <div class="wrap">
   251 <div class="wrap">
   218 	<h1 class="wp-heading-inline"><?php esc_html_e( 'Users' ); ?></h1>
   252 	<h1 class="wp-heading-inline"><?php esc_html_e( 'Users' ); ?></h1>
   219 
   253 
   220 	<?php
   254 	<?php
   221 	if ( current_user_can( 'create_users') ) : ?>
   255 	if ( current_user_can( 'create_users' ) ) :
   222 		<a href="<?php echo network_admin_url('user-new.php'); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'user' ); ?></a><?php
   256 		?>
       
   257 		<a href="<?php echo network_admin_url( 'user-new.php' ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'user' ); ?></a>
       
   258 							<?php
   223 	endif;
   259 	endif;
   224 
   260 
   225 	if ( strlen( $usersearch ) ) {
   261 	if ( strlen( $usersearch ) ) {
   226 		/* translators: %s: search keywords */
   262 		/* translators: %s: search keywords */
   227 		printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $usersearch ) );
   263 		printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $usersearch ) );