Skip to content

Instantly share code, notes, and snippets.

@bappi-d-great bappi-d-great/code.php
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.