Skip to content

Instantly share code, notes, and snippets.

@ideadude
Last active April 12, 2021 20:21
Show Gist options
  • Save ideadude/63ed6dcb4d59c27e6081d357fab65ff8 to your computer and use it in GitHub Desktop.
Save ideadude/63ed6dcb4d59c27e6081d357fab65ff8 to your computer and use it in GitHub Desktop.
Show membership level next to comments with Paid Memberships Pro.
/**
* Show membership level next to comments.
* This gist will work with PMPro and most WP themes.
* Add this code into a custom plugin. https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_comment_author_show_membership_level( $author_text, $comment_ID ) {
$email = get_comment_author_email( $comment_ID );
if( empty( $email ) ) {
return $author_text;
}
$user = get_user_by( 'email', $email );
if( empty( $user ) ) {
return $author_text;
}
if( function_exists( 'pmpro_hasMembershipLevel' ) && pmpro_hasMembershipLevel( NULL, $user->ID ) ) {
$level = pmpro_getMembershipLevelForUser( $user->ID );
$author_text = $author_text . ' (' . $level->name . ')';
}
return $author_text;
}
add_filter( 'comment_author', 'my_comment_author_show_membership_level', 10, 2 );
@laurenhagan0306
Copy link

This recipe is included in the blog post on "Show a Member’s Level Name in Post Comments" at Paid Memberships Pro here: https://www.paidmembershipspro.com/show-a-members-level-name-in-post-comments/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment