The user_new_form and edit_user_profile action hooks allow developers to add content to the user editor when a new user is added to the site and when users are edited, respectively.
Our callback function first checks to see whether it received a valid user through the $user parameter or whether a new user is being created. Based on the result, it retrieves the associated user level data by calling the get_user_meta function or initializes a blank variable. The syntax of get_user_meta follows the same structure as the get_post_meta and get_term_meta functions, with the first parameter being used to specify the user ID and the remaining fields indicating the field name to be retrieved and whether data should be returned as a single variable or an array:
get_user_meta( $user_id, $field_name, $single );
The rest of our callback functions are responsible for rendering a basic HTML select list and selecting one of the items in the list based on the current user membership level.
The only additional element that we put in place in this recipe is the declaration of an array of user membership levels as a global variable that we will be referencing in multiple functions in this chapter.