You can use wpmem_user_has_access()
to check if a user has access to a specific membership or not:
https://rocketgeek.com/plugins/wp-members/docs/api-functions/wpmem_user_has_access/
This function checks if a user has access to a membership by passing the membership slug:
$has_access = wpmem_user_has_access( 'my-membership' );
It will check the currently logged in user by default. If you have to check a specific user, include $user_id
:
$has_access = wpmem_user_has_access( 'my-membership', $user_id );
If checking expirations, there is also wpmem_user_is_current()
. It functions essentially the same way, but tells you if the membership is current or not (if it’s an expiration membership – non-expiring memberships are obviously always current). Note that you do not need to use both if just checking if the user has access. wpmem_user_has_access()
will check the expiration as part of its validation. wpmem_user_is_current()
just tells you if they are expired or not.