Skip to content

Instantly share code, notes, and snippets.

@psynewave
Created February 4, 2012 09:31
Show Gist options
  • Save psynewave/1736746 to your computer and use it in GitHub Desktop.
Save psynewave/1736746 to your computer and use it in GitHub Desktop.
Wordpress User Info Short Code
// display content to logged in users via shortcode
function member_only($atts, $content = null) {
if (is_user_logged_in())
return '<div class="memberContent">' . do_shortcode($content) . '</div>';
return '';
}
add_shortcode('member_only', 'member_only');
// display content to logged out users via shortcode
function non_member($atts, $content = null) {
if (!is_user_logged_in())
return '<div class="nonMemberContent">' .do_shortcode($content) . '</div>';
return '';
}
add_shortcode('non_member', 'non_member');
//display user id via shortcode
function member_id(){
$current_user = wp_get_current_user();
$member = $current_user->user_login;
return $member;
}
add_shortcode('member_id', 'member_id');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment