Created
December 2, 2015 21:53
-
-
Save vaughanm/e86802c785b706d121a4 to your computer and use it in GitHub Desktop.
adding user shortcode to display any user data
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
// Add Shortcode | |
function user_shortcode( $atts ) { | |
$a = shortcode_atts( | |
array( | |
'user_id' => get_current_user_id(), | |
'field' => '', | |
), $atts ); | |
| |
$user = get_user_by( 'id', $a['user_id'] ); | |
$output = !empty($user->$a['field']) ? $user->$a['field'] : ''; | |
| |
return $output; | |
} | |
add_shortcode( 'user', 'user_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now you can display any user data via shortcode.
[user field="user_login" user_id="1"]
will display the user login for user id 1. if user_id is omitted, defaults to current_user.
[user field="first_name" user_id="1"]
will display the first name for user_id 1.