PMPro includes a built-in function allowing you to require membership or require a specific membership level for your custom web applications. You will need to know the ID or Name for the member level(s) you would like to check for. The membership level ID and Name can be found in the “Membership Levels” admin page.
Check for a specific membership level with ID 12
<?php if( pmpro_hasMembershipLevel( '12' ) ) { ?> Place your content here to show if the user is in the required membership level. <?php } ?>
Check for a specific membership with name ‘Gold’
<?php if( pmpro_hasMembershipLevel( 'Gold' ) ) { ?> Place your content here to show if the user is in the Gold membership level. <?php } ?>
Check for any membership levels with ID 12, 14 or name=Gold
<?php if( pmpro_hasMembershipLevel( array('12','14','Gold') ) { ?> Place your content here to show if the user is in the Gold membership level. <?php } ?>
Check for a specific user_id (i.e. not the current user).
<?php $user_id = 1; //some other user if ( pmpro_hasMembershipLevel( '1' , $user_id ) ) { ?> Place your content here to show if the user is in the Gold membership level. <?php } ?>
Was this article helpful?
YesNo