wordpress收费下载资源主题
wordpress付费下载资源插件

wordpress 如何在后台添加用户时自定义字段

wordpress如何在后台添加用户时添加自定义字段,下面模板兔给出相关代码:

function userMetaBirthdayForm(WP_User $user) {
?>
<h2>Birthday</h2>
<table class="form-table">
<tr>
<th><label for="user_birthday">Birthday</label></th>
<td>
<input
type="date"
value="<?php echo esc_attr(get_user_meta($user->ID, 'birthday', true)); ?>"
name="user_birthday"
id="user_birthday"
>
<span class="description">Some description to the input</span>
</td>
</tr>
</table>
<?php
}
add_action('show_user_profile', 'userMetaBirthdayForm'); // editing your own profile
add_action('edit_user_profile', 'userMetaBirthdayForm'); // editing another user
add_action('user_new_form', 'userMetaBirthdayForm'); // creating a new user

function userMetaBirthdaySave($userId) {
if (!current_user_can('edit_user', $userId)) {
return;
}

update_user_meta($userId, 'birthday', $_REQUEST['user_birthday']);
}
add_action('personal_options_update', 'userMetaBirthdaySave');
add_action('edit_user_profile_update', 'userMetaBirthdaySave');
add_action('user_register', 'userMetaBirthdaySave');

以上是添加用户、编辑用户、个人资料更新时都有效。

0 个评论

定制开发
本站承接WordPress等系统建站仿站、二次开发、主题插件定制等开发服务
在线咨询
  • 请直接说明需求,勿问在否
    QQ:1-247-246-247

  • QQ一群:104228692(满)
  • QQ二群:64786792
在线咨询
本站承接WordPress建站仿站、二次开发、主题插件定制等PHP开发服务!

了解详情