Conditional Component Expression by User Capability

I have defined a member_only_content capability and associated it to specific roles on my sight (this can be seen from the plugin interface I used here.

Now I’m trying to leverage this in Cornerstone to make a specific section visible only if the current user has this capability but I don’t see a way to do this. I’ve tried {{dc:user:meta key="member_only_content"}} but it returns no value. I’ve also tried {{ user.meta({"key":"wp_capabilities"}) }} but it seems to return an array containing the User Role.

Based on some details I found here I also tried {{ user.can('member_only_content') }} but it also doesn’t appear to provide any value

Really hoping there is a way to accomplish this but just need some guidance. Thanks!

Hello Nicholas,

Thanks for writing in! May I suggest that you check out J JSM Show Post Metadata to find out the correct post meta of the capabilities that you are trying to access using the dynamic content? We would also love to check out your set up if we can have access to it. You can create a secure note in your next reply with the following info:
– Link to your site
– WP login URL
– WP username
– WP password
– WP Administrator Role
– Confirmation that we can access and make changes to your site

To know how to create a secure note, please check this out: How The Forum Works

image

Best Regards.

I’m not sure I understand. Are you saying that I need a plugin to accomplish this or that this plugin somehow tells me what the capability slug is that I just created? I added a secure note for you to review. I’m looking to make the Event Recap section hidden to only these specific users that have the capability. I also then need to make a separate sections that offers these users a login/signup option.

Hello Nicholas,

The JSM plugin is only a tool that will help you understand how the member_only_content custom field is saved within the post meta or in a user profile. For example in this field group;

Editing an event will give you something like this:

And if you use this in a condition, {{dc:post:meta key="members_only"}} is 1.

Hope this makes sense.

I get how that works for Post data, and I saw that there is another similar plugin for User data, but the metadata I’m referring to is a capability associated to the User’s Role (ie. Administrator, Editor, Business Member). I created them using the Profile Builder Plugin, and before that I used the Roles and Capabilities Plugin (which I assume accomplish the same task of providing an interface WordPress Roles and Capabilities functionality.

In general how would I accomplish this with even the already defined standard capabilities such as edit_posts? I would assume the method would be the same for standard or custom, but neither of these would be considered Post metadata. Does this help clarify my question?

Not sure if this is possible without coding.

My approach with coding: I have used the free Members plugin to set up some user roles like Premium and Supporter roles.

Then I coded some additional Cornerstone conditions which I can just select in the element’s Conditions field.

Now if want to show an element to Premium Members only, I can just set the condition like in the image.
If you can code some PHP, you can achieve this with Themeco’s Conditions API: https://theme.co/docs/conditions-api

1 Like

Hello @raye,

Thanks for chiming in! This is really a great resource to get started with the feature Nicholas is looking for.

@Nicholas, be advised that custom coding is beyond the scope of our support under our Support Policy. If you are unfamiliar with code and resolving potential conflicts, you may select our One service for further assistance.

Cheers.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.