Learn how to restrict viewing and adding comments on blog posts to a specific subscriber level with Restrict Content Pro using code.
In previous tutorials, you have already seen how to restrict comments to subscribers in a CPT or “normal” post entries.
But what if you want to go a little further and want a certain level of subscriber to not have access to those comments?
Are you interested in limiting comments to only one level of subscribers using Restrict Content Pro?
Here is the code to implement it:
Instructions to restrict comments on posts to a specific subscription level
1. Create a comment limiting snippet
Add the following code at the end of functions.php or in your functionality plugin:
When using Restrict Content Pro to manage subscribers, you need to add a conditional tag next to a function that checks if the user has an active subscription. In this case it is r
rcp_is_active(), which is now deprecated).
But in this case, you also check if the subscribers are subscribed to the membership with ID 3 and, if so, you also block them.
You can see the ID of the membership from: Restrict > Membership Levels.
Therefore, if the reader does not meet the condition (is not a subscriber or is an unsupported subscriber) this block takes care of deleting the comments using the Genesis Framework hooks.
The code above serves to limit the snippet in both normal blog posts and CPTs, but you can modify it to your liking, as you saw in the tutorials on how to restrict comments to subscribers in a CPT or in “normal” post entries.
As you can see, with the block you also take the opportunity to place a message or CTA in the hidden area so that ‘non-subscribers’ understand why they don’t see the comments and invite them to subscribe or identify themselves.
Again, you can (and should) modify this text to your liking.
2. Customize the CSS of the CTA in the comments area
Once you have hidden the comments from non-subscribers, you just need to style the message that appears in the restricted area.
To do this, add this block to the end of style.css:
If you want the padlock to be displayed, add this file to the path /assets/images/ (hold down the alt key when clicking on the link to download it).
It is possible that your theme does not have the same folder structure and instead of /assets/images/ it is just /images/ or similar
If so, place it in that folder and adjust the path accordingly.
Another option is to upload the image to your media library and place the full path in the ULR. It would look something like this:
As always, I invite you to customize the size of the box, border, corporate colors… according to the image of the project.
Now you know how to hide comments from non-subscribers and those of a given subscription with Restrict Content Pro.
Any questions? I read you in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉