M_Adminbar

The Membership 2 M Adminbar class.

Defined (1)

The class is defined in the following location(s).

/app_old/membershipincludes/classes/class.adminbar.php  
  1. class M_Adminbar { 
  2.  
  3. var $build = 12; 
  4. var $db; 
  5.  
  6. var $tables = array('membership_levels', 'membership_rules', 'subscriptions', 'subscriptions_levels', 'membership_relationships', 'membermeta', 'communications', 'urlgroups', 'ping_history', 'pings', 'coupons'); 
  7.  
  8. var $membership_levels; 
  9. var $membership_rules; 
  10. var $membership_relationships; 
  11. var $subscriptions; 
  12. var $subscriptions_levels; 
  13. var $membermeta; 
  14. var $communications; 
  15. var $urlgroups; 
  16. var $ping_history; 
  17. var $pings; 
  18. var $coupons; 
  19.  
  20. function __construct() { 
  21.  
  22. global $wpdb; 
  23.  
  24. $this->db =& $wpdb; 
  25.  
  26. foreach($this->tables as $table) { 
  27. $this->$table = membership_db_prefix($this->db, $table); 
  28.  
  29. add_action( 'add_admin_bar_menus', array( &$this, 'add_admin_bar_items' ) ); 
  30.  
  31. add_action('membership_dashboard_membershipuselevel', array( &$this, 'switch_membership_level' ) ); 
  32.  
  33.  
  34. function M_Adminbar() { 
  35. $this->__construct(); 
  36.  
  37. function get_membership_levels($filter = false) { 
  38.  
  39. if($filter) { 
  40. $where = array(); 
  41. $orderby = array(); 
  42.  
  43. if(isset($filter['s'])) { 
  44. $where[] = "level_title LIKE '%" . mysql_real_escape_string($filter['s']) . "%'"; 
  45.  
  46. if(isset($filter['level_id'])) { 
  47. switch($filter['level_id']) { 
  48.  
  49. case 'active': $where[] = "level_active = 1"; 
  50. break; 
  51. case 'inactive': $where[] = "level_active = 0"; 
  52. break; 
  53.  
  54.  
  55. if(isset($filter['order_by'])) { 
  56. switch($filter['order_by']) { 
  57.  
  58. case 'order_id': $orderby[] = 'id ASC'; 
  59. break; 
  60. case 'order_name': $orderby[] = 'level_title ASC'; 
  61. break; 
  62.  
  63.  
  64.  
  65. // No need to prepare on table name 
  66. $sql = "SELECT * FROM {$this->membership_levels}"; 
  67.  
  68. // ... and these are already pretty strongly defined (and escaped where needed)... 
  69. if(!empty($where)) { 
  70. $sql .= " WHERE " . implode(' AND ', $where); 
  71.  
  72. // ... so are these. 
  73. if(!empty($orderby)) { 
  74. $sql .= " ORDER BY " . implode(', ', $orderby); 
  75.  
  76. return $this->db->get_results($sql); 
  77.  
  78.  
  79.  
  80. // Add the admin bar menu item 
  81. function add_admin_bar_enabled_item( $wp_admin_bar ) { 
  82.  
  83. global $M_options; 
  84.  
  85. $active = M_get_membership_active(); 
  86.  
  87. $title = __('Membership', 'membership') . " : <span style='color:red; text-shadow: 1px 1px 0 #000;'>" . __('Disabled', 'membership') . "</span>"; 
  88. $metatitle = __('Click to Enable the Membership protection', 'membership'); 
  89. $linkurl = wp_nonce_url(admin_url("admin.php?page=membership&action=activate"), 'toggle-plugin'); 
  90. $wp_admin_bar->add_menu( array( 
  91. 'id' => 'membership',  
  92. 'parent' => 'top-secondary',  
  93. 'title' => $title,  
  94. 'href' => $linkurl,  
  95. 'meta' => array( 
  96. 'class' => '',  
  97. 'title' => $metatitle,  
  98. ),  
  99. ) ); 
  100.  
  101.  
  102. $linkurl = wp_nonce_url(admin_url("admin.php?page=membership&action=activate"), 'toggle-plugin'); 
  103. $wp_admin_bar->add_menu( array( 
  104. 'parent' => 'membership',  
  105. 'id' => 'membershipenable',  
  106. 'title' => __('Enable Membership', 'membership'),  
  107. 'href' => $linkurl,  
  108. ) ); 
  109.  
  110.  
  111. function switch_membership_level() { 
  112.  
  113. if(isset($_GET['level_id'])) { 
  114. $level_id = (int) $_GET['level_id']; 
  115. check_admin_referer( 'membershipuselevel-' . $level_id ); 
  116.  
  117. @setcookie('membershipuselevel', $level_id, 0, COOKIEPATH, COOKIE_DOMAIN); 
  118.  
  119. wp_safe_redirect( wp_get_referer() ); 
  120.  
  121.  
  122. function add_admin_bar_view_site_as( $wp_admin_bar ) { 
  123.  
  124. global $M_options; 
  125.  
  126. $levels = $this->get_membership_levels( array( 'level_id' => 'active', 'order_by' => 'order_id' ) ); 
  127.  
  128. $title = __('View site as : ', 'membership'); 
  129. if(empty($_COOKIE['membershipuselevel']) || $_COOKIE['membershipuselevel'] == '0') { 
  130. $title .= __('Membership Admin', 'membership'); 
  131. } else { 
  132. $level_id = (int) $_COOKIE['membershipuselevel']; 
  133. $level = new M_Level( $level_id ); 
  134. $title .= $level->level_title(); 
  135. $class = apply_filters('membership_adminbar_view_site_as_class', 'membership-view-site-as'); 
  136. $metatitle = __('Select a level to view your site as', 'membership'); 
  137. $linkurl = ''; // No link for the main menu 
  138. $wp_admin_bar->add_menu( array( 
  139. 'id' => 'membershipuselevel',  
  140. 'parent' => 'top-secondary',  
  141. 'title' => $title,  
  142. 'href' => $linkurl,  
  143. 'meta' => array( 
  144. 'class' => $class,  
  145. 'title' => $metatitle,  
  146. ),  
  147. ) ); 
  148.  
  149. if(!empty($levels)) { 
  150. foreach( $levels as $key => $level ) { 
  151. $linkurl = wp_nonce_url(admin_url("admin.php?page=membership&action=membershipuselevel&level_id=" . $level->id), 'membershipuselevel-' . $level->id); 
  152. $wp_admin_bar->add_menu( array( 
  153. 'parent' => 'membershipuselevel',  
  154. 'id' => 'membershipuselevel-' . $level->id,  
  155. 'title' => $level->level_title,  
  156. 'href' => $linkurl 
  157. ) ); 
  158.  
  159. if(empty($_COOKIE['membershipuselevel']) || $_COOKIE['membershipuselevel'] == '0') { 
  160. } else { 
  161. $linkurl = wp_nonce_url(admin_url("admin.php?page=membership&action=membershipuselevel&level_id=0"), 'membershipuselevel-0'); 
  162. $wp_admin_bar->add_menu( array( 
  163. 'parent' => 'membershipuselevel',  
  164. 'id' => 'membershipuselevel-0',  
  165. 'title' => __('Reset', 'membership'),  
  166. 'href' => $linkurl 
  167. ) ); 
  168.  
  169.  
  170.  
  171. function add_admin_bar_items() { 
  172.  
  173. global $M_options, $user; 
  174.  
  175. if(empty($user) || !method_exists($user, 'has_cap')) { 
  176. $user = wp_get_current_user(); 
  177.  
  178. if(!method_exists($user, 'has_cap') || $user->has_cap('membershipadmin')) { 
  179. $active = M_get_membership_active(); 
  180.  
  181. if($active == 'yes') { 
  182. add_action( 'admin_bar_menu', array( &$this, 'add_admin_bar_view_site_as' ), 8 ); 
  183. } else { 
  184. add_action( 'admin_bar_menu', array( &$this, 'add_admin_bar_enabled_item' ), 8 ); 
  185.  
  186.  
  187.