wp/wp-admin/network/users.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
     6  * @subpackage Multisite
     6  * @subpackage Multisite
     7  * @since 3.0.0
     7  * @since 3.0.0
     8  */
     8  */
     9 
     9 
    10 /** Load WordPress Administration Bootstrap */
    10 /** Load WordPress Administration Bootstrap */
    11 require_once( dirname( __FILE__ ) . '/admin.php' );
    11 require_once __DIR__ . '/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 
    25 			}
    25 			}
    26 
    26 
    27 			check_admin_referer( 'deleteuser' );
    27 			check_admin_referer( 'deleteuser' );
    28 
    28 
    29 			$id = intval( $_GET['id'] );
    29 			$id = intval( $_GET['id'] );
    30 			if ( $id != '0' && $id != '1' ) {
    30 			if ( $id > 1 ) {
    31 				$_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle with arrays
    31 				$_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle arrays.
    32 				$title             = __( 'Users' );
    32 				$title             = __( 'Users' );
    33 				$parent_file       = 'users.php';
    33 				$parent_file       = 'users.php';
    34 				require_once( ABSPATH . 'wp-admin/admin-header.php' );
    34 				require_once ABSPATH . 'wp-admin/admin-header.php';
    35 				echo '<div class="wrap">';
    35 				echo '<div class="wrap">';
    36 				confirm_delete_users( $_POST['allusers'] );
    36 				confirm_delete_users( $_POST['allusers'] );
    37 				echo '</div>';
    37 				echo '</div>';
    38 				require_once( ABSPATH . 'wp-admin/admin-footer.php' );
    38 				require_once ABSPATH . 'wp-admin/admin-footer.php';
    39 			} else {
    39 			} else {
    40 				wp_redirect( network_admin_url( 'users.php' ) );
    40 				wp_redirect( network_admin_url( 'users.php' ) );
    41 			}
    41 			}
    42 			exit();
    42 			exit;
    43 
    43 
    44 		case 'allusers':
    44 		case 'allusers':
    45 			if ( ! current_user_can( 'manage_network_users' ) ) {
    45 			if ( ! current_user_can( 'manage_network_users' ) ) {
    46 				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 );
    47 			}
    47 			}
    48 
    48 
    49 			if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allusers'] ) ) {
    49 			if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allusers'] ) ) {
    50 				check_admin_referer( 'bulk-users-network' );
    50 				check_admin_referer( 'bulk-users-network' );
    51 
    51 
    52 				$doaction     = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
    52 				$doaction     = -1 != $_POST['action'] ? $_POST['action'] : $_POST['action2'];
    53 				$userfunction = '';
    53 				$userfunction = '';
    54 
    54 
    55 				foreach ( (array) $_POST['allusers'] as $user_id ) {
    55 				foreach ( (array) $_POST['allusers'] as $user_id ) {
    56 					if ( ! empty( $user_id ) ) {
    56 					if ( ! empty( $user_id ) ) {
    57 						switch ( $doaction ) {
    57 						switch ( $doaction ) {
    59 								if ( ! current_user_can( 'delete_users' ) ) {
    59 								if ( ! current_user_can( 'delete_users' ) ) {
    60 									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 );
    61 								}
    61 								}
    62 								$title       = __( 'Users' );
    62 								$title       = __( 'Users' );
    63 								$parent_file = 'users.php';
    63 								$parent_file = 'users.php';
    64 								require_once( ABSPATH . 'wp-admin/admin-header.php' );
    64 								require_once ABSPATH . 'wp-admin/admin-header.php';
    65 								echo '<div class="wrap">';
    65 								echo '<div class="wrap">';
    66 								confirm_delete_users( $_POST['allusers'] );
    66 								confirm_delete_users( $_POST['allusers'] );
    67 								echo '</div>';
    67 								echo '</div>';
    68 								require_once( ABSPATH . 'wp-admin/admin-footer.php' );
    68 								require_once ABSPATH . 'wp-admin/admin-footer.php';
    69 								exit();
    69 								exit;
    70 
    70 
    71 							case 'spam':
    71 							case 'spam':
    72 								$user = get_userdata( $user_id );
    72 								$user = get_userdata( $user_id );
    73 								if ( is_super_admin( $user->ID ) ) {
    73 								if ( is_super_admin( $user->ID ) ) {
    74 									wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), esc_html( $user->user_login ) ) );
    74 									wp_die(
       
    75 										sprintf(
       
    76 											/* translators: %s: User login. */
       
    77 											__( 'Warning! User cannot be modified. The user %s is a network administrator.' ),
       
    78 											esc_html( $user->user_login )
       
    79 										)
       
    80 									);
    75 								}
    81 								}
    76 
    82 
    77 								$userfunction = 'all_spam';
    83 								$userfunction = 'all_spam';
    78 								$blogs        = get_blogs_of_user( $user_id, true );
    84 								$blogs        = get_blogs_of_user( $user_id, true );
       
    85 
    79 								foreach ( (array) $blogs as $details ) {
    86 								foreach ( (array) $blogs as $details ) {
    80 									if ( $details->userblog_id != get_network()->site_id ) { // main blog not a spam !
    87 									if ( get_network()->site_id != $details->userblog_id ) { // Main blog is not a spam!
    81 										update_blog_status( $details->userblog_id, 'spam', '1' );
    88 										update_blog_status( $details->userblog_id, 'spam', '1' );
    82 									}
    89 									}
    83 								}
    90 								}
    84 								update_user_status( $user_id, 'spam', '1' );
    91 
       
    92 								$user_data         = $user->to_array();
       
    93 								$user_data['spam'] = '1';
       
    94 
       
    95 								wp_update_user( $user_data );
    85 								break;
    96 								break;
    86 
    97 
    87 							case 'notspam':
    98 							case 'notspam':
       
    99 								$user = get_userdata( $user_id );
       
   100 
    88 								$userfunction = 'all_notspam';
   101 								$userfunction = 'all_notspam';
    89 								$blogs        = get_blogs_of_user( $user_id, true );
   102 								$blogs        = get_blogs_of_user( $user_id, true );
       
   103 
    90 								foreach ( (array) $blogs as $details ) {
   104 								foreach ( (array) $blogs as $details ) {
    91 									update_blog_status( $details->userblog_id, 'spam', '0' );
   105 									update_blog_status( $details->userblog_id, 'spam', '0' );
    92 								}
   106 								}
    93 
   107 
    94 								update_user_status( $user_id, 'spam', '0' );
   108 								$user_data         = $user->to_array();
       
   109 								$user_data['spam'] = '0';
       
   110 
       
   111 								wp_update_user( $user_data );
    95 								break;
   112 								break;
    96 						}
   113 						}
    97 					}
   114 					}
    98 				}
   115 				}
    99 
   116 
   100 				if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) {
   117 				if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) {
   101 					$sendback = wp_get_referer();
   118 					$sendback = wp_get_referer();
   102 
       
   103 					$user_ids = (array) $_POST['allusers'];
   119 					$user_ids = (array) $_POST['allusers'];
       
   120 
   104 					/** This action is documented in wp-admin/network/site-themes.php */
   121 					/** This action is documented in wp-admin/network/site-themes.php */
   105 					$sendback = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $sendback, $doaction, $user_ids );
   122 					$sendback = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $sendback, $doaction, $user_ids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
   106 
   123 
   107 					wp_safe_redirect( $sendback );
   124 					wp_safe_redirect( $sendback );
   108 					exit();
   125 					exit;
   109 				}
   126 				}
   110 
   127 
   111 				wp_safe_redirect(
   128 				wp_safe_redirect(
   112 					add_query_arg(
   129 					add_query_arg(
   113 						array(
   130 						array(
   123 				if ( ! empty( $_REQUEST['paged'] ) ) {
   140 				if ( ! empty( $_REQUEST['paged'] ) ) {
   124 					$location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
   141 					$location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
   125 				}
   142 				}
   126 				wp_redirect( $location );
   143 				wp_redirect( $location );
   127 			}
   144 			}
   128 			exit();
   145 			exit;
   129 
   146 
   130 		case 'dodelete':
   147 		case 'dodelete':
   131 			check_admin_referer( 'ms-users-delete' );
   148 			check_admin_referer( 'ms-users-delete' );
   132 			if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) ) {
   149 			if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) ) {
   133 				wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
   150 				wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
   138 					foreach ( $users as $blogid => $user_id ) {
   155 					foreach ( $users as $blogid => $user_id ) {
   139 						if ( ! current_user_can( 'delete_user', $id ) ) {
   156 						if ( ! current_user_can( 'delete_user', $id ) ) {
   140 							continue;
   157 							continue;
   141 						}
   158 						}
   142 
   159 
   143 						if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][ $blogid ][ $id ] ) {
   160 						if ( ! empty( $_POST['delete'] ) && 'reassign' === $_POST['delete'][ $blogid ][ $id ] ) {
   144 							remove_user_from_blog( $id, $blogid, $user_id );
   161 							remove_user_from_blog( $id, $blogid, (int) $user_id );
   145 						} else {
   162 						} else {
   146 							remove_user_from_blog( $id, $blogid );
   163 							remove_user_from_blog( $id, $blogid );
   147 						}
   164 						}
   148 					}
   165 					}
   149 				}
   166 				}
   150 			}
   167 			}
       
   168 
   151 			$i = 0;
   169 			$i = 0;
       
   170 
   152 			if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) ) {
   171 			if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) ) {
   153 				foreach ( $_POST['user'] as $id ) {
   172 				foreach ( $_POST['user'] as $id ) {
   154 					if ( ! current_user_can( 'delete_user', $id ) ) {
   173 					if ( ! current_user_can( 'delete_user', $id ) ) {
   155 						continue;
   174 						continue;
   156 					}
   175 					}
   157 					wpmu_delete_user( $id );
   176 					wpmu_delete_user( $id );
   158 					$i++;
   177 					$i++;
   159 				}
   178 				}
   160 			}
   179 			}
   161 
   180 
   162 			if ( $i == 1 ) {
   181 			if ( 1 === $i ) {
   163 				$deletefunction = 'delete';
   182 				$deletefunction = 'delete';
   164 			} else {
   183 			} else {
   165 				$deletefunction = 'all_delete';
   184 				$deletefunction = 'all_delete';
   166 			}
   185 			}
   167 
   186 
   172 						'action'  => $deletefunction,
   191 						'action'  => $deletefunction,
   173 					),
   192 					),
   174 					network_admin_url( 'users.php' )
   193 					network_admin_url( 'users.php' )
   175 				)
   194 				)
   176 			);
   195 			);
   177 			exit();
   196 			exit;
   178 	}
   197 	}
   179 }
   198 }
   180 
   199 
   181 $wp_list_table = _get_list_table( 'WP_MS_Users_List_Table' );
   200 $wp_list_table = _get_list_table( 'WP_MS_Users_List_Table' );
   182 $pagenum       = $wp_list_table->get_pagenum();
   201 $pagenum       = $wp_list_table->get_pagenum();
   218 		'heading_pagination' => __( 'Users list navigation' ),
   237 		'heading_pagination' => __( 'Users list navigation' ),
   219 		'heading_list'       => __( 'Users list' ),
   238 		'heading_list'       => __( 'Users list' ),
   220 	)
   239 	)
   221 );
   240 );
   222 
   241 
   223 require_once( ABSPATH . 'wp-admin/admin-header.php' );
   242 require_once ABSPATH . 'wp-admin/admin-header.php';
   224 
   243 
   225 if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty( $_REQUEST['action'] ) ) {
   244 if ( isset( $_REQUEST['updated'] ) && 'true' == $_REQUEST['updated'] && ! empty( $_REQUEST['action'] ) ) {
   226 	?>
   245 	?>
   227 	<div id="message" class="updated notice is-dismissible"><p>
   246 	<div id="message" class="updated notice is-dismissible"><p>
   228 		<?php
   247 		<?php
   229 		switch ( $_REQUEST['action'] ) {
   248 		switch ( $_REQUEST['action'] ) {
   230 			case 'delete':
   249 			case 'delete':
   257 		<a href="<?php echo network_admin_url( 'user-new.php' ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'user' ); ?></a>
   276 		<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
   277 							<?php
   259 	endif;
   278 	endif;
   260 
   279 
   261 	if ( strlen( $usersearch ) ) {
   280 	if ( strlen( $usersearch ) ) {
   262 		/* translators: %s: search keywords */
   281 		/* translators: %s: Search query. */
   263 		printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $usersearch ) );
   282 		printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $usersearch ) );
   264 	}
   283 	}
   265 	?>
   284 	?>
   266 
   285 
   267 	<hr class="wp-header-end">
   286 	<hr class="wp-header-end">
   275 	<form id="form-user-list" action="users.php?action=allusers" method="post">
   294 	<form id="form-user-list" action="users.php?action=allusers" method="post">
   276 		<?php $wp_list_table->display(); ?>
   295 		<?php $wp_list_table->display(); ?>
   277 	</form>
   296 	</form>
   278 </div>
   297 </div>
   279 
   298 
   280 <?php require_once( ABSPATH . 'wp-admin/admin-footer.php' ); ?>
   299 <?php require_once ABSPATH . 'wp-admin/admin-footer.php'; ?>