M_Menu

The Membership 2 M Menu class.

Defined (1)

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

/app_old/membershipincludes/includes/default.rules.php  
  1. class M_Menu extends M_Rule { 
  2.  
  3. var $name = 'menu'; 
  4. var $label = 'Menu'; 
  5. var $description = 'Allows specific menu items to be protected.'; 
  6.  
  7. var $rulearea = 'public'; 
  8.  
  9. function admin_main($data) { 
  10. if(!$data) $data = array(); 
  11. ?> 
  12. <div class='level-operation' id='main-menu'> 
  13. <h2 class='sidebar-name'><?php _e('Menu', 'membership');?><span><a href='#remove' id='remove-menu' class='removelink' title='<?php _e("Remove Menu from this rules area.", 'membership'); ?>'><?php _e('Remove', 'membership'); ?></a></span></h2> 
  14. <div class='inner-operation'> 
  15. <p><?php _e('Select the Menu items to be covered by this rule by checking the box next to the relevant menu labels.', 'membership'); ?></p> 
  16. <?php 
  17.  
  18. $navs = wp_get_nav_menus( array('orderby' => 'name') ); 
  19.  
  20. if(!empty($navs)) { 
  21. ?> 
  22. <table cellspacing="0" class="widefat fixed"> 
  23. <thead> 
  24. <tr> 
  25. <th style="" class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox"></th> 
  26. <th style="" class="manage-column column-name" id="name" scope="col"><?php _e('Menu / Item title', 'membership'); ?></th> 
  27. </tr> 
  28. </thead> 
  29.  
  30. <tfoot> 
  31. <tr> 
  32. <th style="" class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox"></th> 
  33. <th style="" class="manage-column column-name" id="name" scope="col"><?php _e('Menu / Item title', 'membership'); ?></th> 
  34. </tr> 
  35. </tfoot> 
  36.  
  37. <tbody> 
  38. <?php 
  39. foreach($navs as $key => $nav) { 
  40. ?> 
  41. <tr valign="middle" class="alternate" id="menu-<?php echo $nav->term_id; ?>-0"> 
  42. <td class="column-name" colspan='2'> 
  43. <strong><?php echo __('MENU', 'membership') . " - " . esc_html($nav->name); ?></strong> 
  44. </td> 
  45. </tr> 
  46. <?php 
  47. $items = wp_get_nav_menu_items($nav->term_id); 
  48. if(!empty($items)) { 
  49. foreach($items as $ikey => $item) { 
  50. ?> 
  51. <tr valign="middle" class="alternate" id="menu-<?php //echo $nav->term_id . '-'; ?><?php echo $item->ID; ?>"> 
  52. <th class="check-column" scope="row"> 
  53. <input type="checkbox" value="<?php //echo $nav->term_id . '-'; ?><?php echo $item->ID; ?>" name="menu[]" <?php if(in_array($item->ID, $data)) echo 'checked="checked"'; ?>> 
  54. </th> 
  55. <td class="column-name"> 
  56.  
  57. <strong> – <?php if($item->menu_item_parent != 0) echo "– "; ?><?php echo esc_html($item->title); ?></strong> 
  58. </td> 
  59. </tr> 
  60. <?php 
  61. ?> 
  62. </tbody> 
  63. </table> 
  64. <?php 
  65. ?> 
  66. </div> 
  67. </div> 
  68. <?php 
  69.  
  70. function on_positive($data) { 
  71.  
  72. $this->data = $data; 
  73.  
  74. add_filter( 'wp_get_nav_menu_items', array(&$this, 'filter_viewable_menus'), 10, 3 ); 
  75.  
  76.  
  77. function on_negative($data) { 
  78.  
  79. $this->data = $data; 
  80.  
  81. add_filter( 'wp_get_nav_menu_items', array(&$this, 'filter_unviewable_menus'), 10, 3 ); 
  82.  
  83. function filter_viewable_menus($items, $menu, $args) { 
  84.  
  85. if(!empty($items)) { 
  86. foreach($items as $key => $item) { 
  87. if(!in_array($item->ID, $this->data) || ($item->menu_item_parent != 0 && !in_array($item->menu_item_parent, $this->data))) { 
  88. unset($items[$key]); 
  89.  
  90.  
  91. return $items; 
  92.  
  93.  
  94. function filter_unviewable_menus($items, $menu, $args) { 
  95.  
  96. if(!empty($items)) { 
  97. foreach($items as $key => $item) { 
  98. if(in_array($item->ID, $this->data) || ($item->menu_item_parent != 0 && in_array($item->menu_item_parent, $this->data))) { 
  99. unset($items[$key]); 
  100.  
  101.  
  102. return $items; 
  103.  
  104.