#Overview
This function determines whether the a user can access a given post (by ID). It can use the current logged in user, as in the example below, or an alternate user ID can be provided.
#Basic Usage
The basic usage takes a post ID and tells you whether or not the current user has access to that post, based on the access rules configured in the WP Fusion meta box, and the current user』s logged-in status and CRM tags.
if ( wpf_user_can_access( $post_id ) ) {
echo "Welcome to the post.";
} else {
echo "Sorry, but this content is restricted.";
}
#With a user ID
You can also pass in a user ID as the second argument to perform the check on other users. For example, to check by a user』s email address:
$user = get_user_by( 'email', '[email protected]' );
if ( wpf_user_can_access( $post_id, $user->ID ) ) {
echo "Welcome to the post.";
}
#Within a loop
When used within a loop, you can omit the $post_id and WP Fusion will check the access rules against the current post:
if ( wpf_user_can_access() ) {
echo "Welcome to the post.";
}
#Was this helpful?
Let us know if you liked the post. That』s the only way we can improve.
Yes
No