update_user_meta()更新一个用户的meta自定义附加信息

目录

描述

Update user meta field based on user ID.

Use the $prev_value parameter to differentiate between meta fields with the same key and user ID.

If the meta field for the user does not exist, it will be added.

update_user_meta() 描述

用法

<?php update_user_meta$user_id$meta_key$meta_value$prev_value ); ?>

update_user_meta() 用法

参数

$user_id

(integer) (必填) User ID.

默认值: None

$meta_key

(string) (必填) The meta_key in the wp_usermeta table for the meta_value to be updated.

默认值: None

$meta_value

(mixed) (必填) The new desired value of the meta_key, which must be different from the existing value. Arrays and objects will be automatically serialized. Note that using objects may cause this bug to popup.

默认值: None

$prev_value

(mixed) (可选) Previous value to check before removing.

默认值: ''

update_user_meta() 参数

返回值

(int/boolean

Meta ID if the key didn't exist; true on successful update; false on failure or if $meta_value is the same as the existing meta value in the database.

update_user_meta() 返回值

示例

Below is an example showing how to update a user's Website profile field

Below is an example showing how to check for errors:

update_user_meta() 示例

注意

Changes in behavior from the now deprecated update_usermeta:

  • update_user_meta does not delete the meta if the new value is empty.
  • The 动作s are different.

update_user_meta() 注意

历史

添加于 版本: 3.0.0

update_user_meta() 历史

源文件

update_user_meta() 函数的代码位于 wp-includes/user.php.

update_user_meta() 源文件

相关