Restricting Content in Template Files

If you would like to restrict portions of your theme or plugin template files, Restrict Content Pro provides a series of functions that will allow you to do that. Consult the Function Reference for a complete list of the functions you may use.

Please note: any changes you make to theme files should be done in a  child theme, so that you don't lose your customizations when you install theme updates. If you don't understand this, please consider hiring a developer.

The main function you will use is rcp_is_active(). It is a very simple function to use:

<?php if( rcp_is_active() ) : ?>
	<p>This content is restricted to active subscribers.</p>
<?php endif; ?>

That will limit the content between the conditional to members that have an active subscription. Note: members with a free subscription level are not covered by rcp_is_active(). For free users, you need a different check.

<?php if ( rcp_is_active() || ( rcp_get_subscription_id() && 'free' === rcp_get_status() ) ) : ?>
	<p>This content is restricted to active paid and active free subscribers.</p>
<?php endif; ?>

There are more advanced checks you can do (see the function reference linked above) as well. For example, you could show content to just active subscribers that have a specific subscription level:

<?php if( rcp_is_active() && 2 == rcp_get_subscription_id() ) : ?>
	<p>This content is restricted to active subscribers with a subscription level ID of 2.</p>
<?php endif; ?>

The RCP_Member class can be helpful for determining if a member has access to content as well.

Restricting access to posting comments

If you want to allow only active members to post comments on your site, you'll need to customize your theme's comments.php file.

Note: the comments.php file varies from theme to theme, but the generally have a similar structure.

To restrict access to the posting of comments, find this line in your comments.php file:

<?php comment_form(); ?>

Now let's adjust it so that only active members can post comments.

<?php if ( rcp_is_active() ) : ?>
	<?php comment_form(); ?>
<?php endif; ?>