Restrict Content Pro
rcp_user_can_access()
Coming soon: Restrict Content Pro is becoming Kadence Memberships. You may see both names used while we update the product, documentation, and customer experience.
Note: This content is provided as a resource within our developer documentation. Because custom code requires highly specific implementation, we encourage you to work with a qualified developer if you need guidance. You can find our recommended consultants here: https://codeable.io/developers/restrict-content-pro
Determines whether a user can view a specific post (or the current post in the loop). This runs RCP’s full restriction logic—membership levels, access levels, and related rules—so it is the most reliable check in templates.
If the user has an RCP_Customer record, access is evaluated with RCP_Customer::can_access( $post_id ). Users without a customer record may still get access when the post is unrestricted, when they are an administrator, or when the post is restricted only by WordPress role. See also rcp_user_can_access_term() for taxonomy restrictions.
Parameters
$user_id (int) – User ID. Default: 0 (current logged-in user).
$post_id (int) – Post ID. Default: 0 (uses the global $post in the loop). If no post can be resolved, the function returns true.
Return values
(bool) – true if the user can access the content; otherwise false.
Examples
Current user and current post in the loop:
if ( rcp_user_can_access( get_current_user_id(), get_the_ID() ) ) {
// Show restricted content.
} else {
// Show restriction message or redirect.
}
Specific user and post:
if ( rcp_user_can_access( 42, 100 ) ) {
// User #42 can access post #100.
}
Omit $post_id inside the loop (uses global post):
if ( rcp_user_can_access() ) {
the_content();
}