27th Nov '22
/
4 comments

Restrict Content Pro in Bricks

This Pro tutorial provides the steps to restrict Pages and individual elements like Sections in Bricks depending on whether the current user has any active membership (free or paid) or any active paid membership or has access to a specific membership level when using Restrict Content Pro.

After implementing the tutorial, you can

  • assign a class of has-active-membership to an element for it to be output only to members that have at least one active membership - free or paid.
  • assign a class of has-paid-membership to an element for it to be output only to members that have at least one active membership for a paid membership level.

and use Dynamic data condition like

{echo:bl_has_rcp_membership_level(1)}

for an element to be output only if the current user has access to the specified membership level i.e., 1 in this example.

Content from the block editor is automatically protected by Restrict Content Pro.

If your Page Bricks template is set to also show Bricks content (as it should), note that out of the box it will be visible to everyone and not just to the members that should have access to it per what's set at the Page level via the "Restrict this content" meta box.

After adding the following code, you could simply add has-active-membership or has-paid-membership class to the Post Content element that's set to show Bricks content in your Page template at its STYLE → CSS → CSS classes to have the Bricks content be output only to members that have any active membership or any paid membership.

Step 1

Add the following in child theme's functions.php (w/o the opening PHP tag) or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 625 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
How to add a Class to all Images in Bricks Galleries

How to add a Class to all Images in Bricks Galleries

Learn how to add a custom class to all the images rendered by Bricks' Gallery elements so these images can be excluded from Perfmatters' Lazy…
Pro
Conditional Rendering in Bricks Based on CSS Class

Conditional Rendering in Bricks Based on CSS Class

Updated on 19 Jun 2024 A user asks: Is there a way to apply the same conditions to several elements like we set styles appending…
Categories:
Pro
Prefiltering Bricks Terms Query Loop

Prefiltering Bricks Terms Query Loop

Let's say there's a Events CPT with a 'Event Year' custom taxonomy. Sample event year names could be: 2021, 2022, 2024, 2025, 2028 etc. We…
Pro
Filtering a Bricks Terms query on Term archive pages

Filtering a Bricks Terms query on Term archive pages

On product category archives, how to show product type names but only those that the current product category has.
Pro
Conditionally Excluding Elements from Bricks Editor

Conditionally Excluding Elements from Bricks Editor

In the past, we shared How to Exclude Elements from Bricks Editor. This Pro tutorial shows how specific elements can be excluded selectively based on…
How to Add a Custom Control Field to an Element in Bricks

How to Add a Custom Control Field to an Element in Bricks

In this tutorial, we'll learn how to add a custom control field to an element and dynamically change a CSS property inside the builder. Introduction…
Categories:
Tags: