rcp_member_can_access

Determines whether or not a given user should be able to access a given post. If this returns false then the restricted content message is shown when trying to view the post.

Parameters:

  • $can_access - Will be either true (they can access) or false (cannot access).
  • $member_id - ID of the user account being checked.
  • $post_id - ID of the post being checked.
  • $member - RCP_Member object.

Example:

/**
 * Restrict access to all posts, but grant access to users in subscription level ID 2.
 *
 * @param bool $can_access
 * @param int $member_id
 * @param int $post_id
 * @param RCP_Member $member
 */
function ag_rcp_member_can_access( $can_access, $member_id, $post_id, $member ) {

	// Only make changes if this is a `post`.
	if ( 'post' == get_post_type( $post_id ) ) {

		// Grant access if they're on sub level #2 and their account isn't expired.
		if ( 2 == $member->get_subscription_id() && ! $member->is_expired() ) {
			$can_access = true;
		} else {
			$can_access = false;
		}

		// Always grant access to admins.
		if ( user_can( $member_id, 'manage_options' ) ) {
			$can_access = true;
		}

	}

	return $can_access;

}

add_filter( 'rcp_member_can_access', 'ag_rcp_member_can_access', 10, 4 );