wp/wp-admin/includes/ms.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
--- a/wp/wp-admin/includes/ms.php	Wed Sep 21 18:19:35 2022 +0200
+++ b/wp/wp-admin/includes/ms.php	Tue Sep 27 16:37:53 2022 +0200
@@ -12,15 +12,15 @@
  *
  * @since 3.0.0
  *
- * @param array $file $_FILES array for a given file.
- * @return array $_FILES array with 'error' key set if file exceeds quota. 'error' is empty otherwise.
+ * @param array $file An element from the `$_FILES` array for a given file.
+ * @return array The `$_FILES` array element with 'error' key set if file exceeds quota. 'error' is empty otherwise.
  */
 function check_upload_size( $file ) {
 	if ( get_site_option( 'upload_space_check_disabled' ) ) {
 		return $file;
 	}
 
-	if ( '0' != $file['error'] ) { // There's already an error.
+	if ( $file['error'] > 0 ) { // There's already an error.
 		return $file;
 	}
 
@@ -45,7 +45,7 @@
 		$file['error'] = __( 'You have used your space quota. Please delete files before uploading.' );
 	}
 
-	if ( '0' != $file['error'] && ! isset( $_POST['html-upload'] ) && ! wp_doing_ajax() ) {
+	if ( $file['error'] > 0 && ! isset( $_POST['html-upload'] ) && ! wp_doing_ajax() ) {
 		wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' );
 	}
 
@@ -66,8 +66,10 @@
 function wpmu_delete_blog( $blog_id, $drop = false ) {
 	global $wpdb;
 
+	$blog_id = (int) $blog_id;
+
 	$switch = false;
-	if ( get_current_blog_id() != $blog_id ) {
+	if ( get_current_blog_id() !== $blog_id ) {
 		$switch = true;
 		switch_to_blog( $blog_id );
 	}
@@ -82,7 +84,10 @@
 	}
 
 	// Don't destroy the initial, main, or root blog.
-	if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_network->path && $blog->domain == $current_network->domain ) ) ) {
+	if ( $drop
+		&& ( 1 === $blog_id || is_main_site( $blog_id )
+			|| ( $blog->path === $current_network->path && $blog->domain === $current_network->domain ) )
+	) {
 		$drop = false;
 	}
 
@@ -212,10 +217,11 @@
  *
  * @since MU (3.0.0)
  *
- * @param bool $echo Optional. If $echo is set and the quota is exceeded, a warning message is echoed. Default is true.
+ * @param bool $display_message Optional. If set to true and the quota is exceeded,
+ *                              a warning message is displayed. Default true.
  * @return bool True if user is over upload space quota, otherwise false.
  */
-function upload_is_user_over_quota( $echo = true ) {
+function upload_is_user_over_quota( $display_message = true ) {
 	if ( get_site_option( 'upload_space_check_disabled' ) ) {
 		return false;
 	}
@@ -227,7 +233,7 @@
 	$space_used = get_space_used();
 
 	if ( ( $space_allowed - $space_used ) < 0 ) {
-		if ( $echo ) {
+		if ( $display_message ) {
 			printf(
 				/* translators: %s: Allowed space allocation. */
 				__( 'Sorry, you have used your space allocation of %s. Please delete some files to upload more files.' ),
@@ -687,7 +693,7 @@
  * @since 3.0.0
  *
  * @global int    $wp_db_version WordPress database version.
- * @global string $pagenow
+ * @global string $pagenow       The filename of the current screen.
  *
  * @return void|false Void on success. False if the current user is not a super admin.
  */
@@ -702,7 +708,7 @@
 		return;
 	}
 
-	if ( get_site_option( 'wpmu_upgrade_site' ) != $wp_db_version ) {
+	if ( (int) get_site_option( 'wpmu_upgrade_site' ) !== $wp_db_version ) {
 		echo "<div class='update-nag notice notice-warning inline'>" . sprintf(
 			/* translators: %s: URL to Upgrade Network screen. */
 			__( 'Thank you for Updating! Please visit the <a href="%s">Upgrade Network</a> page to update all your sites.' ),
@@ -736,16 +742,22 @@
 	if ( ! is_main_site() ) {
 		return $data;
 	}
+	if ( isset( $data['post_parent'] ) && $data['post_parent'] ) {
+		return $data;
+	}
 
 	$post_name = $data['post_name'];
 	$c         = 0;
+
 	while ( $c < 10 && get_id_from_blogname( $post_name ) ) {
 		$post_name .= mt_rand( 1, 10 );
-		$c ++;
+		$c++;
 	}
-	if ( $post_name != $data['post_name'] ) {
+
+	if ( $post_name !== $data['post_name'] ) {
 		$data['post_name'] = $post_name;
 	}
+
 	return $data;
 }
 
@@ -766,14 +778,14 @@
 		<td>
 		<?php
 		$all_blogs    = get_blogs_of_user( get_current_user_id() );
-		$primary_blog = get_user_meta( get_current_user_id(), 'primary_blog', true );
+		$primary_blog = (int) get_user_meta( get_current_user_id(), 'primary_blog', true );
 		if ( count( $all_blogs ) > 1 ) {
 			$found = false;
 			?>
 			<select name="primary_blog" id="primary_blog">
 				<?php
 				foreach ( (array) $all_blogs as $blog ) {
-					if ( $primary_blog == $blog->userblog_id ) {
+					if ( $blog->userblog_id === $primary_blog ) {
 						$found = true;
 					}
 					?>
@@ -787,10 +799,10 @@
 				$blog = reset( $all_blogs );
 				update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
 			}
-		} elseif ( count( $all_blogs ) == 1 ) {
+		} elseif ( 1 === count( $all_blogs ) ) {
 			$blog = reset( $all_blogs );
 			echo esc_url( get_home_url( $blog->userblog_id ) );
-			if ( $primary_blog != $blog->userblog_id ) { // Set the primary blog again if it's out of sync with blog list.
+			if ( $blog->userblog_id !== $primary_blog ) { // Set the primary blog again if it's out of sync with blog list.
 				update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
 			}
 		} else {
@@ -815,7 +827,7 @@
  * @return bool True if network can be edited, otherwise false.
  */
 function can_edit_network( $network_id ) {
-	if ( get_current_network_id() == $network_id ) {
+	if ( get_current_network_id() === (int) $network_id ) {
 		$result = true;
 	} else {
 		$result = false;
@@ -875,7 +887,7 @@
 	<?php
 	$allusers = (array) $_POST['allusers'];
 	foreach ( $allusers as $user_id ) {
-		if ( '' !== $user_id && '0' != $user_id ) {
+		if ( '' !== $user_id && '0' !== $user_id ) {
 			$delete_user = get_userdata( $user_id );
 
 			if ( ! current_user_can( 'delete_user', $delete_user->ID ) ) {
@@ -999,7 +1011,7 @@
 function network_settings_add_js() {
 	?>
 <script type="text/javascript">
-jQuery(document).ready( function($) {
+jQuery( function($) {
 	var languageSelect = $( '#WPLANG' );
 	$( 'form' ).on( 'submit', function() {
 		// Don't show a spinner for English and installed languages,
@@ -1008,7 +1020,7 @@
 			$( '#submit', this ).after( '<span class="spinner language-install-spinner is-active" />' );
 		}
 	});
-});
+} );
 </script>
 	<?php
 }
@@ -1018,7 +1030,7 @@
  *
  * @since 4.6.0
  *
- * @global string $pagenow
+ * @global string $pagenow The filename of the current screen.
  *
  * @param array $args {
  *     Optional. Array or string of Query parameters. Default empty array.