Created
December 18, 2014 14:33
-
-
Save digitalchild/35d4a33509c2c4dcd9ee to your computer and use it in GitHub Desktop.
WC Vendors - Vendor Shop Name as Full Name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Format WordPress User's "Display Name" to Full Name on Login | |
* ------------------------------------------------------------------------------ | |
*/ | |
add_action( 'wp_login', 'wpse_9326315_format_user_display_name_on_login' ); | |
function wpse_9326315_format_user_display_name_on_login( $username ) { | |
$user = get_user_by( 'login', $username ); | |
$first_name = get_user_meta( $user->ID, 'first_name', true ); | |
$last_name = get_user_meta( $user->ID, 'last_name', true ); | |
$shop_name = get_user_meta( $user->ID, 'pv_shop_name', true ); | |
$full_name = trim( $first_name . ' ' . $last_name ); | |
if ( ! empty( $full_name ) && ( $user->data->display_name != $full_name ) ) { | |
$userdata = array( | |
'ID' => $user->ID, | |
'display_name' => $full_name, | |
); | |
// Update Shop Name | |
if ( !empty( $full_name ) && ( $shop_name != $full_name ) ) { | |
update_user_meta($user->id, 'pv_shop_name', $fullname); | |
} | |
wp_update_user( $userdata ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment