Created
May 17, 2023 18:42
-
-
Save coulterpeterson/3c9ed108bfd019fa3ca81278bca49d00 to your computer and use it in GitHub Desktop.
WordPress Shortcode for Outputting Current User's Email Address
This file contains hidden or 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
<?php | |
add_shortcode('user_email', function($atts) { | |
$the_atts = shortcode_atts([ | |
"encode" => 'false' | |
], $atts); | |
if( is_user_logged_in() ) { | |
$current_user = wp_get_current_user(); | |
if( $the_atts['encode'] == 'true' ) { | |
return urlencode($current_user->user_email); | |
} else { | |
return $current_user->user_email; | |
} | |
} | |
return ""; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment