Restrict Content Pro(简称RCP)是一个控制WordPress文章/页面或其它类型文章对用户可见性的WordPress插件,可以用其设立一个付费阅读优质内容的会员网站。
限制付费订阅者的内容
The main function you will use is rcp_is_active(). It is a very simple function to use:
<?php if( rcp_is_active() ) : ?>
<p>Content inside here would only be visible to active members.</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>Content inside here would only be visible 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>Content inside here would only be visible to active subscribers with a subscription level ID of 2.</p>
<?php endif; ?>
根据元数据设置限制内容
If you’re adding restrictions to a custom page template, you may want to set up PHP restrictions based on your metabox settings for that page. That can be done using the rcp_user_can_access() function. This checks to see if the current user has access to view the current page, based on the settings you’ve chosen in the “Restrict this content” meta box.
<?php if( rcp_user_can_access() ) : ?>
<p>Content inside here would only be visible to people who meet the requirements you've set in the "Restrict this content" meta box.</p>
<?php endif; ?>
限制发布评论的访问权限
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; ?>