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