From 786ac48c84602287937716c5830b933d2c4053cd Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 24 May 2020 09:17:09 +0000 Subject: [PATCH] Coding Standards: Use strict comparison in `wp-admin/network` where static strings are involved. Includes minor code layout fixes for better readability. Follow-up to [47808]. See #49542. Built from https://develop.svn.wordpress.org/trunk@47853 git-svn-id: http://core.svn.wordpress.org/trunk@47629 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/network/plugin-install.php | 2 +- wp-admin/network/settings.php | 17 ++++++++++++++--- wp-admin/network/site-info.php | 4 ++-- wp-admin/network/site-new.php | 5 +++-- wp-admin/network/site-settings.php | 11 ++++++++--- wp-admin/network/site-themes.php | 8 ++++---- wp-admin/network/site-users.php | 7 +++++-- wp-admin/network/sites.php | 5 +++++ wp-admin/network/theme-install.php | 2 +- wp-admin/network/user-new.php | 6 ++++-- wp-admin/network/users.php | 10 ++++++---- wp-includes/version.php | 2 +- 12 files changed, 54 insertions(+), 25 deletions(-) diff --git a/wp-admin/network/plugin-install.php b/wp-admin/network/plugin-install.php index f34ed8346d..86aba63363 100644 --- a/wp-admin/network/plugin-install.php +++ b/wp-admin/network/plugin-install.php @@ -7,7 +7,7 @@ * @since 3.1.0 */ -if ( isset( $_GET['tab'] ) && ( 'plugin-information' == $_GET['tab'] ) ) { +if ( isset( $_GET['tab'] ) && ( 'plugin-information' === $_GET['tab'] ) ) { define( 'IFRAME_REQUEST', true ); } diff --git a/wp-admin/network/settings.php b/wp-admin/network/settings.php index ed7bb5f5dc..f7bfdb524c 100644 --- a/wp-admin/network/settings.php +++ b/wp-admin/network/settings.php @@ -32,7 +32,7 @@ if ( ! empty( $_GET['network_admin_hash'] ) ) { } wp_redirect( network_admin_url( $redirect ) ); exit; -} elseif ( ! empty( $_GET['dismiss'] ) && 'new_network_admin_email' == $_GET['dismiss'] ) { +} elseif ( ! empty( $_GET['dismiss'] ) && 'new_network_admin_email' === $_GET['dismiss'] ) { check_admin_referer( 'dismiss_new_network_admin_email' ); delete_site_option( 'network_admin_hash' ); delete_site_option( 'new_admin_email' ); @@ -255,9 +255,13 @@ if ( isset( $_GET['updated'] ) ) { +

@@ -267,8 +271,15 @@ if ( isset( $_GET['updated'] ) ) { + +

diff --git a/wp-admin/network/site-info.php b/wp-admin/network/site-info.php index 7bba7da934..dddb0bb962 100644 --- a/wp-admin/network/site-info.php +++ b/wp-admin/network/site-info.php @@ -35,7 +35,7 @@ if ( ! can_edit_network( $details->site_id ) ) { $parsed_scheme = parse_url( $details->siteurl, PHP_URL_SCHEME ); $is_main_site = is_main_site( $id ); -if ( isset( $_REQUEST['action'] ) && 'update-site' == $_REQUEST['action'] ) { +if ( isset( $_REQUEST['action'] ) && 'update-site' === $_REQUEST['action'] ) { check_admin_referer( 'edit-site' ); switch_to_blog( $id ); @@ -117,7 +117,7 @@ if ( isset( $_REQUEST['action'] ) && 'update-site' == $_REQUEST['action'] ) { if ( isset( $_GET['update'] ) ) { $messages = array(); - if ( 'updated' == $_GET['update'] ) { + if ( 'updated' === $_GET['update'] ) { $messages[] = __( 'Site info updated.' ); } } diff --git a/wp-admin/network/site-new.php b/wp-admin/network/site-new.php index acb7feb90b..7e9716bf37 100644 --- a/wp-admin/network/site-new.php +++ b/wp-admin/network/site-new.php @@ -33,7 +33,7 @@ get_current_screen()->set_help_sidebar( '

' . __( 'Support Forums' ) . '

' ); -if ( isset( $_REQUEST['action'] ) && 'add-site' == $_REQUEST['action'] ) { +if ( isset( $_REQUEST['action'] ) && 'add-site' === $_REQUEST['action'] ) { check_admin_referer( 'add-blog', '_wpnonce_add-blog' ); if ( ! is_array( $_POST['blog'] ) ) { @@ -139,6 +139,7 @@ if ( isset( $_REQUEST['action'] ) && 'add-site' == $_REQUEST['action'] ) { $wpdb->hide_errors(); $id = wpmu_create_blog( $newdomain, $path, $title, $user_id, $meta, get_current_network_id() ); $wpdb->show_errors(); + if ( ! is_wp_error( $id ) ) { if ( ! is_super_admin( $user_id ) && ! get_user_option( 'primary_blog', $user_id ) ) { update_user_option( $user_id, 'primary_blog', $id, true ); @@ -187,7 +188,7 @@ Name: %3$s' if ( isset( $_GET['update'] ) ) { $messages = array(); - if ( 'added' == $_GET['update'] ) { + if ( 'added' === $_GET['update'] ) { $messages[] = sprintf( /* translators: 1: Dashboard URL, 2: Network admin edit URL. */ __( 'Site added. Visit Dashboard or Edit Site' ), diff --git a/wp-admin/network/site-settings.php b/wp-admin/network/site-settings.php index c77a05150b..44c417f0d9 100644 --- a/wp-admin/network/site-settings.php +++ b/wp-admin/network/site-settings.php @@ -34,7 +34,7 @@ if ( ! can_edit_network( $details->site_id ) ) { $is_main_site = is_main_site( $id ); -if ( isset( $_REQUEST['action'] ) && 'update-site' == $_REQUEST['action'] && is_array( $_POST['option'] ) ) { +if ( isset( $_REQUEST['action'] ) && 'update-site' === $_REQUEST['action'] && is_array( $_POST['option'] ) ) { check_admin_referer( 'edit-site' ); switch_to_blog( $id ); @@ -44,7 +44,7 @@ if ( isset( $_REQUEST['action'] ) && 'update-site' == $_REQUEST['action'] && is_ $key = wp_unslash( $key ); $val = wp_unslash( $val ); if ( 0 === $key || is_array( $val ) || in_array( $key, $skip_options, true ) ) { - continue; // Avoids "0 is a protected WP option and may not be modified" error when edit blog options. + continue; // Avoids "0 is a protected WP option and may not be modified" error when editing blog options. } update_option( $key, $val ); } @@ -74,7 +74,7 @@ if ( isset( $_REQUEST['action'] ) && 'update-site' == $_REQUEST['action'] && is_ if ( isset( $_GET['update'] ) ) { $messages = array(); - if ( 'updated' == $_GET['update'] ) { + if ( 'updated' === $_GET['update'] ) { $messages[] = __( 'Site options updated.' ); } } @@ -123,12 +123,15 @@ if ( ! empty( $messages ) ) { '%' . $wpdb->esc_like( 'user_roles' ) ); $options = $wpdb->get_results( $query ); + foreach ( $options as $option ) { if ( 'default_role' === $option->option_name ) { $editblog_default_role = $option->option_value; } + $disabled = false; $class = 'all-options'; + if ( is_serialized( $option->option_value ) ) { if ( is_serialized_string( $option->option_value ) ) { $option->option_value = esc_html( maybe_unserialize( $option->option_value ) ); @@ -138,6 +141,7 @@ if ( ! empty( $messages ) ) { $class = 'all-options disabled'; } } + if ( strpos( $option->option_value, "\n" ) !== false ) { ?> @@ -158,6 +162,7 @@ if ( ! empty( $messages ) ) {

' . sprintf( $message, number_format_i18n( $enabled ) ) . '

'; } elseif ( isset( $_GET['disabled'] ) ) { $disabled = absint( $_GET['disabled'] ); - if ( 1 == $disabled ) { + if ( 1 === $disabled ) { $message = __( 'Theme disabled.' ); } else { /* translators: %s: Number of themes. */ $message = _n( '%s theme disabled.', '%s themes disabled.', $disabled ); } echo '

' . sprintf( $message, number_format_i18n( $disabled ) ) . '

'; -} elseif ( isset( $_GET['error'] ) && 'none' == $_GET['error'] ) { +} elseif ( isset( $_GET['error'] ) && 'none' === $_GET['error'] ) { echo '

' . __( 'No theme selected.' ) . '

'; } ?> diff --git a/wp-admin/network/site-users.php b/wp-admin/network/site-users.php index cb00cab973..30a962e664 100644 --- a/wp-admin/network/site-users.php +++ b/wp-admin/network/site-users.php @@ -77,6 +77,7 @@ if ( $action ) { $update = 'err_add_fail'; } else { $update = 'newuser'; + /** * Fires after a user has been created via the network site-users.php page. * @@ -178,9 +179,11 @@ if ( $action ) { } check_admin_referer( 'bulk-users' ); $userids = $_REQUEST['users']; + /** This action is documented in wp-admin/network/site-themes.php */ $referer = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $referer, $action, $userids, $id ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores - $update = $action; + + $update = $action; break; } @@ -190,7 +193,7 @@ if ( $action ) { restore_current_blog(); -if ( isset( $_GET['action'] ) && 'update-site' == $_GET['action'] ) { +if ( isset( $_GET['action'] ) && 'update-site' === $_GET['action'] ) { wp_safe_redirect( $referer ); exit(); } diff --git a/wp-admin/network/sites.php b/wp-admin/network/sites.php index a82cdc9ffc..b8687b1413 100644 --- a/wp-admin/network/sites.php +++ b/wp-admin/network/sites.php @@ -223,11 +223,14 @@ if ( isset( $_GET['action'] ) ) { wp_die( __( 'Sorry, you are not allowed to change the current site.' ) ); } } + if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) { $redirect_to = wp_get_referer(); $blogs = (array) $_POST['allblogs']; + /** This action is documented in wp-admin/network/site-themes.php */ $redirect_to = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $redirect_to, $doaction, $blogs, $id ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores + wp_safe_redirect( $redirect_to ); exit(); } @@ -237,6 +240,7 @@ if ( isset( $_GET['action'] ) ) { array( '_wp_http_referer', '_wpnonce' ), add_query_arg( $_POST, network_admin_url( 'sites.php' ) ) ); + wp_redirect( $location ); exit; } @@ -270,6 +274,7 @@ if ( isset( $_GET['action'] ) ) { * @param string $id The ID of the site being deactivated. */ do_action( 'deactivate_blog', $id ); + update_blog_status( $id, 'deleted', '1' ); break; diff --git a/wp-admin/network/theme-install.php b/wp-admin/network/theme-install.php index 93695d5a8a..eff3539113 100644 --- a/wp-admin/network/theme-install.php +++ b/wp-admin/network/theme-install.php @@ -7,7 +7,7 @@ * @since 3.1.0 */ -if ( isset( $_GET['tab'] ) && ( 'theme-information' == $_GET['tab'] ) ) { +if ( isset( $_GET['tab'] ) && ( 'theme-information' === $_GET['tab'] ) ) { define( 'IFRAME_REQUEST', true ); } diff --git a/wp-admin/network/user-new.php b/wp-admin/network/user-new.php index 0af5a1169f..f23f1b248f 100644 --- a/wp-admin/network/user-new.php +++ b/wp-admin/network/user-new.php @@ -30,7 +30,7 @@ get_current_screen()->set_help_sidebar( '

' . __( 'Support Forums' ) . '

' ); -if ( isset( $_REQUEST['action'] ) && 'add-user' == $_REQUEST['action'] ) { +if ( isset( $_REQUEST['action'] ) && 'add-user' === $_REQUEST['action'] ) { check_admin_referer( 'add-user', '_wpnonce_add-user' ); if ( ! current_user_can( 'manage_network_users' ) ) { @@ -44,6 +44,7 @@ if ( isset( $_REQUEST['action'] ) && 'add-user' == $_REQUEST['action'] ) { $user = wp_unslash( $_POST['user'] ); $user_details = wpmu_validate_user_signup( $user['username'], $user['email'] ); + if ( is_wp_error( $user_details['errors'] ) && $user_details['errors']->has_errors() ) { $add_user_errors = $user_details['errors']; } else { @@ -61,6 +62,7 @@ if ( isset( $_REQUEST['action'] ) && 'add-user' == $_REQUEST['action'] ) { * @param int $user_id ID of the newly created user. */ do_action( 'network_user_new_created_user', $user_id ); + wp_redirect( add_query_arg( array( @@ -77,7 +79,7 @@ if ( isset( $_REQUEST['action'] ) && 'add-user' == $_REQUEST['action'] ) { if ( isset( $_GET['update'] ) ) { $messages = array(); - if ( 'added' == $_GET['update'] ) { + if ( 'added' === $_GET['update'] ) { $edit_link = ''; if ( isset( $_GET['user_id'] ) ) { $user_id_new = absint( $_GET['user_id'] ); diff --git a/wp-admin/network/users.php b/wp-admin/network/users.php index 263ae57709..ca21118b25 100644 --- a/wp-admin/network/users.php +++ b/wp-admin/network/users.php @@ -27,7 +27,7 @@ if ( isset( $_GET['action'] ) ) { check_admin_referer( 'deleteuser' ); $id = intval( $_GET['id'] ); - if ( '0' != $id && '1' != $id ) { + if ( $id > 1 ) { $_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle arrays. $title = __( 'Users' ); $parent_file = 'users.php'; @@ -116,8 +116,8 @@ if ( isset( $_GET['action'] ) ) { if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) { $sendback = wp_get_referer(); - $user_ids = (array) $_POST['allusers']; + /** This action is documented in wp-admin/network/site-themes.php */ $sendback = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $sendback, $doaction, $user_ids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores @@ -157,7 +157,7 @@ if ( isset( $_GET['action'] ) ) { continue; } - if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][ $blogid ][ $id ] ) { + if ( ! empty( $_POST['delete'] ) && 'reassign' === $_POST['delete'][ $blogid ][ $id ] ) { remove_user_from_blog( $id, $blogid, (int) $user_id ); } else { remove_user_from_blog( $id, $blogid ); @@ -165,7 +165,9 @@ if ( isset( $_GET['action'] ) ) { } } } + $i = 0; + if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) ) { foreach ( $_POST['user'] as $id ) { if ( ! current_user_can( 'delete_user', $id ) ) { @@ -176,7 +178,7 @@ if ( isset( $_GET['action'] ) ) { } } - if ( 1 == $i ) { + if ( 1 === $i ) { $deletefunction = 'delete'; } else { $deletefunction = 'all_delete'; diff --git a/wp-includes/version.php b/wp-includes/version.php index 96642bf424..caea19210c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.5-alpha-47852'; +$wp_version = '5.5-alpha-47853'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.