add_user_meta()添加一个用户的meta自定义附加信息

目录

描述

Add metadata to a user's record.

add_user_meta() 描述

用法

<?php add_user_meta$user_id$meta_key$meta_value$unique ); ?>

add_user_meta() 用法

参数

$user_id

(integer) (必填) user ID

默认值: None

$meta_key

(string) (必填) Metadata name.

默认值: None

$meta_value

(mixed) (必填) Metadata value.

默认值: None

$unique

(boolean) (可选) Whether the same key should not be added.

默认值: false

add_user_meta() 参数

返回值

(integer/boolean

Primary key id for success. False for failure.

add_user_meta() 返回值

示例

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

<?php
$user_id = 1;
$awesome_level = 1000;
add_user_meta( $user_id, '_level_of_awesomeness', $awesome_level);
?>

add_user_meta() 示例

注意

add_user_meta() 注意

历史

添加于 版本: 3.0.0

add_user_meta() 历史

源文件

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

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Add meta data field to a user.
 *
 * Post meta data is called "Custom Fields" on the Administration Screens.
 *
 * @since 3.0.0
 * @link https://codex.wordpress.org/Function_Reference/add_user_meta
 *
 * @param int    $user_id    User ID.
 * @param string $meta_key   Metadata name.
 * @param mixed  $meta_value Metadata value.
 * @param bool   $unique     Optional, default is false. Whether the same key should not be added.
 * @return int|false Meta ID on success, false on failure.
 */
function add_user_meta($user_id, $meta_key, $meta_value, $unique = false) {
	return add_metadata('user', $user_id, $meta_key, $meta_value, $unique);
}

add_user_meta() 源文件

相关