MemberPress: List the Member's Active Memberships
Adds a [wpide_mepr_memberships] shortcode that lists the logged-in member's active memberships by name, for welcome boxes and account pages.
Opens WPIDE on
Code
if ( ! class_exists( 'MeprUser' ) ) {
return;
}
add_shortcode( 'wpide_mepr_memberships', function ( $atts ) {
$atts = shortcode_atts( array( 'none' => 'You do not have an active membership.' ), $atts, 'wpide_mepr_memberships' );
if ( ! is_user_logged_in() ) {
return '';
}
$member = new MeprUser( get_current_user_id() );
$ids = array_unique( array_map( 'intval', (array) $member->active_product_subscriptions( 'ids' ) ) );
if ( ! $ids ) {
return '<p class="wpide-mepr-none">' . esc_html( $atts['none'] ) . '</p>';
}
$html = '<ul class="wpide-mepr-memberships">';
foreach ( $ids as $id ) {
$html .= '<li>' . esc_html( get_the_title( $id ) ) . '</li>';
}
return $html . '</ul>';
} );
Notes
Shows the optional none="..." text when the member has no active membership.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.