Membership Level

Paid Memberships Pro is a plugin that allows you to sell different membership levels to people. You can use Conditional Blocks to control the visibility of WordPress blocks based on the membership of the current user.

This guide was suggested by Hari via support.

Add the intergration snippet

Paid Memberships Pro has a built-in function called pmpro_hasMembershipLevel. To use this function with the PHP Logic (Custom conditions) we’ll need to register it as an allowed function using the snippet below.

Place the snippet in your theme’s function.php file, custom plugin, or you can use the (free) Code Snippets plugin

/** * Show blocks depending on the current users memebership. This snippet registers pmpro_hasMembershipLevel to be used with Conditional Blocks PHP logic. * * @param array $allowed_functions * @return array $allowed_functions */ function custom_add_allowed_function_conditional_blocks( $allowed_functions ) { // Add Paid Membership Pro Level condition. array_push( $allowed_functions, 'pmpro_hasMembershipLevel' ); return $allowed_functions; } add_filter( 'conditional_blocks_filter_php_logic_functions', 'custom_add_allowed_function_conditional_blocks', 10, 1 );
Code language: PHP (php)

Displaying WordPress blocks based on membership

Screenshot of displaying a WordPress block based on the users Paid Memberships Pro level.

Once you’ve placed the snippet on your site, you are ready to use it inside Conditional Blocks.

Create and select the WordPress blocks you wish to only be visible to specific membership levels, then add the PHP Logic condition.

Let’s say you want to display selected blocks to members who hold the ‘gold‘ membership. You’d simply write in the function name and use the allowed parameters (from the PMPRO docs).

Make the blocks visible to Gold Members

You’ll need to write the following pmpro_hasMembershipLevel('gold') and save.

Make the blocks visible to multiple memberships levels

Adding multiple lines to the same PHP logic condition will check if any of the called functions are TRUE.

pmpro_hasMembershipLevel('gold'); pmpro_hasMembershipLevel('silver');
Code language: JavaScript (javascript)

The selected block will be only visible to users who hold either a gold or silver membership.

TIP: If one user MUST have both membership levels at the same time, then you should add another PHP Logic condition. Both PHP logic conditions have to be true for the block to visible.

Make the blocks hidden to Gold Members

You’ll need to write the following !pmpro_hasMembershipLevel('gold') and save.

More information

We recommend reading the documentation for PHP Logic condition for more in-depth use and tips. We also have a write-up on Github for the Paid Memberships Pro integration.

Was this page helpful?