Shortcode to return the User's domain from their email address

Labels

This Discussion is public

Notifications

add_shortcode('users-email-domain',extract_domain_func);
function extract_domain_func(){
$current_user = wp_get_current_user();
$email = $current_user->user_email;
if( filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
// split on @ and return last value of array (the domain)
$domain = array_pop(explode('@', $email));
return $domain;
}
}

Usage [users-email-domain]

Reply to this Discussion