Last active
August 29, 2015 14:04
-
-
Save bappi-d-great/5ab5a1bd9684d8512b39 to your computer and use it in GitHub Desktop.
WPMU Membership Card with shortcode
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 | |
/* | |
* 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