0

I know how to customize the users in the admin area of WordPress. I have done it many times. However, I would like to customize the user a bit differently as explained below.

I would like to add a new labe and a new textbox associated with that label. Lets call them "Label 1" and "Textbox 1". I like to add those under the "Username" field set and before the "Role" field set. In other words, I like the admin area for the user to look like this after the customization"

Username: <TEXTBOX FOR USER NAME>
Label 1: <TEXTBOX 1>
Role: <DROPDOWN LIST FOR ROLES>

All examples I found describe adding the new fields at the bottom of the User page. How can I add them to the middle?

Thanks.

1 Answer 1

2

How can I add them to the middle?

You won't be able to add them directly where you want, but you can get close.

There are four hooks to put stuff into the profile page:

  • personal_options -- fires on every user edit screen, including when a user is viewing their own profile. Directly above username.
  • profile_personal_options -- fires only when a user is viewing/editing their own profile. Directly above username.
  • show_user_profile -- fires when the a user is viewing/editing their own profile. At the bottom of the page, before the submit.
  • edit_user_profile -- fires when another user is editing a profile (eg. an admin editing someone else's profile). At the bottom of the page, before the submit.

Most examples put the fields in show_user_profile and edit_user_profile.

add_action('show_user_profile', 'wpse142687_show_fields');
add_action('edit_user_profile', 'wpse142687_show_fields');
function wpse142687_show_fields($user)
{
   // echo fields and such
}

In your case, you probably want to use personal_options:

add_action('personal_options', 'wpse142687_show_fields');
function wpse142687_show_fields($user)
{
   // anything here will be shown directly above the username field
   // please note that it's inside a form table, so you should format
   // your HTML fields accordingly
}

Saving the fields works the same as putting them at the bottom.

add_action('personal_options_update', 'wpse142687_save_fields');
add_action('edit_user_profile_update', 'wpse142687_save_fields');
function wpse142687_save_fields($user_id)
{
   // check nonce
   // check permisions
   // save stuff
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.