wp/wp-admin/includes/ms.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    18 function check_upload_size( $file ) {
    18 function check_upload_size( $file ) {
    19 	if ( get_site_option( 'upload_space_check_disabled' ) ) {
    19 	if ( get_site_option( 'upload_space_check_disabled' ) ) {
    20 		return $file;
    20 		return $file;
    21 	}
    21 	}
    22 
    22 
    23 	if ( $file['error'] != '0' ) { // there's already an error
    23 	if ( '0' != $file['error'] ) { // There's already an error.
    24 		return $file;
    24 		return $file;
    25 	}
    25 	}
    26 
    26 
    27 	if ( defined( 'WP_IMPORTING' ) ) {
    27 	if ( defined( 'WP_IMPORTING' ) ) {
    28 		return $file;
    28 		return $file;
    30 
    30 
    31 	$space_left = get_upload_space_available();
    31 	$space_left = get_upload_space_available();
    32 
    32 
    33 	$file_size = filesize( $file['tmp_name'] );
    33 	$file_size = filesize( $file['tmp_name'] );
    34 	if ( $space_left < $file_size ) {
    34 	if ( $space_left < $file_size ) {
    35 		/* translators: %s: required disk space in kilobytes */
    35 		/* translators: %s: Required disk space in kilobytes. */
    36 		$file['error'] = sprintf( __( 'Not enough space to upload. %s KB needed.' ), number_format( ( $file_size - $space_left ) / KB_IN_BYTES ) );
    36 		$file['error'] = sprintf( __( 'Not enough space to upload. %s KB needed.' ), number_format( ( $file_size - $space_left ) / KB_IN_BYTES ) );
    37 	}
    37 	}
    38 
    38 
    39 	if ( $file_size > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) {
    39 	if ( $file_size > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) {
    40 		/* translators: %s: maximum allowed file size in kilobytes */
    40 		/* translators: %s: Maximum allowed file size in kilobytes. */
    41 		$file['error'] = sprintf( __( 'This file is too big. Files must be less than %s KB in size.' ), get_site_option( 'fileupload_maxk', 1500 ) );
    41 		$file['error'] = sprintf( __( 'This file is too big. Files must be less than %s KB in size.' ), get_site_option( 'fileupload_maxk', 1500 ) );
    42 	}
    42 	}
    43 
    43 
    44 	if ( upload_is_user_over_quota( false ) ) {
    44 	if ( upload_is_user_over_quota( false ) ) {
    45 		$file['error'] = __( 'You have used your space quota. Please delete files before uploading.' );
    45 		$file['error'] = __( 'You have used your space quota. Please delete files before uploading.' );
    46 	}
    46 	}
    47 
    47 
    48 	if ( $file['error'] != '0' && ! isset( $_POST['html-upload'] ) && ! wp_doing_ajax() ) {
    48 	if ( '0' != $file['error'] && ! isset( $_POST['html-upload'] ) && ! wp_doing_ajax() ) {
    49 		wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' );
    49 		wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' );
    50 	}
    50 	}
    51 
    51 
    52 	return $file;
    52 	return $file;
    53 }
    53 }
    59  * @since 5.1.0 Use wp_delete_site() internally to delete the site row from the database.
    59  * @since 5.1.0 Use wp_delete_site() internally to delete the site row from the database.
    60  *
    60  *
    61  * @global wpdb $wpdb WordPress database abstraction object.
    61  * @global wpdb $wpdb WordPress database abstraction object.
    62  *
    62  *
    63  * @param int  $blog_id Site ID.
    63  * @param int  $blog_id Site ID.
    64  * @param bool $drop    True if site's database tables should be dropped. Default is false.
    64  * @param bool $drop    True if site's database tables should be dropped. Default false.
    65  */
    65  */
    66 function wpmu_delete_blog( $blog_id, $drop = false ) {
    66 function wpmu_delete_blog( $blog_id, $drop = false ) {
    67 	global $wpdb;
    67 	global $wpdb;
    68 
    68 
    69 	$switch = false;
    69 	$switch = false;
   127 /**
   127 /**
   128  * Delete a user from the network and remove from all sites.
   128  * Delete a user from the network and remove from all sites.
   129  *
   129  *
   130  * @since 3.0.0
   130  * @since 3.0.0
   131  *
   131  *
   132  * @todo Merge with wp_delete_user() ?
   132  * @todo Merge with wp_delete_user()?
   133  *
   133  *
   134  * @global wpdb $wpdb WordPress database abstraction object.
   134  * @global wpdb $wpdb WordPress database abstraction object.
   135  *
   135  *
   136  * @param int $id The user ID.
   136  * @param int $id The user ID.
   137  * @return bool True if the user was deleted, otherwise false.
   137  * @return bool True if the user was deleted, otherwise false.
   158 
   158 
   159 	/**
   159 	/**
   160 	 * Fires before a user is deleted from the network.
   160 	 * Fires before a user is deleted from the network.
   161 	 *
   161 	 *
   162 	 * @since MU (3.0.0)
   162 	 * @since MU (3.0.0)
   163 	 *
   163 	 * @since 5.5.0 Added the `$user` parameter.
   164 	 * @param int $id ID of the user about to be deleted from the network.
   164 	 *
       
   165 	 * @param int     $id   ID of the user about to be deleted from the network.
       
   166 	 * @param WP_User $user WP_User object of the user about to be deleted from the network.
   165 	 */
   167 	 */
   166 	do_action( 'wpmu_delete_user', $id );
   168 	do_action( 'wpmu_delete_user', $id, $user );
   167 
   169 
   168 	$blogs = get_blogs_of_user( $id );
   170 	$blogs = get_blogs_of_user( $id );
   169 
   171 
   170 	if ( ! empty( $blogs ) ) {
   172 	if ( ! empty( $blogs ) ) {
   171 		foreach ( $blogs as $blog ) {
   173 		foreach ( $blogs as $blog ) {
   175 			$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) );
   177 			$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) );
   176 			foreach ( (array) $post_ids as $post_id ) {
   178 			foreach ( (array) $post_ids as $post_id ) {
   177 				wp_delete_post( $post_id );
   179 				wp_delete_post( $post_id );
   178 			}
   180 			}
   179 
   181 
   180 			// Clean links
   182 			// Clean links.
   181 			$link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );
   183 			$link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );
   182 
   184 
   183 			if ( $link_ids ) {
   185 			if ( $link_ids ) {
   184 				foreach ( $link_ids as $link_id ) {
   186 				foreach ( $link_ids as $link_id ) {
   185 					wp_delete_link( $link_id );
   187 					wp_delete_link( $link_id );
   198 	$wpdb->delete( $wpdb->users, array( 'ID' => $id ) );
   200 	$wpdb->delete( $wpdb->users, array( 'ID' => $id ) );
   199 
   201 
   200 	clean_user_cache( $user );
   202 	clean_user_cache( $user );
   201 
   203 
   202 	/** This action is documented in wp-admin/includes/user.php */
   204 	/** This action is documented in wp-admin/includes/user.php */
   203 	do_action( 'deleted_user', $id, null );
   205 	do_action( 'deleted_user', $id, null, $user );
   204 
   206 
   205 	return true;
   207 	return true;
   206 }
   208 }
   207 
   209 
   208 /**
   210 /**
   218 		return false;
   220 		return false;
   219 	}
   221 	}
   220 
   222 
   221 	$space_allowed = get_space_allowed();
   223 	$space_allowed = get_space_allowed();
   222 	if ( ! is_numeric( $space_allowed ) ) {
   224 	if ( ! is_numeric( $space_allowed ) ) {
   223 		$space_allowed = 10; // Default space allowed is 10 MB
   225 		$space_allowed = 10; // Default space allowed is 10 MB.
   224 	}
   226 	}
   225 	$space_used = get_space_used();
   227 	$space_used = get_space_used();
   226 
   228 
   227 	if ( ( $space_allowed - $space_used ) < 0 ) {
   229 	if ( ( $space_allowed - $space_used ) < 0 ) {
   228 		if ( $echo ) {
   230 		if ( $echo ) {
   229 			printf(
   231 			printf(
   230 				/* translators: %s: allowed space allocation */
   232 				/* translators: %s: Allowed space allocation. */
   231 				__( 'Sorry, you have used your space allocation of %s. Please delete some files to upload more files.' ),
   233 				__( 'Sorry, you have used your space allocation of %s. Please delete some files to upload more files.' ),
   232 				size_format( $space_allowed * MB_IN_BYTES )
   234 				size_format( $space_allowed * MB_IN_BYTES )
   233 			);
   235 			);
   234 		}
   236 		}
   235 		return true;
   237 		return true;
   247 	$space_allowed = get_space_allowed();
   249 	$space_allowed = get_space_allowed();
   248 	$space_used    = get_space_used();
   250 	$space_used    = get_space_used();
   249 
   251 
   250 	$percent_used = ( $space_used / $space_allowed ) * 100;
   252 	$percent_used = ( $space_used / $space_allowed ) * 100;
   251 
   253 
   252 	if ( $space_allowed > 1000 ) {
   254 	$space = size_format( $space_allowed * MB_IN_BYTES );
   253 		$space = number_format( $space_allowed / KB_IN_BYTES );
       
   254 		/* translators: Gigabytes */
       
   255 		$space .= __( 'GB' );
       
   256 	} else {
       
   257 		$space = number_format( $space_allowed );
       
   258 		/* translators: Megabytes */
       
   259 		$space .= __( 'MB' );
       
   260 	}
       
   261 	?>
   255 	?>
   262 	<strong>
   256 	<strong>
   263 	<?php
   257 	<?php
   264 		/* translators: Storage space that's been used. 1: Percentage of used space, 2: Total space allowed in megabytes or gigabytes */
   258 		/* translators: Storage space that's been used. 1: Percentage of used space, 2: Total space allowed in megabytes or gigabytes. */
   265 		printf( __( 'Used: %1$s%% of %2$s' ), number_format( $percent_used ), $space );
   259 		printf( __( 'Used: %1$s%% of %2$s' ), number_format( $percent_used ), $space );
   266 	?>
   260 	?>
   267 	</strong>
   261 	</strong>
   268 	<?php
   262 	<?php
   269 }
   263 }
   310 	</tr>
   304 	</tr>
   311 	<?php
   305 	<?php
   312 }
   306 }
   313 
   307 
   314 /**
   308 /**
   315  * Update the status of a user in the database.
       
   316  *
       
   317  * Used in core to mark a user as spam or "ham" (not spam) in Multisite.
       
   318  *
       
   319  * @since 3.0.0
       
   320  *
       
   321  * @global wpdb $wpdb WordPress database abstraction object.
       
   322  *
       
   323  * @param int    $id         The user ID.
       
   324  * @param string $pref       The column in the wp_users table to update the user's status
       
   325  *                           in (presumably user_status, spam, or deleted).
       
   326  * @param int    $value      The new status for the user.
       
   327  * @param null   $deprecated Deprecated as of 3.0.2 and should not be used.
       
   328  * @return int   The initially passed $value.
       
   329  */
       
   330 function update_user_status( $id, $pref, $value, $deprecated = null ) {
       
   331 	global $wpdb;
       
   332 
       
   333 	if ( null !== $deprecated ) {
       
   334 		_deprecated_argument( __FUNCTION__, '3.0.2' );
       
   335 	}
       
   336 
       
   337 	$wpdb->update( $wpdb->users, array( sanitize_key( $pref ) => $value ), array( 'ID' => $id ) );
       
   338 
       
   339 	$user = new WP_User( $id );
       
   340 	clean_user_cache( $user );
       
   341 
       
   342 	if ( $pref == 'spam' ) {
       
   343 		if ( $value == 1 ) {
       
   344 			/**
       
   345 			 * Fires after the user is marked as a SPAM user.
       
   346 			 *
       
   347 			 * @since 3.0.0
       
   348 			 *
       
   349 			 * @param int $id ID of the user marked as SPAM.
       
   350 			 */
       
   351 			do_action( 'make_spam_user', $id );
       
   352 		} else {
       
   353 			/**
       
   354 			 * Fires after the user is marked as a HAM user. Opposite of SPAM.
       
   355 			 *
       
   356 			 * @since 3.0.0
       
   357 			 *
       
   358 			 * @param int $id ID of the user marked as HAM.
       
   359 			 */
       
   360 			do_action( 'make_ham_user', $id );
       
   361 		}
       
   362 	}
       
   363 
       
   364 	return $value;
       
   365 }
       
   366 
       
   367 /**
       
   368  * Cleans the user cache for a specific user.
   309  * Cleans the user cache for a specific user.
   369  *
   310  *
   370  * @since 3.0.0
   311  * @since 3.0.0
   371  *
   312  *
   372  * @param int $id The user ID.
   313  * @param int $id The user ID.
   373  * @return bool|int The ID of the refreshed user or false if the user does not exist.
   314  * @return bool|int The ID of the refreshed user or false if the user does not exist.
   374  */
   315  */
   375 function refresh_user_details( $id ) {
   316 function refresh_user_details( $id ) {
   376 	$id = (int) $id;
   317 	$id = (int) $id;
   377 
   318 
   378 	if ( ! $user = get_userdata( $id ) ) {
   319 	$user = get_userdata( $id );
       
   320 	if ( ! $user ) {
   379 		return false;
   321 		return false;
   380 	}
   322 	}
   381 
   323 
   382 	clean_user_cache( $user );
   324 	clean_user_cache( $user );
   383 
   325 
   606  *                                will be returned untouched.
   548  *                                will be returned untouched.
   607  * @return WP_Term|array Returns `$term`, after filtering the 'slug' field with `sanitize_title()`
   549  * @return WP_Term|array Returns `$term`, after filtering the 'slug' field with `sanitize_title()`
   608  *                       if `$taxonomy` is 'category' or 'post_tag'.
   550  *                       if `$taxonomy` is 'category' or 'post_tag'.
   609  */
   551  */
   610 function sync_category_tag_slugs( $term, $taxonomy ) {
   552 function sync_category_tag_slugs( $term, $taxonomy ) {
   611 	if ( global_terms_enabled() && ( $taxonomy == 'category' || $taxonomy == 'post_tag' ) ) {
   553 	if ( global_terms_enabled() && ( 'category' === $taxonomy || 'post_tag' === $taxonomy ) ) {
   612 		if ( is_object( $term ) ) {
   554 		if ( is_object( $term ) ) {
   613 			$term->slug = sanitize_title( $term->name );
   555 			$term->slug = sanitize_title( $term->name );
   614 		} else {
   556 		} else {
   615 			$term['slug'] = sanitize_title( $term['name'] );
   557 			$term['slug'] = sanitize_title( $term['name'] );
   616 		}
   558 		}
   637 	}
   579 	}
   638 
   580 
   639 	$blog_name = get_bloginfo( 'name' );
   581 	$blog_name = get_bloginfo( 'name' );
   640 
   582 
   641 	if ( empty( $blogs ) ) {
   583 	if ( empty( $blogs ) ) {
   642 		wp_die( sprintf( __( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ), $blog_name ), 403 );
   584 		wp_die(
   643 	}
   585 			sprintf(
   644 
   586 				/* translators: 1: Site title. */
   645 	$output  = '<p>' . sprintf( __( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ), $blog_name ) . '</p>';
   587 				__( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ),
       
   588 				$blog_name
       
   589 			),
       
   590 			403
       
   591 		);
       
   592 	}
       
   593 
       
   594 	$output = '<p>' . sprintf(
       
   595 		/* translators: 1: Site title. */
       
   596 		__( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ),
       
   597 		$blog_name
       
   598 	) . '</p>';
   646 	$output .= '<p>' . __( 'If you reached this screen by accident and meant to visit one of your own sites, here are some shortcuts to help you find your way.' ) . '</p>';
   599 	$output .= '<p>' . __( 'If you reached this screen by accident and meant to visit one of your own sites, here are some shortcuts to help you find your way.' ) . '</p>';
   647 
   600 
   648 	$output .= '<h3>' . __( 'Your Sites' ) . '</h3>';
   601 	$output .= '<h3>' . __( 'Your Sites' ) . '</h3>';
   649 	$output .= '<table>';
   602 	$output .= '<table>';
   650 
   603 
   691 	$output = array();
   644 	$output = array();
   692 
   645 
   693 	foreach ( (array) $lang_files as $val ) {
   646 	foreach ( (array) $lang_files as $val ) {
   694 		$code_lang = basename( $val, '.mo' );
   647 		$code_lang = basename( $val, '.mo' );
   695 
   648 
   696 		if ( $code_lang == 'en_US' ) { // American English
   649 		if ( 'en_US' === $code_lang ) { // American English.
   697 			$flag          = true;
   650 			$flag          = true;
   698 			$ae            = __( 'American English' );
   651 			$ae            = __( 'American English' );
   699 			$output[ $ae ] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $ae . '</option>';
   652 			$output[ $ae ] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $ae . '</option>';
   700 		} elseif ( $code_lang == 'en_GB' ) { // British English
   653 		} elseif ( 'en_GB' === $code_lang ) { // British English.
   701 			$flag          = true;
   654 			$flag          = true;
   702 			$be            = __( 'British English' );
   655 			$be            = __( 'British English' );
   703 			$output[ $be ] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $be . '</option>';
   656 			$output[ $be ] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $be . '</option>';
   704 		} else {
   657 		} else {
   705 			$translated            = format_code_lang( $code_lang );
   658 			$translated            = format_code_lang( $code_lang );
   706 			$output[ $translated ] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . esc_html( $translated ) . '</option>';
   659 			$output[ $translated ] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . esc_html( $translated ) . '</option>';
   707 		}
   660 		}
   708 	}
   661 	}
   709 
   662 
   710 	if ( $flag === false ) { // WordPress english
   663 	if ( false === $flag ) { // WordPress English.
   711 		$output[] = '<option value=""' . selected( $current, '', false ) . '>' . __( 'English' ) . '</option>';
   664 		$output[] = '<option value=""' . selected( $current, '', false ) . '>' . __( 'English' ) . '</option>';
   712 	}
   665 	}
   713 
   666 
   714 	// Order by name
   667 	// Order by name.
   715 	uksort( $output, 'strnatcasecmp' );
   668 	uksort( $output, 'strnatcasecmp' );
   716 
   669 
   717 	/**
   670 	/**
   718 	 * Filters the languages available in the dropdown.
   671 	 * Filters the languages available in the dropdown.
   719 	 *
   672 	 *
   731 /**
   684 /**
   732  * Displays an admin notice to upgrade all sites after a core upgrade.
   685  * Displays an admin notice to upgrade all sites after a core upgrade.
   733  *
   686  *
   734  * @since 3.0.0
   687  * @since 3.0.0
   735  *
   688  *
   736  * @global int    $wp_db_version The version number of the database.
   689  * @global int    $wp_db_version WordPress database version.
   737  * @global string $pagenow
   690  * @global string $pagenow
   738  *
   691  *
   739  * @return false False if the current user is not a super admin.
   692  * @return false False if the current user is not a super admin.
   740  */
   693  */
   741 function site_admin_notice() {
   694 function site_admin_notice() {
   743 
   696 
   744 	if ( ! current_user_can( 'upgrade_network' ) ) {
   697 	if ( ! current_user_can( 'upgrade_network' ) ) {
   745 		return false;
   698 		return false;
   746 	}
   699 	}
   747 
   700 
   748 	if ( 'upgrade.php' == $pagenow ) {
   701 	if ( 'upgrade.php' === $pagenow ) {
   749 		return;
   702 		return;
   750 	}
   703 	}
   751 
   704 
   752 	if ( get_site_option( 'wpmu_upgrade_site' ) != $wp_db_version ) {
   705 	if ( get_site_option( 'wpmu_upgrade_site' ) != $wp_db_version ) {
   753 		echo "<div class='update-nag'>" . sprintf( __( 'Thank you for Updating! Please visit the <a href="%s">Upgrade Network</a> page to update all your sites.' ), esc_url( network_admin_url( 'upgrade.php' ) ) ) . '</div>';
   706 		echo "<div class='update-nag notice notice-warning inline'>" . sprintf(
       
   707 			/* translators: %s: URL to Upgrade Network screen. */
       
   708 			__( 'Thank you for Updating! Please visit the <a href="%s">Upgrade Network</a> page to update all your sites.' ),
       
   709 			esc_url( network_admin_url( 'upgrade.php' ) )
       
   710 		) . '</div>';
   754 	}
   711 	}
   755 }
   712 }
   756 
   713 
   757 /**
   714 /**
   758  * Avoids a collision between a site slug and a permalink slug.
   715  * Avoids a collision between a site slug and a permalink slug.
   768  */
   725  */
   769 function avoid_blog_page_permalink_collision( $data, $postarr ) {
   726 function avoid_blog_page_permalink_collision( $data, $postarr ) {
   770 	if ( is_subdomain_install() ) {
   727 	if ( is_subdomain_install() ) {
   771 		return $data;
   728 		return $data;
   772 	}
   729 	}
   773 	if ( $data['post_type'] != 'page' ) {
   730 	if ( 'page' !== $data['post_type'] ) {
   774 		return $data;
   731 		return $data;
   775 	}
   732 	}
   776 	if ( ! isset( $data['post_name'] ) || $data['post_name'] == '' ) {
   733 	if ( ! isset( $data['post_name'] ) || '' === $data['post_name'] ) {
   777 		return $data;
   734 		return $data;
   778 	}
   735 	}
   779 	if ( ! is_main_site() ) {
   736 	if ( ! is_main_site() ) {
   780 		return $data;
   737 		return $data;
   781 	}
   738 	}
   802  */
   759  */
   803 function choose_primary_blog() {
   760 function choose_primary_blog() {
   804 	?>
   761 	?>
   805 	<table class="form-table" role="presentation">
   762 	<table class="form-table" role="presentation">
   806 	<tr>
   763 	<tr>
   807 	<?php /* translators: My sites label */ ?>
   764 	<?php /* translators: My Sites label. */ ?>
   808 		<th scope="row"><label for="primary_blog"><?php _e( 'Primary Site' ); ?></label></th>
   765 		<th scope="row"><label for="primary_blog"><?php _e( 'Primary Site' ); ?></label></th>
   809 		<td>
   766 		<td>
   810 		<?php
   767 		<?php
   811 		$all_blogs    = get_blogs_of_user( get_current_user_id() );
   768 		$all_blogs    = get_blogs_of_user( get_current_user_id() );
   812 		$primary_blog = get_user_meta( get_current_user_id(), 'primary_blog', true );
   769 		$primary_blog = get_user_meta( get_current_user_id(), 'primary_blog', true );
   856  *
   813  *
   857  * @param int $network_id The network ID to check.
   814  * @param int $network_id The network ID to check.
   858  * @return bool True if network can be edited, otherwise false.
   815  * @return bool True if network can be edited, otherwise false.
   859  */
   816  */
   860 function can_edit_network( $network_id ) {
   817 function can_edit_network( $network_id ) {
   861 	if ( $network_id == get_current_network_id() ) {
   818 	if ( get_current_network_id() == $network_id ) {
   862 		$result = true;
   819 		$result = true;
   863 	} else {
   820 	} else {
   864 		$result = false;
   821 		$result = false;
   865 	}
   822 	}
   866 
   823 
   899 		return false;
   856 		return false;
   900 	}
   857 	}
   901 	?>
   858 	?>
   902 	<h1><?php esc_html_e( 'Users' ); ?></h1>
   859 	<h1><?php esc_html_e( 'Users' ); ?></h1>
   903 
   860 
   904 	<?php if ( 1 == count( $users ) ) : ?>
   861 	<?php if ( 1 === count( $users ) ) : ?>
   905 		<p><?php _e( 'You have chosen to delete the user from all networks and sites.' ); ?></p>
   862 		<p><?php _e( 'You have chosen to delete the user from all networks and sites.' ); ?></p>
   906 	<?php else : ?>
   863 	<?php else : ?>
   907 		<p><?php _e( 'You have chosen to delete the following users from all networks and sites.' ); ?></p>
   864 		<p><?php _e( 'You have chosen to delete the following users from all networks and sites.' ); ?></p>
   908 	<?php endif; ?>
   865 	<?php endif; ?>
   909 
   866 
   914 	$site_admins = get_super_admins();
   871 	$site_admins = get_super_admins();
   915 	$admin_out   = '<option value="' . esc_attr( $current_user->ID ) . '">' . $current_user->user_login . '</option>';
   872 	$admin_out   = '<option value="' . esc_attr( $current_user->ID ) . '">' . $current_user->user_login . '</option>';
   916 	?>
   873 	?>
   917 	<table class="form-table" role="presentation">
   874 	<table class="form-table" role="presentation">
   918 	<?php
   875 	<?php
   919 	foreach ( ( $allusers = (array) $_POST['allusers'] ) as $user_id ) {
   876 	$allusers = (array) $_POST['allusers'];
   920 		if ( $user_id != '' && $user_id != '0' ) {
   877 	foreach ( $allusers as $user_id ) {
       
   878 		if ( '' !== $user_id && '0' != $user_id ) {
   921 			$delete_user = get_userdata( $user_id );
   879 			$delete_user = get_userdata( $user_id );
   922 
   880 
   923 			if ( ! current_user_can( 'delete_user', $delete_user->ID ) ) {
   881 			if ( ! current_user_can( 'delete_user', $delete_user->ID ) ) {
   924 				wp_die( sprintf( __( 'Warning! User %s cannot be deleted.' ), $delete_user->user_login ) );
   882 				wp_die(
       
   883 					sprintf(
       
   884 						/* translators: %s: User login. */
       
   885 						__( 'Warning! User %s cannot be deleted.' ),
       
   886 						$delete_user->user_login
       
   887 					)
       
   888 				);
   925 			}
   889 			}
   926 
   890 
   927 			if ( in_array( $delete_user->user_login, $site_admins ) ) {
   891 			if ( in_array( $delete_user->user_login, $site_admins, true ) ) {
   928 				wp_die( sprintf( __( 'Warning! User cannot be deleted. The user %s is a network administrator.' ), '<em>' . $delete_user->user_login . '</em>' ) );
   892 				wp_die(
       
   893 					sprintf(
       
   894 						/* translators: %s: User login. */
       
   895 						__( 'Warning! User cannot be deleted. The user %s is a network administrator.' ),
       
   896 						'<em>' . $delete_user->user_login . '</em>'
       
   897 					)
       
   898 				);
   929 			}
   899 			}
   930 			?>
   900 			?>
   931 			<tr>
   901 			<tr>
   932 				<th scope="row"><?php echo $delete_user->user_login; ?>
   902 				<th scope="row"><?php echo $delete_user->user_login; ?>
   933 					<?php echo '<input type="hidden" name="user[]" value="' . esc_attr( $user_id ) . '" />' . "\n"; ?>
   903 					<?php echo '<input type="hidden" name="user[]" value="' . esc_attr( $user_id ) . '" />' . "\n"; ?>
   938 			if ( ! empty( $blogs ) ) {
   908 			if ( ! empty( $blogs ) ) {
   939 				?>
   909 				?>
   940 				<td><fieldset><p><legend>
   910 				<td><fieldset><p><legend>
   941 				<?php
   911 				<?php
   942 				printf(
   912 				printf(
   943 					/* translators: user login */
   913 					/* translators: %s: User login. */
   944 					__( 'What should be done with content owned by %s?' ),
   914 					__( 'What should be done with content owned by %s?' ),
   945 					'<em>' . $delete_user->user_login . '</em>'
   915 					'<em>' . $delete_user->user_login . '</em>'
   946 				);
   916 				);
   947 				?>
   917 				?>
   948 				</legend></p>
   918 				</legend></p>
   952 						array(
   922 						array(
   953 							'blog_id' => $details->userblog_id,
   923 							'blog_id' => $details->userblog_id,
   954 							'fields'  => array( 'ID', 'user_login' ),
   924 							'fields'  => array( 'ID', 'user_login' ),
   955 						)
   925 						)
   956 					);
   926 					);
       
   927 
   957 					if ( is_array( $blog_users ) && ! empty( $blog_users ) ) {
   928 					if ( is_array( $blog_users ) && ! empty( $blog_users ) ) {
   958 						$user_site      = "<a href='" . esc_url( get_home_url( $details->userblog_id ) ) . "'>{$details->blogname}</a>";
   929 						$user_site      = "<a href='" . esc_url( get_home_url( $details->userblog_id ) ) . "'>{$details->blogname}</a>";
   959 						$user_dropdown  = '<label for="reassign_user" class="screen-reader-text">' . __( 'Select a user' ) . '</label>';
   930 						$user_dropdown  = '<label for="reassign_user" class="screen-reader-text">' . __( 'Select a user' ) . '</label>';
   960 						$user_dropdown .= "<select name='blog[$user_id][$key]' id='reassign_user'>";
   931 						$user_dropdown .= "<select name='blog[$user_id][$key]' id='reassign_user'>";
   961 						$user_list      = '';
   932 						$user_list      = '';
       
   933 
   962 						foreach ( $blog_users as $user ) {
   934 						foreach ( $blog_users as $user ) {
   963 							if ( ! in_array( $user->ID, $allusers ) ) {
   935 							if ( ! in_array( (int) $user->ID, $allusers, true ) ) {
   964 								$user_list .= "<option value='{$user->ID}'>{$user->user_login}</option>";
   936 								$user_list .= "<option value='{$user->ID}'>{$user->user_login}</option>";
   965 							}
   937 							}
   966 						}
   938 						}
   967 						if ( '' == $user_list ) {
   939 
       
   940 						if ( '' === $user_list ) {
   968 							$user_list = $admin_out;
   941 							$user_list = $admin_out;
   969 						}
   942 						}
       
   943 
   970 						$user_dropdown .= $user_list;
   944 						$user_dropdown .= $user_list;
   971 						$user_dropdown .= "</select>\n";
   945 						$user_dropdown .= "</select>\n";
   972 						?>
   946 						?>
   973 						<ul style="list-style:none;">
   947 						<ul style="list-style:none;">
   974 							<li><?php printf( __( 'Site: %s' ), $user_site ); ?></li>
   948 							<li>
       
   949 								<?php
       
   950 								/* translators: %s: Link to user's site. */
       
   951 								printf( __( 'Site: %s' ), $user_site );
       
   952 								?>
       
   953 							</li>
   975 							<li><label><input type="radio" id="delete_option0" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID; ?>]" value="delete" checked="checked" />
   954 							<li><label><input type="radio" id="delete_option0" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID; ?>]" value="delete" checked="checked" />
   976 							<?php _e( 'Delete all content.' ); ?></label></li>
   955 							<?php _e( 'Delete all content.' ); ?></label></li>
   977 							<li><label><input type="radio" id="delete_option1" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID; ?>]" value="reassign" />
   956 							<li><label><input type="radio" id="delete_option1" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID; ?>]" value="reassign" />
   978 							<?php _e( 'Attribute all content to:' ); ?></label>
   957 							<?php _e( 'Attribute all content to:' ); ?></label>
   979 							<?php echo $user_dropdown; ?></li>
   958 							<?php echo $user_dropdown; ?></li>
   995 	</table>
   974 	</table>
   996 	<?php
   975 	<?php
   997 	/** This action is documented in wp-admin/users.php */
   976 	/** This action is documented in wp-admin/users.php */
   998 	do_action( 'delete_user_form', $current_user, $allusers );
   977 	do_action( 'delete_user_form', $current_user, $allusers );
   999 
   978 
  1000 	if ( 1 == count( $users ) ) :
   979 	if ( 1 === count( $users ) ) :
  1001 		?>
   980 		?>
  1002 		<p><?php _e( 'Once you hit &#8220;Confirm Deletion&#8221;, the user will be permanently removed.' ); ?></p>
   981 		<p><?php _e( 'Once you hit &#8220;Confirm Deletion&#8221;, the user will be permanently removed.' ); ?></p>
  1003 	<?php else : ?>
   982 	<?php else : ?>
  1004 		<p><?php _e( 'Once you hit &#8220;Confirm Deletion&#8221;, these users will be permanently removed.' ); ?></p>
   983 		<p><?php _e( 'Once you hit &#8220;Confirm Deletion&#8221;, these users will be permanently removed.' ); ?></p>
  1005 		<?php
   984 		<?php
  1037 /**
  1016 /**
  1038  * Outputs the HTML for a network's "Edit Site" tabular interface.
  1017  * Outputs the HTML for a network's "Edit Site" tabular interface.
  1039  *
  1018  *
  1040  * @since 4.6.0
  1019  * @since 4.6.0
  1041  *
  1020  *
  1042  * @param $args {
  1021  * @param array $args {
  1043  *     Optional. Array or string of Query parameters. Default empty array.
  1022  *     Optional. Array or string of Query parameters. Default empty array.
  1044  *
  1023  *
  1045  *     @type int    $blog_id  The site ID. Default is the current site.
  1024  *     @type int    $blog_id  The site ID. Default is the current site.
  1046  *     @type array  $links    The tabs to include with (label|url|cap) keys.
  1025  *     @type array  $links    The tabs to include with (label|url|cap) keys.
  1047  *     @type string $selected The ID of the selected link.
  1026  *     @type string $selected The ID of the selected link.
  1092 				'cap'   => 'manage_sites',
  1071 				'cap'   => 'manage_sites',
  1093 			),
  1072 			),
  1094 		)
  1073 		)
  1095 	);
  1074 	);
  1096 
  1075 
  1097 	// Parse arguments
  1076 	// Parse arguments.
  1098 	$r = wp_parse_args(
  1077 	$parsed_args = wp_parse_args(
  1099 		$args,
  1078 		$args,
  1100 		array(
  1079 		array(
  1101 			'blog_id'  => isset( $_GET['blog_id'] ) ? (int) $_GET['blog_id'] : 0,
  1080 			'blog_id'  => isset( $_GET['blog_id'] ) ? (int) $_GET['blog_id'] : 0,
  1102 			'links'    => $links,
  1081 			'links'    => $links,
  1103 			'selected' => 'site-info',
  1082 			'selected' => 'site-info',
  1104 		)
  1083 		)
  1105 	);
  1084 	);
  1106 
  1085 
  1107 	// Setup the links array
  1086 	// Setup the links array.
  1108 	$screen_links = array();
  1087 	$screen_links = array();
  1109 
  1088 
  1110 	// Loop through tabs
  1089 	// Loop through tabs.
  1111 	foreach ( $r['links'] as $link_id => $link ) {
  1090 	foreach ( $parsed_args['links'] as $link_id => $link ) {
  1112 
  1091 
  1113 		// Skip link if user can't access
  1092 		// Skip link if user can't access.
  1114 		if ( ! current_user_can( $link['cap'], $r['blog_id'] ) ) {
  1093 		if ( ! current_user_can( $link['cap'], $parsed_args['blog_id'] ) ) {
  1115 			continue;
  1094 			continue;
  1116 		}
  1095 		}
  1117 
  1096 
  1118 		// Link classes
  1097 		// Link classes.
  1119 		$classes = array( 'nav-tab' );
  1098 		$classes = array( 'nav-tab' );
  1120 
  1099 
  1121 		// Aria-current attribute.
  1100 		// Aria-current attribute.
  1122 		$aria_current = '';
  1101 		$aria_current = '';
  1123 
  1102 
  1124 		// Selected is set by the parent OR assumed by the $pagenow global
  1103 		// Selected is set by the parent OR assumed by the $pagenow global.
  1125 		if ( $r['selected'] === $link_id || $link['url'] === $GLOBALS['pagenow'] ) {
  1104 		if ( $parsed_args['selected'] === $link_id || $link['url'] === $GLOBALS['pagenow'] ) {
  1126 			$classes[]    = 'nav-tab-active';
  1105 			$classes[]    = 'nav-tab-active';
  1127 			$aria_current = ' aria-current="page"';
  1106 			$aria_current = ' aria-current="page"';
  1128 		}
  1107 		}
  1129 
  1108 
  1130 		// Escape each class
  1109 		// Escape each class.
  1131 		$esc_classes = implode( ' ', $classes );
  1110 		$esc_classes = implode( ' ', $classes );
  1132 
  1111 
  1133 		// Get the URL for this link
  1112 		// Get the URL for this link.
  1134 		$url = add_query_arg( array( 'id' => $r['blog_id'] ), network_admin_url( $link['url'] ) );
  1113 		$url = add_query_arg( array( 'id' => $parsed_args['blog_id'] ), network_admin_url( $link['url'] ) );
  1135 
  1114 
  1136 		// Add link to nav links
  1115 		// Add link to nav links.
  1137 		$screen_links[ $link_id ] = '<a href="' . esc_url( $url ) . '" id="' . esc_attr( $link_id ) . '" class="' . $esc_classes . '"' . $aria_current . '>' . esc_html( $link['label'] ) . '</a>';
  1116 		$screen_links[ $link_id ] = '<a href="' . esc_url( $url ) . '" id="' . esc_attr( $link_id ) . '" class="' . $esc_classes . '"' . $aria_current . '>' . esc_html( $link['label'] ) . '</a>';
  1138 	}
  1117 	}
  1139 
  1118 
  1140 	// All done!
  1119 	// All done!
  1141 	echo '<nav class="nav-tab-wrapper wp-clearfix" aria-label="' . esc_attr__( 'Secondary menu' ) . '">';
  1120 	echo '<nav class="nav-tab-wrapper wp-clearfix" aria-label="' . esc_attr__( 'Secondary menu' ) . '">';
  1156 		'title'   => __( 'Overview' ),
  1135 		'title'   => __( 'Overview' ),
  1157 		'content' =>
  1136 		'content' =>
  1158 			'<p>' . __( 'The menu is for editing information specific to individual sites, particularly if the admin area of a site is unavailable.' ) . '</p>' .
  1137 			'<p>' . __( 'The menu is for editing information specific to individual sites, particularly if the admin area of a site is unavailable.' ) . '</p>' .
  1159 			'<p>' . __( '<strong>Info</strong> &mdash; The site URL is rarely edited as this can cause the site to not work properly. The Registered date and Last Updated date are displayed. Network admins can mark a site as archived, spam, deleted and mature, to remove from public listings or disable.' ) . '</p>' .
  1138 			'<p>' . __( '<strong>Info</strong> &mdash; The site URL is rarely edited as this can cause the site to not work properly. The Registered date and Last Updated date are displayed. Network admins can mark a site as archived, spam, deleted and mature, to remove from public listings or disable.' ) . '</p>' .
  1160 			'<p>' . __( '<strong>Users</strong> &mdash; This displays the users associated with this site. You can also change their role, reset their password, or remove them from the site. Removing the user from the site does not remove the user from the network.' ) . '</p>' .
  1139 			'<p>' . __( '<strong>Users</strong> &mdash; This displays the users associated with this site. You can also change their role, reset their password, or remove them from the site. Removing the user from the site does not remove the user from the network.' ) . '</p>' .
  1161 			'<p>' . sprintf( __( '<strong>Themes</strong> &mdash; This area shows themes that are not already enabled across the network. Enabling a theme in this menu makes it accessible to this site. It does not activate the theme, but allows it to show in the site&#8217;s Appearance menu. To enable a theme for the entire network, see the <a href="%s">Network Themes</a> screen.' ), network_admin_url( 'themes.php' ) ) . '</p>' .
  1140 			'<p>' . sprintf(
       
  1141 				/* translators: %s: URL to Network Themes screen. */
       
  1142 				__( '<strong>Themes</strong> &mdash; This area shows themes that are not already enabled across the network. Enabling a theme in this menu makes it accessible to this site. It does not activate the theme, but allows it to show in the site&#8217;s Appearance menu. To enable a theme for the entire network, see the <a href="%s">Network Themes</a> screen.' ),
       
  1143 				network_admin_url( 'themes.php' )
       
  1144 			) . '</p>' .
  1162 			'<p>' . __( '<strong>Settings</strong> &mdash; This page shows a list of all settings associated with this site. Some are created by WordPress and others are created by plugins you activate. Note that some fields are grayed out and say Serialized Data. You cannot modify these values due to the way the setting is stored in the database.' ) . '</p>',
  1145 			'<p>' . __( '<strong>Settings</strong> &mdash; This page shows a list of all settings associated with this site. Some are created by WordPress and others are created by plugins you activate. Note that some fields are grayed out and say Serialized Data. You cannot modify these values due to the way the setting is stored in the database.' ) . '</p>',
  1163 	);
  1146 	);
  1164 }
  1147 }
  1165 
  1148 
  1166 /**
  1149 /**
  1170  *
  1153  *
  1171  * @return string Help sidebar content.
  1154  * @return string Help sidebar content.
  1172  */
  1155  */
  1173 function get_site_screen_help_sidebar_content() {
  1156 function get_site_screen_help_sidebar_content() {
  1174 	return '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  1157 	return '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  1175 		'<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Sites_Screen">Documentation on Site Management</a>' ) . '</p>' .
  1158 		'<p>' . __( '<a href="https://wordpress.org/support/article/network-admin-sites-screen/">Documentation on Site Management</a>' ) . '</p>' .
  1176 		'<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>' ) . '</p>';
  1159 		'<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>' ) . '</p>';
  1177 }
  1160 }