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

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

wordpress如何在后台添加用户时添加自定义字段,下面点启资源给出相关代码: function userMetaBirthdayForm(WP_User $user) { ?> <h2>Birthday</h2> <table class="form-table"> <tr> <th><label for="...

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');

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

原文链接:https://www.dqzy.cn/2025/04/10/318.html,转载请注明出处。 1、本站所有源码资源(包括源代码、软件、学习资料等)仅供研究学习以及参考等合法使用,请勿用于商业用途以及违法使用。如本站不慎侵犯您的版权请联系我们,我们将及时处理,并撤下相关内容! 2、访问本站的用户必须明白,本站对所提供下载的软件和程序代码不拥有任何权利,其版权归该软件和程序代码的合法拥有者所有,请用户在下载使用前必须详细阅读并遵守软件作者的“使用许可协议”,本站仅仅是一个学习交流的平台。 3、如下载的压缩包需要解压密码,若无特殊说明,那么文件的解压密码则为:www.dqzy.cn。 4、点启资源网是一个免费且专业分享网站源码、图片素材、特效代码、教程文章、站长工具的平台。我们努力给站长提供好的资源!
0

评论0

请先
显示验证码
没有账号?注册  忘记密码?