Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Use user_login as fallback when email is empty or invalid.
- *
- * @since 1.0.0
- *
- * @param string $email_address The email address.
- * @param int $user_id The user ID.
- * @return string The email address to use.
- */
- function wpf_use_username_as_email_fallback( $email_address, $user_id ) {
- // If email is empty or invalid, try to use username instead
- if ( empty( $email_address ) || ! is_email( $email_address ) ) {
- $user = get_user_by( 'id', $user_id );
- if ( $user && ! empty( $user->user_login ) ) {
- // Only use user_login if it looks like an email address
- if ( is_email( $user->user_login ) ) {
- return $user->user_login;
- }
- }
- }
- return $email_address;
- }
- add_filter( 'wpf_get_contact_id_email', 'wpf_use_username_as_email_fallback', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement