add_user_meta
Add meta data field to a user.
Description
(int|false) add_user_meta( (int) $user_id, (string) $meta_key, (mixed) $meta_value, (constant) $unique = false );
Post meta data is called Custom Fields on the Administration Screens.
Returns (int|false)
Meta ID on success, false on failure.
Parameters (4)
- 0. $user_id (int)
- The user id.
- 1. $meta_key (string)
- Metadata name.
- 2. $meta_value (mixed)
- The meta value.
- 3. $unique — Optional. (constant) =>
false
- Optional, default is false. Whether the same key should not be added.
Usage
if ( !function_exists( 'add_user_meta' ) ) { require_once ABSPATH . WPINC . '/user.php'; } // The user id. $user_id = -1; // Metadata name. $meta_key = ''; // The meta value. $meta_value = null; // Optional, default is false. Whether the same key should not be added. $unique = false; // NOTICE! Understand what this does before running. $result = add_user_meta($user_id, $meta_key, $meta_value, $unique);
Defined (1)
The function is defined in the following location(s).
- /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);
- }