Updating user meta

One of two functions you’ll need; update_user_meta or add_user_meta – more often than not you’ll just need the former, but it’s worth noting the difference:

add_post_meta will only create an entry if the $unique parameter is false, or if there is no existing data for $meta_key. update_post_meta will add if no data exists yet, otherwise it will update, depending on if/what you specified for $prev_value.

Both functions take the same three initial parameters; a user ID, a meta key, and a value:

$current_user = wp_get_current_user();
$current_user->ID; // The current user ID
$current_user_id = get_current_user_id(); // Alternative for getting current user ID

// Update current user's first name
update_user_meta( $current_user_id, 'first_name', 'Jimbo' );

// Update a specific user's first name
update_user_meta( 4 /* User ID 4 */, 'first_name', 'Janey' );