Make WordPress Core

Changeset 56478


Ignore:
Timestamp:
08/27/2023 12:21:33 PM (13 months ago)
Author:
johnbillion
Message:

Users: Call add_user_meta() instead of update_user_meta() when adding metadata to a new user.

This improves the performance of inserting users as it removes one unnecessary SELECT query for every row of metadata inserted.

Props swissspidy, spacedmonkey, johnbillion

Fixes #59212

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/user.php

    r56477 r56478  
    24322432    $meta = array_merge( $meta, $custom_meta );
    24332433
    2434     // Update user meta.
    2435     foreach ( $meta as $key => $value ) {
    2436         update_user_meta( $user_id, $key, $value );
     2434    if ( $update ) {
     2435        // Update user meta.
     2436        foreach ( $meta as $key => $value ) {
     2437            update_user_meta( $user_id, $key, $value );
     2438        }
     2439    } else {
     2440        // Add user meta.
     2441        foreach ( $meta as $key => $value ) {
     2442            add_user_meta( $user_id, $key, $value );
     2443        }
    24372444    }
    24382445
Note: See TracChangeset for help on using the changeset viewer.