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

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

Discover more from BenSayer.com

Subscribe now to keep reading and get access to the full archive.

Continue Reading