Restrict Content Pro
rcp_user_has_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
Checks whether a user’s active memberships grant an access level equal to or higher than the value you pass. Uses RCP_Customer::has_access_level().
This is not the same as rcp_user_can_access(), which checks whether a user can view a specific post. The names are similar; use the post-level function for content restrictions.
Parameters
$user_id (int) – User ID. Default: 0 (current logged-in user when $user_id is empty and the visitor is logged in).
$access_level_needed (int) – Required access level (0–10). Default: 0.
Return values
(bool) – true if the customer has at least one qualifying membership with that access level or higher; false if there is no customer or no membership meets the level. Passing 0 returns true when the customer has no memberships (level 0 is treated as satisfied).
Examples
if ( rcp_user_has_access( get_current_user_id(), 5 ) ) {
// User has access level 5 or higher.
}
// Level 0 — true for users with no memberships.
if ( rcp_user_has_access( $user_id, 0 ) ) {
// ...
}