钩子文档

profile_personal_options

💡 云策文档标注

概述

profile_personal_options 是一个 WordPress 动作钩子,在用户个人资料编辑页面的“个人选项”设置表格后触发。此钩子仅在当前用户编辑自己的个人资料时执行。

关键要点

  • 触发时机:在“个人资料”编辑屏幕的“个人选项”设置表格后触发。
  • 条件限制:仅当当前用户编辑自己的个人资料时才会触发。
  • 参数:$profile_user(WP_User 对象),代表当前用户对象。
  • 源调用:do_action( 'profile_personal_options', $profile_user );
  • 版本历史:自 WordPress 2.0.0 版本引入。

代码示例

// This will show below the color scheme and above username field
add_action( 'profile_personal_options', 'extra_profile_fields' );
    
function extra_profile_fields( $user ) {
    // get the value of a single meta key
    $meta_value = get_user_meta( $user->ID, 'meta_key', true ); // $user contains WP_User object
    // do something with it.
    ?>
    " />
    

注意事项

  • 确保钩子函数正确处理 $profile_user 参数,以访问用户数据。
  • 此钩子适用于在个人资料页面添加自定义字段或逻辑,但需注意权限和条件限制。

📄 原文内容

Fires after the ‘Personal Options’ settings table on the ‘Profile’ editing screen.

Description

The action only fires if the current user is editing their own profile.

Parameters

$profile_userWP_User
The current WP_User object.

Source

do_action( 'profile_personal_options', $profile_user );

Changelog

Version Description
2.0.0 Introduced.

User Contributed Notes

  1. Skip to note 2 content

    Example:

     // This will show below the color scheme and above username field
    add_action( 'profile_personal_options', 'extra_profile_fields' );
        
    function extra_profile_fields( $user ) {
    	// get the value of a single meta key
    	$meta_value = get_user_meta( $user->ID, 'meta_key', true ); // $user contains WP_User object
    	// do something with it.
    	?>
    	<input type="text" name="value" value="" />