MS_Helper_ListTable_Membership

Membership List Table.

Defined (1)

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

/app/helper/listtable/class-ms-helper-listtable-membership.php  
  1. class MS_Helper_ListTable_Membership extends MS_Helper_ListTable { 
  2.  
  3. protected $id = 'membership'; 
  4.  
  5. public function __construct() { 
  6. parent::__construct( 
  7. array( 
  8. 'singular' => 'membership',  
  9. 'plural' => 'memberships',  
  10. 'ajax' => false,  
  11. ); 
  12.  
  13. public function get_columns() { 
  14. $columns = array( 
  15. 'priority' => sprintf( 
  16. '<span title="%s">#</span>',  
  17. __( 'Membership Order', 'membership2' ) 
  18. ),  
  19. 'name' => __( 'Membership Name', 'membership2' ),  
  20. 'active' => __( 'Active', 'membership2' ),  
  21. 'type_description' => __( 'Type of Membership', 'membership2' ),  
  22. 'members' => __( 'Members', 'membership2' ),  
  23. 'price' => __( 'Payment', 'membership2' ),  
  24. 'shortcode' => __( 'Shortcodes', 'membership2' ),  
  25. ); 
  26.  
  27. return apply_filters( 
  28. 'membership_helper_listtable_membership_columns',  
  29. $columns 
  30. ); 
  31.  
  32. public function get_hidden_columns() { 
  33. return apply_filters( 
  34. 'membership_helper_listtable_membership_hidden_columns',  
  35. array() 
  36. ); 
  37.  
  38. public function get_sortable_columns() { 
  39. return apply_filters( 
  40. 'membership_helper_listtable_membership_sortable_columns',  
  41. array( 
  42. 'priority' => array( 'menu_order', true ),  
  43. 'name' => array( 'name', true ),  
  44. 'type_description' => array( 'type', true ),  
  45. 'active' => array( 'active', true ),  
  46. ); 
  47.  
  48. public function prepare_items() { 
  49. $this->_column_headers = array( 
  50. $this->get_columns(),  
  51. $this->get_hidden_columns(),  
  52. $this->get_sortable_columns(),  
  53. ); 
  54.  
  55. $args = array(); 
  56.  
  57. if ( ! empty( $_REQUEST['orderby'] ) && ! empty( $_REQUEST['order'] ) ) { 
  58. $args['orderby'] = $_REQUEST['orderby']; 
  59. $args['order'] = $_REQUEST['order']; 
  60.  
  61. // Prepare order by statement. 
  62. if ( ! empty( $args['orderby'] ) 
  63. && property_exists( 'MS_Model_Membership', $args['orderby'] ) 
  64. ) { 
  65. $args['meta_key'] = $args['orderby']; 
  66. $args['orderby'] = 'meta_value'; 
  67.  
  68. $this->items = apply_filters( 
  69. 'membership_helper_listtable_membership_items',  
  70. MS_Model_Membership::get_memberships( $args ) 
  71. ); 
  72.  
  73. public function column_priority( $item ) { 
  74. $result = '-'; 
  75.  
  76. if ( ! $item->is_system() ) { 
  77. $result = $item->priority; 
  78.  
  79. return $result; 
  80.  
  81. public function column_name( $item ) { 
  82. $actions = array(); 
  83.  
  84. // Prepare the Membership actions. 
  85. $actions['edit'] = sprintf( 
  86. '<a href="?page=%1$s&step=%2$s&tab=%3$s&membership_id=%4$s">%5$s</a>',  
  87. esc_attr( $_REQUEST['page'] ),  
  88. MS_Controller_Membership::STEP_EDIT,  
  89. MS_Controller_Membership::TAB_DETAILS,  
  90. esc_attr( $item->id ),  
  91. __( 'Edit', 'membership2' ) 
  92. ); 
  93.  
  94. if ( ! $item->is_system() ) { 
  95. $actions['payment'] = sprintf( 
  96. '<a href="?page=%1$s&step=%2$s&tab=%3$s&membership_id=%4$s">%5$s</a>',  
  97. esc_attr( $_REQUEST['page'] ),  
  98. MS_Controller_Membership::STEP_EDIT,  
  99. MS_Controller_Membership::TAB_PAYMENT,  
  100. esc_attr( $item->id ),  
  101. $item->is_free ? __( 'Access options', 'membership2' ) : __( 'Payment options', 'membership2' ) 
  102. ); 
  103.  
  104. $actions['delete'] = sprintf( 
  105. '<span class="delete"><a href="%s">%s</a></span>',  
  106. wp_nonce_url( 
  107. sprintf( 
  108. '?page=%1$s&membership_id=%2$s&action=%3$s',  
  109. esc_attr( $_REQUEST['page'] ),  
  110. esc_attr( $item->id ),  
  111. 'delete' 
  112. ),  
  113. 'delete' 
  114. ),  
  115. __( 'Delete', 'membership2' ) 
  116. ); 
  117.  
  118. $actions = apply_filters( 
  119. 'ms_helper_listtable_membership_column_name_actions',  
  120. $actions,  
  121. $item 
  122. ); 
  123.  
  124. // Add the badge to special memberships. 
  125. if ( $item->is_guest() ) { 
  126. $badge = sprintf( 
  127. '<span class="ms-badge ms-guest-badge" data-wpmui-tooltip="%2$s" data-width="180">%1$s</span>',  
  128. __( 'Guest', 'membership2' ),  
  129. __( 'All Logged-Out users are considered guests', 'membership2' ) 
  130. ); 
  131. } elseif ( $item->is_user() ) { 
  132. $badge = sprintf( 
  133. '<span class="ms-badge ms-user-badge" data-wpmui-tooltip="%2$s" data-width="180">%1$s</span>',  
  134. __( 'Default', 'membership2' ),  
  135. __( 'All logged-in users that have not signed up for any membership', 'membership2' ) 
  136. ); 
  137. } else { 
  138. $badge = apply_filters( 
  139. 'ms_helper_listtable_memberships_name_badge',  
  140. '',  
  141. $item,  
  142. $this 
  143. ); 
  144.  
  145. return sprintf( 
  146. '<span class="ms-color" style="background-color:%4$s"> </span> ' . 
  147. '<a href="?page=%5$s&step=%6$s&membership_id=%7$s" class="the-name">%1$s</a> ' . 
  148. '%3$s%2$s',  
  149. esc_html( $item->name ), // 1 
  150. $this->row_actions( $actions ), // 2 
  151. $badge, // 3 
  152. $item->get_color(), // 4 
  153. esc_attr( $_REQUEST['page'] ), // 5 
  154. MS_Controller_Membership::STEP_OVERVIEW, // 6 
  155. esc_attr( $item->id ) // 7 
  156. ); 
  157.  
  158. public function column_active( $item ) { 
  159. $toggle = array( 
  160. 'id' => 'ms-toggle-' . $item->id,  
  161. 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER,  
  162. 'value' => $item->active,  
  163. 'data_ms' => array( 
  164. 'action' => MS_Controller_Membership::AJAX_ACTION_TOGGLE_MEMBERSHIP,  
  165. 'field' => 'active',  
  166. 'membership_id' => $item->id,  
  167. ),  
  168. ); 
  169.  
  170. $html = MS_Helper_Html::html_element( $toggle, true ); 
  171.  
  172. return $html; 
  173.  
  174. public function column_members( $item, $column_name ) { 
  175. $html = ''; 
  176.  
  177. if ( ! $item->is_system() ) { 
  178. $count = $item->get_members_count(); 
  179.  
  180. $url = MS_Controller_Plugin::get_admin_url( 
  181. 'members',  
  182. array( 'membership_id' => $item->id ) 
  183. ); 
  184.  
  185. $html = sprintf( 
  186. '<a href="%2$s">%1$s</a>',  
  187. intval( $count ),  
  188. $url 
  189. ); 
  190.  
  191. return $html; 
  192.  
  193. public function column_type_description( $item, $column_name ) { 
  194. $html = ''; 
  195.  
  196. $html .= sprintf( 
  197. '<span class="ms-img-type ms-img-type-%1$s small"></span> ',  
  198. esc_attr( $item->type ) 
  199. ); 
  200.  
  201. $desc = $item->type_description; 
  202. if ( ! empty( $desc ) ) { 
  203. $html .= sprintf( 
  204. '<span class="ms-type-desc ms-%1$s">%2$s</span>',  
  205. esc_attr( $item->type ),  
  206. $desc 
  207. ); 
  208.  
  209. if ( ! $item->is_system() && $item->private ) { 
  210. $html .= sprintf( 
  211. '<span class="ms-is-private">, <span>%1$s</span></span>',  
  212. __( 'Private', 'membership2' ) 
  213. ); 
  214.  
  215. return $html; 
  216.  
  217. public function column_price( $item, $column_name ) { 
  218. $html = ''; 
  219.  
  220. if ( ! $item->is_system() ) { 
  221. if ( ! $item->is_free() ) { 
  222. $html = sprintf( 
  223. '<span class="ms-currency">%1$s</span> <span class="ms-price">%2$s</span> (<span class="ms-payment">%3$s</span>)',  
  224. MS_Plugin::instance()->settings->currency_symbol,  
  225. MS_Helper_Billing::format_price( $item->price ),  
  226. $item->get_payment_type_desc() 
  227. ); 
  228. $html = '<span class="ms-bold">' . $html . '</span>'; 
  229. } else { 
  230. $html = sprintf( 
  231. '<span class="ms-bold">%1$s</span> (<span class="ms-payment">%2$s</span>)',  
  232. __( 'Free', 'membership2' ),  
  233. $item->get_payment_type_desc() 
  234. ); 
  235.  
  236. $followup = MS_Factory::load( 
  237. 'MS_Model_Membership',  
  238. $item->on_end_membership_id 
  239. ); 
  240.  
  241. if ( $followup->is_valid() ) { 
  242. $html .= '<div class="ms-followup">' . sprintf( 
  243. __( 'Follow with: %1$s', 'membership2' ),  
  244. '<span class="ms-color" style="background:' . $followup->get_color() . '"> </span>' . $followup->name 
  245. ) . '</div>'; 
  246.  
  247. return $html; 
  248.  
  249. public function column_shortcode( $item, $column_name ) { 
  250. $shortcodes = array( 
  251. MS_Rule_Shortcode_Model::PROTECT_CONTENT_SHORTCODE => array( 
  252. 'tag' => '[%1$s id="%2$s"][/%1$s]',  
  253. 'label' => __( 'Protect content', 'membership2' ),  
  254. ),  
  255. MS_Helper_Shortcode::SCODE_MS_TITLE => array( 
  256. 'tag' => '[%1$s id="%2$s"]',  
  257. 'label' => __( 'Membership Title', 'membership2' ),  
  258. ),  
  259. MS_Helper_Shortcode::SCODE_MS_DETAILS => array( 
  260. 'tag' => '[%1$s id="%2$s"]',  
  261. 'label' => __( 'Membership Description', 'membership2' ),  
  262. ),  
  263. MS_Helper_Shortcode::SCODE_MS_PRICE => array( 
  264. 'tag' => '[%1$s id="%2$s"]',  
  265. 'label' => __( 'Membership Price', 'membership2' ),  
  266. ),  
  267. MS_Helper_Shortcode::SCODE_MS_BUY => array( 
  268. 'tag' => '[%1$s id="%2$s"]',  
  269. 'label' => __( 'Subscribe Button', 'membership2' ),  
  270. ),  
  271. MS_Helper_Shortcode::SCODE_REGISTER_USER => array( 
  272. 'tag' => '[%1$s membership_id="%2$s"]',  
  273. 'label' => __( 'Registration form', 'membership2' ),  
  274. ),  
  275. ); 
  276. if ( $item->is_system() ) { 
  277. unset( $shortcodes[MS_Helper_Shortcode::SCODE_MS_TITLE] ); 
  278. unset( $shortcodes[MS_Helper_Shortcode::SCODE_MS_DETAILS] ); 
  279. unset( $shortcodes[MS_Helper_Shortcode::SCODE_MS_PRICE] ); 
  280. unset( $shortcodes[MS_Helper_Shortcode::SCODE_MS_BUY] ); 
  281. unset( $shortcodes[MS_Helper_Shortcode::SCODE_REGISTER_USER] ); 
  282.  
  283. $shortcodes = apply_filters( 
  284. 'ms_helper_listtable_membership_shortcodes',  
  285. $shortcodes,  
  286. $item 
  287. ); 
  288.  
  289. $lines = array(); 
  290. foreach ( $shortcodes as $code => $details ) { 
  291. $lines[] = sprintf( 
  292. '<div>%s: <code>%s</code></div>',  
  293. $details['label'],  
  294. sprintf( 
  295. $details['tag'],  
  296. $code,  
  297. esc_attr( $item->id ) 
  298. ); 
  299.  
  300. $html = sprintf( 
  301. '<div class="ms-shortcodes"><span class="ms-trigger"><span class="label">%s</span><div class="inner">%s</div></span></div>',  
  302. __( 'Show', 'membership2' ) . ' <i class="wpmui-fa wpmui-fa-caret-down"></i>',  
  303. implode( '', $lines ) 
  304. ); 
  305.  
  306. return $html; 
  307.  
  308. public function get_bulk_actions() { 
  309. return apply_filters( 
  310. 'ms_helper_listtable_membership_bulk_actions',  
  311. array() 
  312. );