Skip to content

Instantly share code, notes, and snippets.

@bappi-d-great
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bappi-d-great/5ab5a1bd9684d8512b39 to your computer and use it in GitHub Desktop.
Save bappi-d-great/5ab5a1bd9684d8512b39 to your computer and use it in GitHub Desktop.
WPMU Membership Card with shortcode
<?php
/*
* Use [my_mem_card] shorcode in anywhere in a page
*/
function my_mem_func() {
if( is_user_logged_in() ){
$current_user = wp_get_current_user();
$factory = Membership_Plugin::factory();
$user_object = $factory->get_member( $current_user->ID );
$userlevels = $user_object->get_level_ids();
if (!empty($userlevels)) {
$rows = array();
foreach ((array) $userlevels as $key => $value) {
$level = Membership_Plugin::factory()->get_level($value->level_id);
if (!empty($level)) {
if ((int) $value->sub_id != 0) {
$rows[] = "<strong>" . $level->level_title() . "</strong>";
} else {
$rows[] = $level->level_title();
}
}
}
}
$html = '<div class="mem_card">';
$html .= $current_user->user_firstname . '<br>';
$html .= $current_user->user_email . '<br>';
$html .= $current_user->user_login . '<br>';
$html .= 'Level: ' . implode(", ", $rows);;
$html .= '</div>';
return $html;
}
}
add_shortcode('my_mem_card', 'my_mem_func');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment