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

  1. if ( !function_exists( 'add_user_meta' ) ) { 
  2. require_once ABSPATH . WPINC . '/user.php'; 
  3.  
  4. // The user id. 
  5. $user_id = -1; 
  6.  
  7. // Metadata name. 
  8. $meta_key = ''; 
  9.  
  10. // The meta value. 
  11. $meta_value = null; 
  12.  
  13. // Optional, default is false. Whether the same key should not be added. 
  14. $unique = false; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = add_user_meta($user_id, $meta_key, $meta_value, $unique); 
  18.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/user.php  
  1. function add_user_meta($user_id, $meta_key, $meta_value, $unique = false) { 
  2. return add_metadata('user', $user_id, $meta_key, $meta_value, $unique);