/app/rule/menuitem/class-ms-rule-menuitem-listtable.php

  1. <?php 
  2. /** 
  3. * Membership List Table 
  4. * 
  5. * @since 1.0.0 
  6. */ 
  7. class MS_Rule_MenuItem_ListTable extends MS_Helper_ListTable_Rule { 
  8.  
  9. protected $id = MS_Rule_MenuItem::RULE_ID; 
  10.  
  11. /** 
  12. * A list of all available menus. 
  13. * 
  14. * @var array 
  15. */ 
  16. protected $menus; 
  17.  
  18. /** 
  19. * The currently selected menu-ID. 
  20. * 
  21. * @var int 
  22. */ 
  23. protected $menu_id; 
  24.  
  25. public function __construct( $model, $all_menus, $menu_id ) { 
  26. parent::__construct( $model ); 
  27. $this->menus = $all_menus; 
  28. $this->menu_id = $menu_id; 
  29. $this->name['singular'] = __( 'Menu Item', 'membership2' ); 
  30. $this->name['plural'] = __( 'Menu Items', 'membership2' ); 
  31.  
  32. public function get_columns() { 
  33. $columns = array( 
  34. 'cb' => true,  
  35. 'title' => __( 'Menu Title', 'membership2' ),  
  36. 'type' => __( 'Menu Type', 'membership2' ),  
  37. 'access' => true,  
  38. ); 
  39.  
  40. return apply_filters( 
  41. 'membership_helper_listtable_' . $this->id . '_columns',  
  42. $columns 
  43. ); 
  44.  
  45. public function prepare_items_args( $defaults ) { 
  46. $args = apply_filters( 
  47. 'ms_rule_menuitem_listtable_prepare_items_args',  
  48. array( 'menu_id' => $this->menu_id ) 
  49. ); 
  50.  
  51. return wp_parse_args( $args, $defaults ); 
  52.  
  53. public function column_title( $item, $column_name ) { 
  54. return $item->title; 
  55.  
  56. public function column_type( $item, $column_name ) { 
  57. return $item->type_label; 
  58.  
  59. /** 
  60. * No pagination for this rule 
  61. * 
  62. * @since 1.0.0 
  63. * @return int 
  64. */ 
  65. protected function get_items_per_page( $option, $default_value = null ) { 
  66. return 0; 
  67.  
  68. /** 
  69. * Return true if the current list is a view except "all" 
  70. * 
  71. * @since 1.0.0 
  72. * @return bool 
  73. */ 
  74. public function is_view() { 
  75. return true; 
  76.  
  77. /** 
  78. * The rule uses the view-filter to select the menu to protect 
  79. * 
  80. * @since 1.0.0 
  81. */ 
  82. public function get_views() { 
  83. $views = $this->menus; 
  84. $views[$this->menu_id]['current'] = true; 
  85.  
  86. return $views; 
  87.  
.