admin管理员组文章数量:1026214
I use these two functions to be able to set the first and last name when I go to Add New User:
// Add First and Last name to Add New User
function add_new_user_name_fields($user) {
?>
<table class="form-table">
<tr>
<th><label for="first_name">First Name</label></th>
<td>
<input type="text" class="regular-text" name="first_name" id="first_name" />
</td>
</tr>
<tr>
<th><label for="last_name">Last Name</label></th>
<td>
<input type="text" class="regular-text" name="last_name" id="last_name" />
</td>
</tr>
</table>
<?php
}
add_action( "user_new_form", "add_new_user_name_fields" );
// Save First and Last name when new user is added
function save_add_new_user_name_fields($user_id) {
if (!current_user_can('create_users'))
return false;
update_user_meta($user_id, 'first_name', $_POST['first_name']);
update_user_meta($user_id, 'last_name', $_POST['last_name']);
}
add_action('user_register', 'save_add_new_user_name_fields');
This works very good, but how do I set both these fields to be required? Right now I am able to add a new user without setting anything in these fields.
Lastly, adding these two fields means that they end up on the bottom below Add the user without sending an email that requires their confirmation.
Is it possible to place these two fields directly below the Username
?
Thanks!
I use these two functions to be able to set the first and last name when I go to Add New User:
// Add First and Last name to Add New User
function add_new_user_name_fields($user) {
?>
<table class="form-table">
<tr>
<th><label for="first_name">First Name</label></th>
<td>
<input type="text" class="regular-text" name="first_name" id="first_name" />
</td>
</tr>
<tr>
<th><label for="last_name">Last Name</label></th>
<td>
<input type="text" class="regular-text" name="last_name" id="last_name" />
</td>
</tr>
</table>
<?php
}
add_action( "user_new_form", "add_new_user_name_fields" );
// Save First and Last name when new user is added
function save_add_new_user_name_fields($user_id) {
if (!current_user_can('create_users'))
return false;
update_user_meta($user_id, 'first_name', $_POST['first_name']);
update_user_meta($user_id, 'last_name', $_POST['last_name']);
}
add_action('user_register', 'save_add_new_user_name_fields');
This works very good, but how do I set both these fields to be required? Right now I am able to add a new user without setting anything in these fields.
Lastly, adding these two fields means that they end up on the bottom below Add the user without sending an email that requires their confirmation.
Is it possible to place these two fields directly below the Username
?
Thanks!
本文标签: phpAdd New Userextra fields which are required
版权声明:本文标题:php - Add New User, extra fields which are required? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745636281a2160467.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论