Looking to render a Bricks builder element only if the user has access to a specified WishList Member level?
Add the following in child theme‘s functions.php
(w/o the opening PHP tag) or a code snippets plugin:
// Function to check if the current user belongs to the specified WishList Member level.
function bl_user_has_wlm_level( $level ) {
return wlmapi_is_user_a_member( $level, get_current_user_id() );
}
and apply a dynamic condition like this:
{echo:bl_user_has_wlm_level(1679020379)}
where 1679020379
is the ID of the membership level.
Reference
https://wishlistmember.com/docs/knowledge-base/function-reference-wlmapi_is_user_a_member/
5 comments
Matt
Hi, this is great. Thanks Sridhar!
Wondering how I would edit it so only manually approved users of a membership level can access?
Looks like something to do with this:
wishlistmember_approve_user_levels (action)
Called when a member is approved on one or more levels
Parameters:
$id – Member ID
$levels – Membership Levels
For reference that is from:
https://wishlistmember.com/docs/membership-level-hooks/?
Sridhar Katakam
Hi Matt. Per my understanding that hook can not help identify whether a user got automatically added to a specific level or manually by the admin. Going by the description on that doc page of "Called when a member is added to one or more levels" I don't think it is referring to manual approval of users.
Try contacting WLM support and ask if there is a function that returns a boolean (true or false) based on whether a given user has been manually approved or not. Keep us updated.
Matt
Thanks for the reply.
I followed it up wish wishlist member, but haven't been able to edit the code to make it work. Little bit beyond me.
This is the reply I got from them. Would be curious to know what you think.
You can use the function wlmapi_get_level_member_data($level_id, $member_id) instead. Here is a link to our knowledgebase article: https://wishlistmember.com/docs/function-reference-wlmapi_get_level_member_data/?
This will return all the data of the member including if they are active or for approval. You can check their membership status from there.
For your reference, here is screenshot of the return data for a member who is waiting for approval: https://screenrec.com/share/d0fxbGawke
And here is a screenshot of the return data for a member who is already approved: https://screenrec.com/share/O9qN5i0wdV
Sridhar Katakam
Yes, should be possible using this.
Can you provide the WP admin login of a test/dev site for me to work on having this data? https://brickslabs.com/support/
Matthew van der Ende
thanks, created a ticket.