The edit_user_{$field} WordPress PHP filter allows you to modify a user field value in the ‘edit’ context.
Usage
add_filter( 'edit_user_user_email', 'modify_user_email', 10, 2 ); function modify_user_email( $value, $user_id ) { // your custom code here return $value; }
Parameters
- $value (mixed) – Value of the prefixed user field.
- $user_id (int) – User ID.
More information
See WordPress Developer Resources: edit_user_{$field}
Examples
Change User Login
Modify the user login value before displaying it in the edit context.
add_filter( 'edit_user_user_login', 'change_user_login', 10, 2 ); function change_user_login( $value, $user_id ) { $value = str_replace('admin', 'administrator', $value); return $value; }
Modify User Email
Add a custom domain to a user’s email address.
add_filter( 'edit_user_user_email', 'add_custom_domain', 10, 2 ); function add_custom_domain( $value, $user_id ) { $value .= '@mycustomdomain.com'; return $value; }
Format First Name
Capitalize the first letter of the user’s first name.
add_filter( 'edit_user_first_name', 'capitalize_first_name', 10, 2 ); function capitalize_first_name( $value, $user_id ) { $value = ucfirst($value); return $value; }
Append User Role
Add the user’s role to their last name.
add_filter( 'edit_user_last_name', 'append_user_role', 10, 2 ); function append_user_role( $value, $user_id ) { $user = get_userdata($user_id); $role = implode(', ', $user->roles); $value .= ' (' . $role . ')'; return $value; }
Customize Display Name
Create a custom display name based on user meta.
add_filter( 'edit_user_display_name', 'customize_display_name', 10, 2 ); function customize_display_name( $value, $user_id ) { $job_title = get_user_meta( $user_id, 'job_title', true ); $value = $value . ', ' . $job_title; return $value; }