Easily display member cards with WPMU DEV Membership

Here’s a simple shortcode snippet to let you easily add a membership card for your site’s members when using WPMU DEV’s Membership plugin. This was requested in the WPMU DEV forums, where we love to help members out with simple and useful custom snippets. :)

WPMU DEV Forum topic: Display Membership Data Print/Mobile

The snippet adds a [mem_card] shortcode that will then show some member details.

You may also read:  Team Bio – Meet the Team – WordPress Plugin
* 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');

view raw


hosted with ❤ by GitHub

The snippet can easily be added to your theme’s functions.php file, using the downloadable file available in that forum thread or using a plugin like Code Snippets.

You may also like...

Leave a Reply

%d bloggers like this: