Restrict the display of Advanced Custom Fields (ACF) fields by Membership Level

Advanced Custom Fields PluginAdvanced Custom Fields is a popular plugin available in the WordPress.org Plugin Repository. The plugin allows you to add structured information to your posts, pages, and more.

This guide explains three primary methods to hide or show fields based on the membership requirements for the post.


Option 1: The pmpro_hasMembershipLevel() function.

Since the ACF plugin requires you to add custom PHP functions to your theme’s template files, one of the easiest ways to restrict the display of fields is to wrap your entire display in the pmpro_hasMembershipLevel() function. Here’s an example of using the function in your template files:

You can read full documentation on the pmpro_hasMembershipLevel() function here.


Option 2: The pmpro_has_membership_access() function.

Similar to the option above, this method will look to the post’s required membership levels. You won’t need to specify the level IDs when using this function, it will inherit the membership protection from the “Require Membership” metabox for that post. Here’s an example of using the function in your template files:


Option 3: The acf/format_value Filter

If you’re using version 5+ of the Advanced Custom Fields plugin, you can write a single function that will filter all fields on a member-protected page. This code will uses the acf/format_value filter to check first if the user has access to the post and will then optionally restrict the display of the field.

Note that this will not restrict the display of any custom HTML you have in your page templates, but it is a simple solution that won’t require editing all of your theme files.


If you need help altering these recipes to suit your needs, feel free to get in touch with one of our Support Engineers on our Member Support Forum.

Allow Members to Favorite Posts using the Favorites Plugin for WordPress

Add a special feature for your members that allows them to mark posts as “Favorites”. Then, show your members their bookmarked posts on the Membership Account page. Below are two code recipes that integrate Paid Memberships Pro with Favorites by Kyle Phillips.

This page requires a PMPro Core Account or higher.

Already have an account? Login Now »

New to this site? Register Now »

Show a login/register link for non-members when using the [membership] shortcode.

Here’s a useful code recipe for sites using the [membership] shortcode to show unique content based on the membership level of the user.

The code recipe will show “Log In” and “Register” links at the bottom of any post that uses the [membership] shortcode.

This page requires a PMPro Core Account or higher.

Already have an account? Login Now »

New to this site? Register Now »

Sell Single Courses using WP Courseware and Paid Memberships Pro

One of the most requested multiple memberships workarounds is the ability to offer single courses for purchase. This code recipe syncs the purchase of a single page using Addon Packages with WP Courseware, allowing members to individually purchase one or more courses.


Plugins Required

This code recipe requires four separate plugins:

  • Paid Memberships Pro,
  • Addon Packages add on (for selling access to a single page/post),
  • WP Courseware, and
  • the PMPro Addon Packages for WP Courseware plugin via the code recipe below.

How to Set it Up

  1. In the WordPress admin, add a new page for each course. This is basically just a “sales page” for the course and will not hold any of the post content.
  2. Set the “Price” for the course in the “PMPro Addon Package Settings” field.
  3. Set the Membership Levels that can make the purchase of the course addon via the “Require Membership” box. Note that these levels will not gain automatic access to the course, they are just the levels that a member must have or be assigned to at checkout in order to complete purchase.

Now, there’s a bit of simple coding to do. In your theme’s functions.php file or a helper PMPro Customizations plugin, copy these lines:

global $pmpro_addon_pages_for_courses;
$pmpro_addon_pages_for_courses = array(
3366 => 1,
3368 => 2,
);

Update the array values (format is {WP Post ID} => {Course ID}) for each page to course relationship. This is the key step that associates your sales page with the course purchased.

This works independent of the official PMPro for WP Courseware bridge plugin.


The Code Recipe

This code recipe requires a PMPro Plus Account or higher.

View Membership Options


Click here for information about multiple memberships workarounds.