edit_user_profile_update
云策文档标注
概述
edit_user_profile_update 是一个 WordPress 动作钩子,在“编辑用户”页面加载前触发,主要用于保存添加到用户资料页的自定义字段。此钩子仅在用户查看其他用户(非自己)的资料页时触发。
关键要点
- 触发时机:在“编辑用户”页面加载前触发,适用于保存自定义字段。
- 参数:$user_id(整数类型),表示用户 ID。
- 适用范围:仅当用户查看其他用户的资料页时触发;如需应用于所有资料页(包括当前用户),应使用 personal_options_update 钩子。
- 注意事项:在 HTML 表单中,自定义元字段的 name 属性应避免与用户元键名相同,否则可能导致 $_POST 数据为空;建议添加后缀以区分。
代码示例
function update_extra_profile_fields($user_id) {
if ( current_user_can('edit_user',$user_id) )
update_user_meta($user_id, 'my_custom_field', $_POST['your_field']);
}
add_action('edit_user_profile_update', 'update_extra_profile_fields');
原文内容
Fires before the page loads on the ‘Edit User’ screen.
Parameters
$user_idint-
The user ID.
Source
do_action( 'edit_user_profile_update', $user_id );
Changelog
| Version | Description |
|---|---|
| 2.7.0 | Introduced. |
Skip to note 2 content
Steven Lin
Example migrated from Codex:
This example shows how to save a custom field named ‘
your_field‘.function update_extra_profile_fields($user_id) { if ( current_user_can('edit_user',$user_id) ) update_user_meta($user_id, 'my_custom_field', $_POST['your_field']); } add_action('edit_user_profile_update', 'update_extra_profile_fields');