| | 290 | * Add meta data field to a user. |
| | 291 | * |
| | 292 | * Post meta data is called "Custom Fields" on the Administration Panels. |
| | 293 | * |
| | 294 | * @since 2.9 |
| | 295 | * @uses add_metadata |
| | 296 | * @link http://codex.wordpress.org/Function_Reference/add_user_meta |
| | 297 | * |
| | 298 | * @param int $user_id Post ID. |
| | 299 | * @param string $key Metadata name. |
| | 300 | * @param mixed $value Metadata value. |
| | 301 | * @param bool $unique Optional, default is false. Whether the same key should not be added. |
| | 302 | * @return bool False for failure. True for success. |
| | 303 | */ |
| | 304 | function add_user_meta($user_id, $meta_key, $meta_value, $unique = false) { |
| | 305 | return add_metadata('user', $user_id, $meta_key, $meta_value, $unique); |
| | 306 | } |
| | 307 | |
| | 308 | /** |
| | 309 | * Remove metadata matching criteria from a user. |
| | 310 | * |
| | 311 | * You can match based on the key, or key and value. Removing based on key and |
| | 312 | * value, will keep from removing duplicate metadata with the same key. It also |
| | 313 | * allows removing all metadata matching key, if needed. |
| | 314 | * |
| | 315 | * @since 2.9 |
| | 316 | * @uses delete_metadata |
| | 317 | * @link http://codex.wordpress.org/Function_Reference/delete_user_meta |
| | 318 | * |
| | 319 | * @param int $user_id user ID |
| | 320 | * @param string $meta_key Metadata name. |
| | 321 | * @param mixed $meta_value Optional. Metadata value. |
| | 322 | * @return bool False for failure. True for success. |
| | 323 | */ |
| | 324 | function delete_user_meta($user_id, $meta_key, $meta_value = '') { |
| | 325 | return delete_metadata('user', $user_id, $meta_key, $meta_value); |
| | 326 | } |
| | 327 | |
| | 328 | /** |
| | 329 | * Retrieve user meta field for a user. |
| | 330 | * |
| | 331 | * @since 2.9 |
| | 332 | * @uses get_metadata |
| | 333 | * @link http://codex.wordpress.org/Function_Reference/get_user_meta |
| | 334 | * |
| | 335 | * @param int $user_id Post ID. |
| | 336 | * @param string $key The meta key to retrieve. |
| | 337 | * @param bool $single Whether to return a single value. |
| | 338 | * @return mixed Will be an array if $single is false. Will be value of meta data field if $single |
| | 339 | * is true. |
| | 340 | */ |
| | 341 | function get_user_meta($user_id, $key, $single = false) { |
| | 342 | return get_metadata('user', $user_id, $key, $single); |
| | 343 | } |
| | 344 | |
| | 345 | /** |
| | 346 | * Update user meta field based on user ID. |
| | 347 | * |
| | 348 | * Use the $prev_value parameter to differentiate between meta fields with the |
| | 349 | * same key and user ID. |
| | 350 | * |
| | 351 | * If the meta field for the user does not exist, it will be added. |
| | 352 | * |
| | 353 | * @since 2.9 |
| | 354 | * @uses update_metadata |
| | 355 | * @link http://codex.wordpress.org/Function_Reference/update_user_meta |
| | 356 | * |
| | 357 | * @param int $user_id Post ID. |
| | 358 | * @param string $key Metadata key. |
| | 359 | * @param mixed $value Metadata value. |
| | 360 | * @param mixed $prev_value Optional. Previous value to check before removing. |
| | 361 | * @return bool False on failure, true if success. |
| | 362 | */ |
| | 363 | function update_user_meta($user_id, $meta_key, $meta_value, $prev_value = '') { |
| | 364 | return update_metadata('user', $user_id, $meta_key, $meta_value, $prev_value); |
| | 365 | } |
| | 366 | |
| | 367 | |
| | 368 | /** |