SureMembers User Access Group Condition in Bricks

SureMembers is a relatively new membership WordPress plugin by Brainstorm Force, the team behind the Astra theme.

This article shows how elements in Bricks can be conditionally rendered depending on whether the current user has access to the specified SureMembers access group.

Create this small custom function using a code snippets plugin or in your child theme’s functions.php:

<?php 

function bl_suremembers_user_has_access( int $group_id ): bool {
    return \SureMembers\Inc\Access_Groups::check_if_user_has_access( [$group_id] );
}

Now you are ready to apply a Dynamic data condition like this:

{echo:bl_suremembers_user_has_access(17)}

Replace 17 with the ID of the access group you want to check against.

With that condition in place, that Section will be output only if the current user is logged-in and has access to a SureMembers access group whose ID is 17.

To output an element only if the currently logged-in user DOES NOT have access to the specified access group, set the value (the last input field) in the condition to false.

Our BricksExtras plugin includes a SureMembers condition (besides many others) and enables you to select the access group by its name in a dropdown if you want to do this more quickly and easily.

Reference

wp-content/plugins/suremembers/inc/access-groups.php.

Dev Notes (to self)

<?php

/*$saved_access_groups = get_post_meta( get_the_ID(), SUREMEMBERS_ACCESS_GROUPS, true );

print( "<pre>" . print_r( $saved_access_groups, true ) . "</pre>" );*/

$access_groups = \SureMembers\Inc\Access_Groups::get_active();

print( "<pre>" . print_r( $access_groups, true ) . "</pre>" );

echo \SureMembers\Inc\Access_Groups::check_if_user_has_access( 17 );

echo bl_suremembers_user_has_access(17);

?>
Instant access to 390+ Bricks code tutorials with BricksLabs Pro

Leave the first comment