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 theFunction Referencefor a complete list of the functions you may use.

As of version 3.0.5, the main function you will use is rcp_user_has_active_membership(). If you're on an older version of Restrict Content Pro then you can usercp_is_active()instead, in the exact same way.

They are very simple functions to use:


    Content inside here would only be visible to active members.

or in versions prior to 3.0.5:


    Content inside here would only be visible to active members.

That will limit the content between the conditional to members that have an active subscription. If you want to limit the visibility only to customers who have a paid subscription you will need to use rcp_user_has_paid_membership()instead.


    Content inside here would only be visible to active paid and active free subscribers.

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 members that have a specific membership level.

If you're on version 3.0.5 or higher you can use this:


    Content inside here would only be visible to active members with a membership level ID of 2.

Otherwise, if you're on an older version of RCP you can use this:


    Content inside here would only be visible to active subscribers with a subscription level ID of 2.

In both examples just change the number "2" to the ID number you want to check.

Restricting content based on metabox settings

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.


    Content inside here would only be visible to people who meet the requirements you've set in the "Restrict this content" meta box.

TheRCP_Memberclass can be helpful for determining if a member has access to content as well.

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.

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

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

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇