show_user_profile
云策文档标注
概述
show_user_profile 是一个 WordPress 动作钩子,在用户个人资料编辑页面的“应用程序密码”部分加载后触发,主要用于向用户资料页面底部添加自定义字段或数据。
关键要点
- 触发条件:仅当当前用户编辑自己的个人资料时触发,不适用于其他用户的资料页面。
- 参数:$profile_user(WP_User 对象),代表当前正在编辑的用户。
- 用途:常用于输出自定义字段或数据到用户资料页面底部,增强后台功能。
- 相关钩子:如需应用于所有用户资料页面(包括其他用户),需同时使用 edit_user_profile 钩子。
- 版本历史:自 WordPress 2.0.0 版本引入。
代码示例
/**
* Show custom user profile fields
*
* @param object $profileuser A WP_User object
* @return void
*/
function wpdocs_custom_user_profile_fields( $profileuser ) {
?>
<h3>Extra profile information</h3>
<table class="form-table">
<tr>
<th><label for="twitter">Twitter</label></th>
<td>
<input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $profileuser->ID ) ); ?>" class="regular-text" />
<p class="description">Please enter your Twitter username.</p>
</td>
</tr>
</table>
<?php
}注意事项
- 此钩子仅对当前用户自己的资料页面有效,若需处理其他用户的资料,应结合 edit_user_profile 钩子使用。
- 示例代码展示了如何添加自定义字段(如 Twitter 用户名)到用户资料页面,并确保数据安全输出。
原文内容
Fires after the ‘Application Passwords’ section is loaded on the ‘Profile’ editing screen.
Description
The action only fires if the current user is editing their own profile.
Parameters
Source
do_action( 'show_user_profile', $profile_user );
Changelog
| Version | Description |
|---|---|
| 2.0.0 | Introduced. |
Skip to note 3 content
1994rstefan
See the edit_user_profile action for an example on how to add a form to the backend user edit screen and save some additional user meta data.
https://developer.wordpress.org/reference/hooks/edit_user_profile/#comment-2228
Skip to note 4 content
Collins Mbaka
Example migrated from Codex: