edit user profile - Action介绍

原文:Plugin API/Action Reference/edit user profile

Action介绍

这个Action钩子通常会在用户属性编辑页面需要输出新的字段或者在编辑页面底部添加更多内容的时候会使用到。

这个钩子只有在用户编辑其他用户的属性时候才会触发(不是当前登录用户)。如果需要所有用户编辑页面都会触发事件,那应该使用show_user_profile钩子。

参数

$user
(object) (optional) 当前被正在被编辑的用户。
默认: None

例子

/**
 * Show custom user profile fields
 * @param  obj $user The user object.
 * @return void
 */
function numediaweb_custom_user_profile_fields($user) {
?>
<table class="form-table">
<tr>
    <th>
        <label for="tc_location"><?php _e('Location'); ?></label>
    </th>
    <td>
        <input type="text" name="tc_location" id="tc_location" value="<?php echo esc_attr( get_the_author_meta( 'tc_location', $user->ID ) ); ?>" class="regular-text" />
        <br><span class="description"><?php _e('Your location.', 'travelcat'); ?></span>
    </td>
</tr>
<tr>
    <th>
        <label for="tc_favorites"><?php _e('Favorites', 'travelcat'); ?></label>
    </th>
    <td>
        <input type="text" name="tc_favorites" id="tc_favorites" value="<?php echo esc_attr( get_the_author_meta( 'tc_favorites', $user->ID ) ); ?>" class="regular-text" />
        <br><span class="description"><?php _e('Can you share a few of your favorite places to be or to stay?', 'travelcat'); ?></span>
        <br><span class="description"><?php _e('Separate by commas.', 'travelcat'); ?></span>
    </td>
</tr>
<tr>
    <th>
        <label for="tc_travel_map"><?php _e('Travel map', 'travelcat'); ?></label>
    </th>
    <td>
        <input type="text" name="tc_travel_map" id="tc_travel_map" value="<?php echo esc_attr( get_the_author_meta( 'tc_travel_map', $user->ID ) ); ?>" class="regular-text" />
        <br><span class="description"><?php _e('Been there / Going there within a year / Wish list.', 'travelcat'); ?></span>
        <br><span class="description"><?php _e('Separate by commas.', 'travelcat'); ?></span>
    </td>
</tr>
</table>
<?php
}
add_action('show_user_profile', 'numediaweb_custom_user_profile_fields');
add_action('edit_user_profile', 'numediaweb_custom_user_profile_fields');

源文件

edit_user_profile 钩子的源文件在 /wp-admin/user-edit.php

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值