Advertisement
chrishajer

Add to body class based on WLM level

Aug 20th, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. <?php
  2. // http://www.gravityhelp.com/forums/topic/changing-the-background-color-of-a-post
  3. // filter the body class
  4. add_filter( 'body_class', 'adzoom_wishlist_member_classes' );
  5.  
  6. // function to add body class based on wishlist member weekly, 180 day or 365 day
  7. function adzoom_wishlist_member_classes ($classes) {
  8.  
  9.     // grab the current user's wishlist member levels
  10.     global $current_user;
  11.     $user_id = $current_user->ID;
  12.     $levels = wlmapi_get_member_levels($user_id);
  13.     $levels = $levels['levels']['level'];
  14.  
  15.     // these three if statements will all run, no matter what, in case there are multiple membership levels possible for a member?
  16.     // not sure if that's possible, but the wlmapi_get_member_levels returns an array, which could be multiple membership levels
  17.  
  18.     // add the membership levels to the body class
  19.     if(in_array(365, $levels)) {
  20.         // add 'year-member' to the $classes array
  21.         $classes[] = 'year-member';
  22.     }
  23.     if(in_array(180, $levels)) {
  24.         // add 'half-year-member' to the $classes array
  25.         $classes[] = 'half-year-member';
  26.     }
  27.     if(in_array('weekly', $levels)) {
  28.         // add 'week-member' to the $classes array
  29.         $classes[] = 'week-member';
  30.     }
  31.  
  32.     // return the $classes array no matter what
  33.     return $classes;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement