wordpress wishlist plugin: quickly find out if a user is a member of a level

wordpress wishlist plugin recommends everyone to use its api to connect to wishlist. However, the process of using api is slow and it can take a long time if you have a widget that wants to talk to wishlist on almost every page. As wishlist is a paid plugin, the code is protected and therefore, there is no way for us to figure out how to hook onto the right wishlist function to use. Luckily for us, we can look at the database and work our way through.

I’ve created a simple function to check if a user is subscribed to certain level.

function is_wishlist_member_of($sku) {
  global $wpdb;

  if (is_user_logged_in()) {
    $user_id = wp_get_current_user()->ID;
    $table = $wpdb->prefix.'wlm_options';
    $query = "Select option_value from $table where option_name='wpm_levels'";
    $levels = unserialize($wpdb->get_var($query));
    foreach ($levels as $k => $v) {
      if ($v['name'] == $sku) {
        $id = $k;
    $table = $wpdb->prefix.'wlm_userlevels';
    $query = "Select ID from $table where user_id='$user_id' and level_id='$id'";
    // if ($wpdb->get_var($query)) {
    // allow subscribed users and administator
    if ($wpdb->get_var($query) || current_user_can('administrator')) {
      return true;
    else {
      // user didn't register
      return false;

Author: bpeh

Bernard Peh is a great passioner of web technologies and one of the co-founder of Sitecritic.net Website Design and Reviews. He works with experienced web designers and developers everyday, developing and designing commercial websites. He specialises mainly in SEO and PHP programming.

2 thoughts on “wordpress wishlist plugin: quickly find out if a user is a member of a level”

  1. I am currently using a plug-in called Wishlist member. It allows you to create membership levels in WordPress. I want to be able to display different content on a page depending on if the user is added to two levels.

    Am using the code below – if user is in one level

    // get the current user level from WP more important is global $user. $user = wp_get_current_user();

    // Get user levels from WishlistMembers $levels = WLMAPI::GetUserLevels($user->ID);

    //then run the check for the level you want like this:

    if(in_array(‘silver’, $levels)){

    // PRINT OUT THE silver LEVEL stuff here }

    elseif (in_array(‘gold’, $levels)){

    // PRINT OUT THE gold LEVEL stuff here }

    which works perfectly if the user is one level. If the user is added to two levels then how to use the above code? Please assist.



Comments are closed.