How to Display Content Based on WishList Member Level

I created a PHP function for my GenealogyTools.com blog last night. It may save you some time if you want to control what content displays for different WishList Member member levels.

I use the Thesis theme, so I added the function to custom_functions.php and use it for an after post hook and to control the display of sidebar widgets.

Here’s the function:


function is_user_premium_member() {
$user = wp_get_current_user();
$levels = WLMAPI::GetUserLevels($user->ID);
if(in_array('Premium', $levels)) {
return true;
}
else {
return false;
}
}

This function determines whether the user is in the Premium membership level. You can make it check for a level with different name by changing the value ‘Premium’ to whatever your membership level is (e.g. ‘Gold’).

Once you have the function saved, you can use it in the “Conditional” text box of a widget. To exclude the widget for the membership level, enter: !is_user_premium_member(). To only display it for the membership level, leave off the exclamation point: is_user_premium_member().

Similarly, you can use the function within a hook like I have in the following example of an a single post advertisement hook:

/* Ad after single posts */
function single_post_ads() {
if (is_single()) {
if(!is_user_premium_member()) { ?>

// Put what you want to display for non-premium members here

}
}
}

add_action('thesis_hook_after_post', 'single_post_ads');

In this case, taking out the exclamation point will make the ad display only for premium members.

Comments

  1. Mark Fregnan says:

    Hi. Thanks for your post. I was looking to solve this problem.

    I’m using the Revolutions theme and I couldn’t find the appropriate php file (you used custom_functions.php). However I then added your code to the /wp-includes/pluggable.php file and it works!

    Mark

  2. bsayer says:

    Hi, Mark. I’m glad I helped you! —-Ben >@<

  3. Ben says:

    Thanks Ben. This worked like a charm! I hate how WLM is so proprietary, and their plugin code is all encrypted. I guess there is good security in that but I like sifting through code to figure things out.

  4. bsayer says:

    Hi, Ben. I’m happy you found it helpful.

    I know what you mean about the plugin encryption. I prefer being able to see the source too. That said, I’m okay with proprietary too as long as the solution is elegant and well documented–neither of which apply here. That’s part of why I’m moving off WLM.

    I’m going to use the new member functionality in Premise, from Copyblogger Media. Love those guys!

    —-Ben >@<

  5. Kurt says:

    Ben:
    Thanks for the code snippet! It definitely helped me!

Speak Your Mind

*