Description
Checks if a user has access to a given membership product.
Parameters
$product
(mixed) (required) The meta key of the product being checked, or an array of product meta keys.
$user_id
(integer) (optional) The user ID to check. If no user ID is passed, it will check for the currently logged in user.
Return Value
boolean (true|false) Returns true if the user has access, otherwise false.
Example
/** * This example checks if the currently logged in user has * access to the "my-membership" restriction. The * result will be a true|false boolean. */ $has_access = wpmem_user_has_access( 'my-membership' ); /** * This example is similar to the above, but it checks a * specific user by user ID contained in $user_id. */ $has_access = wpmem_user_has_access( 'my-membership', $user_id );
Notes
If checking multiple memberships, pass an array of the membership meta keys (slugs). If the user has current access to any of the memberships, the function will return true.
Changelog
Introduced in version 3.2.0
Version 3.2.3 reversed the order of arguments.
Source
wpmem_user_has_access() is located in /includes/api/api-users.php.