12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on Aug 11, 2018

MemberPress in Oxygen

Sridhar Katakam

This tutorial provides the steps to protect the entire single entry (post, page etc.) built with Oxygen using MemberPress (affiliate link).

In this example, we are going to create a “Free Membership” and add a rule to grant viewing access to a specific post to only the users that have the free membership.

Note that MemberPress works out of the box without any of the following steps as long as protecting the standard WordPress post content is concerned. Any other elements that are built with Oxygen though, are not. Hence this guide.

The concept is similar to my earlier How to Password Protect entries in Oxygen post.

Step 1

Install and activate MemberPress.

Step 2

Go through the plugin’s settings page and configure as needed.

Go to MemberPress > Memberships > Add New and add a new membership.

Step 3

Go to MemberPress > Rules and add a new rule to restrict a particular single post (for the sake of this example).

Select the free membership.

You should, of course, tweak this to match your site’s needs. For example, you may be wanting to restrict posts that belong to a particular category to users based on a membership or a group.

Note the ID in the “Partial Content Codes” section.

In our example, it is 658.

Step 4

Go to Oxygen > Templates.

Create a new reusable part named say, “Reusable for Blog Post”. Edit it with Oxygen and build it out.

You will most likely be already having a template for single blog posts. If so, you could bring up the Structure tree and save each of your top-level elements (typically, sections) as reusable parts. Then go back to “Reusable for Blog Post” and add these as editable.

Save the reusable part and go back to admin. Note the ID.

For example, if the URL is https://oxygen.test/wp-admin/post.php?post=660&action=edit, the ID is 660.

Step 5

Edit the template that’s applied to all your single blog posts. Create one if not present.

Delete all elements (if any).

Add a Code Block element having the following in PHP & HTML:

    if ( current_user_can ( 'mepr-active', 'rule: 658' ) ) {
        echo do_shortcode( get_post_meta( 660, 'ct_builder_shortcodes', true ) );
    } else {
        echo '<div class="ct-section"><div class="ct-section-inner-wrap">' . do_shortcode( '[mepr-unauthorized-message]' ) . '</div></div>';

Replace 658 with the ID from Step 3 and 660 with the ID from Step 4.

That’s it!

Reference: https://docs.memberpress.com/article/112-available-shortcodes