2

How to Display Content Based on WishList Member Level

by bsayer on August 25, 2011

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.

{ 2 comments… read them below or add one }

Mark Fregnan January 19, 2012 at 3:06 am

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

bsayer January 19, 2012 at 5:02 am

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

Leave a Comment

Previous post:

Next post: