General: Avoid unnecessary calls to `update_user_option()`.

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
This commit is contained in:
desrosj 2021-05-24 19:59:57 +00:00
parent 50c526f82b
commit 0d1e4e553c
8 changed files with 17 additions and 18 deletions

View File

@ -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. * The location is stored network-wide, so that the user doesn't have to set it on each site.
*/ */
if ( $ip_changed || $search ) { 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 ); wp_send_json_success( $events );
@ -1733,13 +1733,13 @@ function wp_ajax_closed_postboxes() {
} }
if ( is_array( $closed ) ) { 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 ) ) { if ( is_array( $hidden ) ) {
// Postboxes that are always shown. // Postboxes that are always shown.
$hidden = array_diff( $hidden, array( 'submitdiv', 'linksubmitdiv', 'manage-menu', 'create-menu' ) ); $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 ); wp_die( 1 );
@ -1764,7 +1764,7 @@ function wp_ajax_hidden_columns() {
} }
$hidden = ! empty( $_POST['hidden'] ) ? explode( ',', $_POST['hidden'] ) : array(); $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 ); wp_die( 1 );
} }
@ -1919,11 +1919,11 @@ function wp_ajax_meta_box_order() {
} }
if ( $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 ) { 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(); wp_send_json_success();

View File

@ -154,7 +154,7 @@ function wp_nav_menu_setup() {
// If first time editing, disable advanced items by default. // If first time editing, disable advanced items by default.
if ( false === get_user_option( 'managenav-menuscolumnshidden' ) ) { if ( false === get_user_option( 'managenav-menuscolumnshidden' ) ) {
$user = wp_get_current_user(); $user = wp_get_current_user();
update_user_option( update_user_meta(
$user->ID, $user->ID,
'managenav-menuscolumnshidden', 'managenav-menuscolumnshidden',
array( array(
@ -163,8 +163,7 @@ function wp_nav_menu_setup() {
2 => 'xfn', 2 => 'xfn',
3 => 'description', 3 => 'description',
4 => 'title-attribute', 4 => 'title-attribute',
), )
true
); );
} }
} }
@ -199,7 +198,7 @@ function wp_initial_nav_menu_meta_boxes() {
} }
$user = wp_get_current_user(); $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 );
} }
/** /**

View File

@ -88,7 +88,7 @@ if ( ! function_exists( 'wp_install' ) ) :
$user_password = wp_generate_password( 12, false ); $user_password = wp_generate_password( 12, false );
$message = __( '<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.' ); $message = __( '<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.' );
$user_id = wp_create_user( $user_name, $user_password, $user_email ); $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; $email_password = true;
$user_created = true; $user_created = true;
} elseif ( ! $user_id ) { } elseif ( ! $user_id ) {

View File

@ -482,7 +482,7 @@ function default_password_nag_handler( $errors = false ) {
|| isset( $_GET['default_password_nag'] ) && '0' == $_GET['default_password_nag'] || isset( $_GET['default_password_nag'] ) && '0' == $_GET['default_password_nag']
) { ) {
delete_user_setting( '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. // Remove the nag if the password has been changed.
if ( $new_data->user_pass != $old_data->user_pass ) { if ( $new_data->user_pass != $old_data->user_pass ) {
delete_user_setting( '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 );
} }
} }

View File

@ -27,7 +27,7 @@ if ( 'updateblogsettings' === $action && isset( $_POST['primary_blog'] ) ) {
$blog = get_site( (int) $_POST['primary_blog'] ); $blog = get_site( (int) $_POST['primary_blog'] );
if ( $blog && isset( $blog->domain ) ) { 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; $updated = true;
} else { } else {
wp_die( __( 'The primary site you chose does not exist.' ) ); wp_die( __( 'The primary site you chose does not exist.' ) );

View File

@ -1789,7 +1789,7 @@ function wp_localize_community_events() {
*/ */
if ( $saved_ip_address && $current_ip_address && $current_ip_address !== $saved_ip_address ) { if ( $saved_ip_address && $current_ip_address && $current_ip_address !== $saved_ip_address ) {
$saved_location['ip'] = $current_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 ); $events_client = new WP_Community_Events( $user_id, $saved_location );

View File

@ -2873,7 +2873,7 @@ function reset_password( $user, $new_pass ) {
do_action( 'password_reset', $user, $new_pass ); do_action( 'password_reset', $user, $new_pass );
wp_set_password( $new_pass, $user->ID ); 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. * Fires after the user's password is reset.
@ -2984,7 +2984,7 @@ function register_new_user( $user_login, $user_email ) {
return $errors; 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. * Fires after a new user registration has been recorded.

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @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. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.