php - Add New User, extra fields which are required?

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

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!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745636283a4637412.html

相关推荐

  • php - Add New User, extra fields which are required?

    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

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信