From 0d1e4e553c7b0ec0bf57a02dc0e40b46e2d1ac1d Mon Sep 17 00:00:00 2001 From: desrosj Date: Mon, 24 May 2021 19:59:57 +0000 Subject: [PATCH] General: Avoid unnecessary calls to `update_user_option()`. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `update_user_option()` function is a way to update a user meta value after adding a blog’s prefix to the beginning of the meta key. But when the fourth parameter is `true`, the behavior is exactly the same as calling `update_user_meta()` directly. This replaces all instances of `update_user_option()` when the fourth parameter is `true` in Core with a direct call to `update_user_meta()` to prevent an unnecessary call to `update_user_option()`. Props johnjamesjacoby, zkancs, obenland, desrosj. Fixes #43339. Built from https://develop.svn.wordpress.org/trunk@50981 git-svn-id: http://core.svn.wordpress.org/trunk@50590 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/ajax-actions.php | 12 ++++++------ wp-admin/includes/nav-menu.php | 7 +++---- wp-admin/includes/upgrade.php | 2 +- wp-admin/includes/user.php | 4 ++-- wp-admin/my-sites.php | 2 +- wp-includes/script-loader.php | 2 +- wp-includes/user.php | 4 ++-- wp-includes/version.php | 2 +- 8 files changed, 17 insertions(+), 18 deletions(-) diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index 275cc4cea6..feb35ca40c 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -374,7 +374,7 @@ function wp_ajax_get_community_events() { * The location is stored network-wide, so that the user doesn't have to set it on each site. */ if ( $ip_changed || $search ) { - update_user_option( $user_id, 'community-events-location', $events['location'], true ); + update_user_meta( $user_id, 'community-events-location', $events['location'] ); } wp_send_json_success( $events ); @@ -1733,13 +1733,13 @@ function wp_ajax_closed_postboxes() { } if ( is_array( $closed ) ) { - update_user_option( $user->ID, "closedpostboxes_$page", $closed, true ); + update_user_meta( $user->ID, "closedpostboxes_$page", $closed ); } if ( is_array( $hidden ) ) { // Postboxes that are always shown. $hidden = array_diff( $hidden, array( 'submitdiv', 'linksubmitdiv', 'manage-menu', 'create-menu' ) ); - update_user_option( $user->ID, "metaboxhidden_$page", $hidden, true ); + update_user_meta( $user->ID, "metaboxhidden_$page", $hidden ); } wp_die( 1 ); @@ -1764,7 +1764,7 @@ function wp_ajax_hidden_columns() { } $hidden = ! empty( $_POST['hidden'] ) ? explode( ',', $_POST['hidden'] ) : array(); - update_user_option( $user->ID, "manage{$page}columnshidden", $hidden, true ); + update_user_meta( $user->ID, "manage{$page}columnshidden", $hidden ); wp_die( 1 ); } @@ -1919,11 +1919,11 @@ function wp_ajax_meta_box_order() { } if ( $order ) { - update_user_option( $user->ID, "meta-box-order_$page", $order, true ); + update_user_meta( $user->ID, "meta-box-order_$page", $order ); } if ( $page_columns ) { - update_user_option( $user->ID, "screen_layout_$page", $page_columns, true ); + update_user_meta( $user->ID, "screen_layout_$page", $page_columns ); } wp_send_json_success(); diff --git a/wp-admin/includes/nav-menu.php b/wp-admin/includes/nav-menu.php index 8e6d01f607..4475d08f96 100644 --- a/wp-admin/includes/nav-menu.php +++ b/wp-admin/includes/nav-menu.php @@ -154,7 +154,7 @@ function wp_nav_menu_setup() { // If first time editing, disable advanced items by default. if ( false === get_user_option( 'managenav-menuscolumnshidden' ) ) { $user = wp_get_current_user(); - update_user_option( + update_user_meta( $user->ID, 'managenav-menuscolumnshidden', array( @@ -163,8 +163,7 @@ function wp_nav_menu_setup() { 2 => 'xfn', 3 => 'description', 4 => 'title-attribute', - ), - true + ) ); } } @@ -199,7 +198,7 @@ function wp_initial_nav_menu_meta_boxes() { } $user = wp_get_current_user(); - update_user_option( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true ); + update_user_meta( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes ); } /** diff --git a/wp-admin/includes/upgrade.php b/wp-admin/includes/upgrade.php index 863454a8c2..c2769e5d4b 100644 --- a/wp-admin/includes/upgrade.php +++ b/wp-admin/includes/upgrade.php @@ -88,7 +88,7 @@ if ( ! function_exists( 'wp_install' ) ) : $user_password = wp_generate_password( 12, false ); $message = __( 'Note that password carefully! It is a random password that was generated just for you.' ); $user_id = wp_create_user( $user_name, $user_password, $user_email ); - update_user_option( $user_id, 'default_password_nag', true, true ); + update_user_meta( $user_id, 'default_password_nag', true ); $email_password = true; $user_created = true; } elseif ( ! $user_id ) { diff --git a/wp-admin/includes/user.php b/wp-admin/includes/user.php index fb11b044be..8d0a8efd9b 100644 --- a/wp-admin/includes/user.php +++ b/wp-admin/includes/user.php @@ -482,7 +482,7 @@ function default_password_nag_handler( $errors = false ) { || isset( $_GET['default_password_nag'] ) && '0' == $_GET['default_password_nag'] ) { delete_user_setting( 'default_password_nag' ); - update_user_option( $user_ID, 'default_password_nag', false, true ); + update_user_meta( $user_ID, 'default_password_nag', false ); } } @@ -503,7 +503,7 @@ function default_password_nag_edit_user( $user_ID, $old_data ) { // Remove the nag if the password has been changed. if ( $new_data->user_pass != $old_data->user_pass ) { delete_user_setting( 'default_password_nag' ); - update_user_option( $user_ID, 'default_password_nag', false, true ); + update_user_meta( $user_ID, 'default_password_nag', false ); } } diff --git a/wp-admin/my-sites.php b/wp-admin/my-sites.php index afbe798cdc..02b373d9a4 100644 --- a/wp-admin/my-sites.php +++ b/wp-admin/my-sites.php @@ -27,7 +27,7 @@ if ( 'updateblogsettings' === $action && isset( $_POST['primary_blog'] ) ) { $blog = get_site( (int) $_POST['primary_blog'] ); if ( $blog && isset( $blog->domain ) ) { - update_user_option( $current_user->ID, 'primary_blog', (int) $_POST['primary_blog'], true ); + update_user_meta( $current_user->ID, 'primary_blog', (int) $_POST['primary_blog'] ); $updated = true; } else { wp_die( __( 'The primary site you chose does not exist.' ) ); diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 6a288e813a..7630cf64e2 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -1789,7 +1789,7 @@ function wp_localize_community_events() { */ if ( $saved_ip_address && $current_ip_address && $current_ip_address !== $saved_ip_address ) { $saved_location['ip'] = $current_ip_address; - update_user_option( $user_id, 'community-events-location', $saved_location, true ); + update_user_meta( $user_id, 'community-events-location', $saved_location ); } $events_client = new WP_Community_Events( $user_id, $saved_location ); diff --git a/wp-includes/user.php b/wp-includes/user.php index 4de8b12b3c..4b1fa4b34f 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -2873,7 +2873,7 @@ function reset_password( $user, $new_pass ) { do_action( 'password_reset', $user, $new_pass ); wp_set_password( $new_pass, $user->ID ); - update_user_option( $user->ID, 'default_password_nag', false, true ); + update_user_meta( $user->ID, 'default_password_nag', false ); /** * Fires after the user's password is reset. @@ -2984,7 +2984,7 @@ function register_new_user( $user_login, $user_email ) { return $errors; } - update_user_option( $user_id, 'default_password_nag', true, true ); // Set up the password change nag. + update_user_meta( $user_id, 'default_password_nag', true ); // Set up the password change nag. /** * Fires after a new user registration has been recorded. diff --git a/wp-includes/version.php b/wp-includes/version.php index bbea3a2d58..fde321ee0b 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.8-alpha-50980'; +$wp_version = '5.8-alpha-50981'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.