add_user_meta() WordPress Function

The add_user_meta() function is used to add user meta data to a user. User meta data is a collection of data about a user that is not part of the user's core data. User meta data can be used to store a variety of information about a user, such as the user's preferences, contact information, and social media profiles.

add_user_meta( int $user_id, string $meta_key, mixed $meta_value, bool $unique = false ) #

Adds meta data to a user.


Parameters

$user_id

(int)(Required)User ID.

$meta_key

(string)(Required)Metadata name.

$meta_value

(mixed)(Required)Metadata value. Must be serializable if non-scalar.

$unique

(bool)(Optional) Whether the same key should not be added.

Default value: false


Top ↑

Return

(int|false) Meta ID on success, false on failure.


Top ↑

Source

File: wp-includes/user.php

function add_user_meta( $user_id, $meta_key, $meta_value, $unique = false ) {
	return add_metadata( 'user', $user_id, $meta_key, $meta_value, $unique );
}


Top ↑

Changelog

Changelog
VersionDescription
3.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More