/app/controller/class-ms-controller-member.php

  1. <?php 
  2. /** 
  3. * Controller for managing Members and Membership relationships. 
  4. * 
  5. * Manages the Member and the member's Memberships. 
  6. * 
  7. * @since 1.0.0 
  8. * 
  9. * @package Membership2 
  10. * @subpackage Controller 
  11. */ 
  12. class MS_Controller_Member extends MS_Controller { 
  13.  
  14. /** 
  15. * AJAX action constant: Edit subscriptions of a single member. 
  16. * 
  17. * @since 1.0.0 
  18. * 
  19. * @var string 
  20. */ 
  21. const AJAX_ACTION_CHANGE_MEMBERSHIPS = 'member_subscriptions'; 
  22.  
  23. /** 
  24. * AJAX action constant: Validate a user field before creating the user. 
  25. * 
  26. * @since 1.0.1.0 
  27. * 
  28. * @var string 
  29. */ 
  30. const AJAX_ACTION_VALIDATE_FIELD = 'member_validate_field'; 
  31.  
  32. /** 
  33. * AJAX action constant: Search users via Ajax. 
  34. * 
  35. * @since 1.0.1.0 
  36. * 
  37. * @var string 
  38. */ 
  39. const AJAX_ACTION_SEARCH = 'member_search'; 
  40.  
  41. /** 
  42. * Used on the Add Member screen to indicate that a new WP User should be 
  43. * created and added to M2. 
  44. * 
  45. * @since 1.0.1.0 
  46. * 
  47. * @var string 
  48. */ 
  49. const ACTION_ADD_MEMBER = 'member_add'; 
  50.  
  51. /** 
  52. * Used on the Add Member screen to indicate that the submitted form details 
  53. * should update an existing user. 
  54. * 
  55. * @since 1.0.1.0 
  56. * 
  57. * @var string 
  58. */ 
  59. const ACTION_UPDATE_MEMBER = 'member_update'; 
  60.  
  61. /** 
  62. * Used on the Add Member screen to trigger a new subscription action for an 
  63. * existing user (user subscribes to one or multiple memberships) 
  64. * 
  65. * @since 1.0.1.0 
  66. * 
  67. * @var string 
  68. */ 
  69. const ACTION_MODIFY_SUBSCRIPTIONS = 'member_subscription'; 
  70.  
  71. /** 
  72. * Used on the Add Member screen to indicate that an existing WP User should 
  73. * be added to M2. 
  74. * 
  75. * @since 1.0.1.0 
  76. * 
  77. * @var string 
  78. */ 
  79. const ACTION_SELECT_MEMBER = 'member_select'; 
  80.  
  81. /** 
  82. * Prepare the Member manager. 
  83. * 
  84. * @since 1.0.0 
  85. */ 
  86. public function __construct() { 
  87. parent::__construct(); 
  88.  
  89. $this->add_action( 
  90. 'ms_controller_membership_setup_completed',  
  91. 'add_current_user' 
  92. ); 
  93.  
  94. $this->add_ajax_action( 
  95. self::AJAX_ACTION_CHANGE_MEMBERSHIPS,  
  96. 'ajax_action_change_memberships' 
  97. ); 
  98.  
  99. $this->add_ajax_action( 
  100. self::AJAX_ACTION_VALIDATE_FIELD,  
  101. 'ajax_action_validate_field' 
  102. ); 
  103.  
  104. $this->add_ajax_action( 
  105. self::AJAX_ACTION_SEARCH,  
  106. 'ajax_action_search' 
  107. ); 
  108.  
  109. $this->add_action( 
  110. 'delete_user',  
  111. 'remove_membership_from_user' 
  112. ); 
  113.  
  114. $this->add_filter( 'set-screen-option', array($this, 'members_admin_page_set_screen_option') , 10, 3); 
  115.  
  116.  
  117. /** 
  118. * Initialize the admin-side functions. 
  119. * 
  120. * @since 1.0.0 
  121. */ 
  122. public function admin_init() { 
  123. $hooks = array( 
  124. 'list' => MS_Controller_Plugin::admin_page_hook( 'members' ),  
  125. 'editor' => MS_Controller_Plugin::admin_page_hook( 'add-member' ),  
  126. ); 
  127.  
  128. $this->add_action( 'load-' . $hooks['list'], 'members_admin_page_screen_option' ); 
  129.  
  130. foreach ( $hooks as $key => $hook ) { 
  131. $this->run_action( 'load-' . $hook, 'members_admin_page_process_' . $key ); 
  132. $this->run_action( 'admin_print_scripts-' . $hook, 'enqueue_scripts_' . $key ); 
  133. $this->run_action( 'admin_print_styles-' . $hook, 'enqueue_styles' ); 
  134.  
  135. /** 
  136. * Add the current user to the Members-List. 
  137. * 
  138. * This does NOT assign any membership to the user, but ensures that the 
  139. * admin user appears in the Members-List 
  140. * 
  141. * @since 1.0.0 
  142. */ 
  143. public function add_current_user() { 
  144. $member = MS_Factory::load( 
  145. 'MS_Model_Member',  
  146. get_current_user_id() 
  147. ); 
  148.  
  149. $member->is_member = true; 
  150. $member->save(); 
  151.  
  152. /** 
  153. * Remove membership for an user 
  154. * 
  155. * @since 1.0.3 
  156. */ 
  157. public function remove_membership_from_user( $user_id ) 
  158. $member = MS_Factory::load( 'MS_Model_Member', $user_id ); 
  159. $memberships_ids = (array) $member->get_membership_ids(); 
  160.  
  161. if( ! empty( $memberships_ids ) ) 
  162. foreach( $memberships_ids as $memberships_id ) 
  163. $member->drop_membership( $memberships_id ); 
  164.  
  165. /** 
  166. * Add pagination members screen option 
  167. * 
  168. * @since 1.0.3 
  169. */ 
  170. function members_admin_page_screen_option() { 
  171. $option = 'per_page'; 
  172. $args = array( 
  173. 'label' => 'Members',  
  174. 'default' => 20,  
  175. 'option' => 'members_per_page' 
  176. ); 
  177.  
  178. add_screen_option( $option, $args ); 
  179. }  
  180.  
  181. /** 
  182. * Set pagination members screen option 
  183. * 
  184. * @since 1.0.3 
  185. */ 
  186. public static function members_admin_page_set_screen_option( $status, $option, $value ) { 
  187. return $value; 
  188. }  
  189.  
  190.  
  191. /** 
  192. * Manages membership actions. 
  193. * 
  194. * Verifies GET and POST requests to manage members 
  195. * 
  196. * @since 1.0.0 
  197. */ 
  198. public function members_admin_page_process_list() { 
  199. $msg = 0; 
  200. $redirect = false; 
  201.  
  202. if ( $this->is_admin_user() ) { 
  203. $fields_new = array( 'new_member', 'action' ); 
  204. $fields_edit = array( 'member_id', 'action' ); 
  205.  
  206. // Execute list table single action. 
  207. if ( $this->verify_nonce( null, 'GET' ) 
  208. && self::validate_required( $fields_edit, 'GET' ) 
  209. ) { 
  210. $msg = $this->member_list_do_action( 
  211. $_GET['action'],  
  212. array( $_GET['member_id'] ) 
  213. ); 
  214.  
  215. $redirect = esc_url_raw( 
  216. add_query_arg( 
  217. array( 'msg' => $msg ),  
  218. remove_query_arg( 
  219. array( 'member_id', 'action', '_wpnonce' ) 
  220. ); 
  221.  
  222. // Execute list table bulk actions. 
  223. elseif ( $this->verify_nonce( 'bulk' ) ) { 
  224. lib3()->array->equip_post( 'action', 'action2', 'member_id' ); 
  225. $action = $_POST['action']; 
  226. if ( empty( $action ) || $action == '-1' ) { 
  227. $action = $_POST['action2']; 
  228. $members = $_POST['member_id']; 
  229.  
  230. /** 
  231. * The Bulk-Edit action is built like 'cmd-id' 
  232. * e.g. 'add-123' will add membership 123 to the selected items. 
  233. */ 
  234. if ( empty( $action ) ) { 
  235. $cmd = array(); 
  236. } elseif ( empty( $members ) ) { 
  237. $cmd = array(); 
  238. } elseif ( '-1' == $action ) { 
  239. $cmd = array(); 
  240. } else { 
  241. $cmd = explode( '-', $action ); 
  242.  
  243. if ( 2 == count( $cmd ) ) { 
  244. $action = $cmd[0]; 
  245. $action_id = $cmd[1]; 
  246.  
  247. // Get a list of specified memberships... 
  248. if ( is_numeric( $action_id ) ) { 
  249. // ... either a single membership. 
  250. $memberships = array( 
  251. MS_Factory::load( 'MS_Model_Membership', $action_id ),  
  252. ); 
  253. } elseif ( 'all' == $action_id ) { 
  254. // ... or all memberships. 
  255. $memberships = MS_Model_Membership::get_memberships(); 
  256.  
  257. // Loop defined memberships and add/remove members. 
  258. foreach ( $memberships as $membership ) { 
  259. $msg = $this->member_list_do_action( 
  260. $action,  
  261. $members,  
  262. $membership->id 
  263. ); 
  264.  
  265. $redirect = esc_url_raw( 
  266. add_query_arg( array( 'msg' => $msg ) ) 
  267. ); 
  268.  
  269. // Execute edit view page action submit. 
  270. elseif ( isset( $_POST['submit'] ) 
  271. && $this->verify_nonce() 
  272. && self::validate_required( $fields_edit, 'POST' ) 
  273. ) { 
  274. if ( is_array( $_POST['member_id'] ) ) { 
  275. $member_ids = $_POST['member_id']; 
  276. } else { 
  277. $member_ids = explode( ', ', $_POST['member_id'] ); 
  278.  
  279. $msg = $this->member_list_do_action( 
  280. $_POST['action'],  
  281. $member_ids,  
  282. $_POST['membership_id'] 
  283. ); 
  284.  
  285. $redirect = esc_url_raw( 
  286. add_query_arg( array( 'msg' => $msg ) ) 
  287. ); 
  288.  
  289. if ( $redirect ) { 
  290. wp_safe_redirect( $redirect ); 
  291. exit; 
  292.  
  293. /** 
  294. * Manages membership actions for the ADD/EDIT screen. 
  295. * 
  296. * @since 1.0.1.0 
  297. */ 
  298. public function members_admin_page_process_editor() { 
  299. $msg = 0; 
  300. $redirect = false; 
  301.  
  302. if ( $this->is_admin_user() ) { 
  303. $fields_add = array( 'username', 'email' ); 
  304. $fields_select = array( 'user_id' ); 
  305. $fields_update = array( 'user_id', 'email' ); 
  306. $fields_modify = array( 'user_id', 'memberships' ); 
  307. $fields_subscribe = array( 'user_id', 'subscribe' ); 
  308.  
  309. // Process Action: Create new user. 
  310. if ( isset( $_POST['btn_create'] ) 
  311. && $this->verify_nonce() 
  312. && self::validate_required( $fields_add, 'POST' ) 
  313. ) { 
  314. $data = array( 
  315. 'user_login' => $_POST['username'],  
  316. 'user_email' => $_POST['email'],  
  317. 'first_name' => $_POST['first_name'],  
  318. 'last_name' => $_POST['last_name'],  
  319. 'user_pass' => $_POST['password'],  
  320. ); 
  321. $user_id = wp_insert_user( $data ); 
  322.  
  323. if ( ! is_wp_error( $user_id ) ) { 
  324. $redirect = esc_url_raw( 
  325. add_query_arg( array( 'user_id' => $user_id ) ) 
  326. ); 
  327.  
  328. // Process Action: Select existing user. 
  329. elseif ( isset( $_POST['btn_select'] ) 
  330. && $this->verify_nonce() 
  331. && self::validate_required( $fields_select, 'POST' ) 
  332. ) { 
  333. $user_id = intval( $_POST['user_id'] ); 
  334.  
  335. $redirect = esc_url_raw( 
  336. add_query_arg( array( 'user_id' => $user_id ) ) 
  337. ); 
  338.  
  339. // Process Action: Update existing user. 
  340. elseif ( isset( $_POST['btn_save'] ) 
  341. && $this->verify_nonce() 
  342. && self::validate_required( $fields_update, 'POST' ) 
  343. ) { 
  344. $data = array( 
  345. 'ID' => intval( $_POST['user_id'] ),  
  346. 'user_email' => $_POST['email'],  
  347. 'first_name' => $_POST['first_name'],  
  348. 'last_name' => $_POST['last_name'],  
  349. 'display_name' => $_POST['displayname'],  
  350. ); 
  351. wp_update_user( $data ); 
  352.  
  353. // Process Action: Subscribe to a new membership. 
  354. elseif ( isset( $_POST['btn_modify'] ) 
  355. && $this->verify_nonce() 
  356. ) { 
  357. // REQUEST here: When editing a user the ID is sent in the URL. 
  358. $user_id = intval( $_REQUEST['user_id'] ); 
  359. $user = MS_Factory::load( 'MS_Model_Member', $user_id ); 
  360. // We don't need need user_id here as this is an user modification 
  361. $fields_modify = array( 'memberships' ); 
  362.  
  363. // Modify existing subscriptions. 
  364. if ( self::validate_required( $fields_modify, 'POST' ) ) { 
  365. $memberships = lib3()->array->get( $_POST['memberships'] ); 
  366.  
  367. foreach ( $memberships as $membership_id ) { 
  368. if ( empty( $_POST['mem_' . $membership_id] ) ) { continue; } 
  369.  
  370. $subscription = $user->get_subscription( $membership_id ); 
  371. $data = $_POST['mem_' . $membership_id]; 
  372.  
  373. $subscription->start_date = $data['start']; 
  374. $subscription->expire_date = $data['expire']; 
  375. $subscription->status = $data['status']; 
  376. $subscription->save(); 
  377.  
  378. // Add new subscriptions. 
  379. if ( self::validate_required( $fields_subscribe, 'POST' ) ) { 
  380. $subscribe_to = $_POST['subscribe']; 
  381.  
  382. if ( MS_Model_Addon::is_enabled( MS_Model_Addon::ADDON_MULTI_MEMBERSHIPS ) ) { 
  383. // Memberships is an array. 
  384. foreach ( $subscribe_to as $membership_id ) { 
  385. $user->add_membership( $membership_id, 'admin' ); 
  386. } else { 
  387. // Memberships is a single ID. 
  388. foreach ( $user->subscriptions as $subscription ) { 
  389. $subscription->deactivate_membership( false ); 
  390. $user->add_membership( $subscribe_to, 'admin' ); 
  391.  
  392. $user->save(); 
  393.  
  394. if ( $redirect ) { 
  395. wp_safe_redirect( $redirect ); 
  396. exit; 
  397.  
  398. /** 
  399. * Show member list. 
  400. * 
  401. * Menu "All Members", show all members available. 
  402. * Called by MS_Controller_Plugin::route_submenu_request() 
  403. * 
  404. * @since 1.0.0 
  405. */ 
  406. public function admin_page() { 
  407. $data = array(); 
  408.  
  409. $view = MS_Factory::create( 'MS_View_Member_List' ); 
  410. $view->data = apply_filters( 'ms_view_member_list_data', $data ); 
  411. $view->render(); 
  412.  
  413. /** 
  414. * Show member editor. 
  415. * 
  416. * Menu "Add Member", add or edit a single member. 
  417. * Called by MS_Controller_Plugin::route_submenu_request() 
  418. * 
  419. * @since 1.0.1.0 
  420. */ 
  421. public function admin_page_editor() { 
  422. $data = array(); 
  423.  
  424. if ( ! empty( $_REQUEST['user_id'] ) && intval( $_REQUEST['user_id'] ) ) { 
  425. $data['user_id'] = intval( $_REQUEST['user_id'] ); 
  426. $data['action'] = 'edit'; 
  427. } else { 
  428. $data['user_id'] = 0; 
  429. $data['action'] = 'add'; 
  430.  
  431. $view = MS_Factory::create( 'MS_View_Member_Editor' ); 
  432. $view->data = apply_filters( 'ms_view_member_editor_data', $data ); 
  433. $view->render(); 
  434.  
  435. /** 
  436. * Handle Ajax change-memberships action. 
  437. * 
  438. * This action handler is only called by admin users via the Members admin 
  439. * page, so all memberships added here have gateway_id 'admin'. 
  440. * 
  441. * Related Action Hooks: 
  442. * - wp_ajax_change_memberships 
  443. * 
  444. * @since 1.0.0 
  445. */ 
  446. public function ajax_action_change_memberships() { 
  447. $msg = 0; 
  448. $this->_resp_reset(); 
  449.  
  450. $required = array( 'member' ); 
  451. if ( $this->_resp_ok() && ! $this->is_admin_user() ) { 
  452. $this->_resp_err( 'permission denied' ); 
  453. } elseif ( $this->_resp_ok() && ! $this->verify_nonce() ) { 
  454. $this->_resp_err( 'subscribe: nonce' ); 
  455. } elseif ( $this->_resp_ok() && ! self::validate_required( $required ) ) { 
  456. $this->_resp_err( 'subscribe: required' ); 
  457.  
  458. if ( $this->_resp_ok() ) { 
  459. $values = array(); 
  460. if ( isset( $_POST['values'] ) && is_array( $_POST['values'] ) ) { 
  461. $values = $_POST['values']; 
  462.  
  463. $msg = $this->assign_memberships( 
  464. $_POST['member'],  
  465. $values 
  466. ); 
  467. $msg .= $this->_resp_code(); 
  468.  
  469. echo $msg; 
  470. exit; 
  471.  
  472. /** 
  473. * Handle Ajax validate field action. 
  474. * 
  475. * This function should validate the field value before the user is created 
  476. * to make sure that the value is unique/valid. 
  477. * 
  478. * Related Action Hooks: 
  479. * - wp_ajax_validate_field 
  480. * 
  481. * @since 1.0.1.0 
  482. */ 
  483. public function ajax_action_validate_field() { 
  484. $msg = 0; 
  485. $this->_resp_reset(); 
  486.  
  487. $required = array( 'field', 'value' ); 
  488. if ( $this->_resp_ok() && ! $this->is_admin_user() ) { 
  489. $this->_resp_err( 'permission denied' ); 
  490. } elseif ( $this->_resp_ok() && ! self::validate_required( $required ) ) { 
  491. $this->_resp_err( __( 'This field is required.', 'membership2' ) ); 
  492.  
  493. if ( $this->_resp_ok() ) { 
  494. $field = $_POST['field']; 
  495. $value = $_POST['value']; 
  496.  
  497. if ( 'email' == $field ) { 
  498. if ( ! is_email( $value ) ) { 
  499. $msg = __( 'Invalid Email address', 'membership2' ); 
  500. } elseif ( email_exists( $value ) ) { 
  501. $msg = __( 'Email already taken', 'membership2' ); 
  502. } else { 
  503. $msg = 1; 
  504. } elseif ( 'username' == $field ) { 
  505. if ( username_exists( $value ) ) { 
  506. $msg = __( 'Username already taken', 'membership2' ); 
  507. } else { 
  508. $msg = 1; 
  509. $msg .= $this->_resp_code(); 
  510.  
  511. echo $msg; 
  512. exit; 
  513.  
  514. /** 
  515. * Handle Ajax search users action. 
  516. * 
  517. * Related Action Hooks: 
  518. * - wp_ajax_search 
  519. * 
  520. * @since 1.0.1.0 
  521. */ 
  522. public function ajax_action_search() { 
  523. $res = (object) array( 
  524. 'items' => array(),  
  525. 'more' => false,  
  526. ); 
  527. $this->_resp_reset(); 
  528. $items_per_page = 20; 
  529.  
  530. $required = array( 'q' ); 
  531. if ( $this->_resp_ok() && ! $this->is_admin_user() ) { 
  532. $this->_resp_err( 'permission denied' ); 
  533. } elseif ( $this->_resp_ok() && ! self::validate_required( $required, 'any' ) ) { 
  534. $this->_resp_err( 'search: required' ); 
  535. if ( empty( $_REQUEST['p'] ) ) { $_REQUEST['p'] = 0; } 
  536.  
  537. if ( $this->_resp_ok() ) { 
  538. $term = $_REQUEST['q']; 
  539. $page = max( intval( $_REQUEST['p'] ) - 1, 0 ); 
  540. $offset = $page * $items_per_page; 
  541.  
  542. $args = array( 
  543. 'search' => '*' . $term . '*',  
  544. 'offset' => $offset,  
  545. 'number' => $items_per_page + 1,  
  546. 'fields' => array( 
  547. 'ID',  
  548. 'user_login',  
  549. 'display_name',  
  550. ),  
  551. 'orderby' => 'display_name',  
  552. ); 
  553. $users = get_users( $args ); 
  554. $admins = get_users( array( 'role' => 'administrator' ) ); 
  555. $users = array_udiff( $users, $admins, array( $this, 'compare_objects' ) ); 
  556.  
  557. if ( count( $users ) > $items_per_page ) { 
  558. $res->more = true; 
  559. array_pop( $users ); 
  560.  
  561. foreach ( $users as $user ) { 
  562. $res->items[] = array( 
  563. 'id' => $user->ID,  
  564. 'text' => sprintf( 
  565. '%s (%s)',  
  566. $user->display_name,  
  567. $user->user_login 
  568. ),  
  569. ); 
  570.  
  571. echo json_encode( $res ); 
  572. exit; 
  573.  
  574. public function compare_objects( $obj_a, $obj_b ) { 
  575. return $obj_a->ID - $obj_b->ID; 
  576.  
  577. /** 
  578. * Assigns (or removes) memberships to a Member. 
  579. * 
  580. * @since 1.0.0 
  581. * 
  582. * @param string $user_id 
  583. * @param array $memberships Memberships that will be assigned to the 
  584. * rule-item. Memberships that are not mentioned are removed. 
  585. * @return string [description] 
  586. */ 
  587. private function assign_memberships( $user_id, $memberships ) { 
  588. $member = MS_Factory::load( 'MS_Model_Member', $user_id ); 
  589.  
  590. $memberships = apply_filters( 
  591. 'ms_controller_member_assign_memberships',  
  592. $memberships,  
  593. $member,  
  594. $this 
  595. ); 
  596.  
  597. // Drop memberships that are not specified 
  598. foreach ( $member->get_membership_ids() as $old_id ) { 
  599. if ( in_array( $old_id, $memberships ) ) { continue; } 
  600. $member->drop_membership( $old_id ); 
  601.  
  602. // Add new memberships 
  603. foreach ( $memberships as $membership_id ) { 
  604. $subscription = $member->add_membership( $membership_id ); 
  605.  
  606. if ( $member->has_membership() ) { 
  607. $member->is_member = true; 
  608. } else { 
  609. $member->is_member = false; 
  610. $member->save(); 
  611.  
  612. do_action( 
  613. 'ms_controller_member_assign_memberships_done',  
  614. $member,  
  615. $memberships,  
  616. $this 
  617. ); 
  618.  
  619. return MS_Helper_Membership::MEMBERSHIP_MSG_UPDATED; 
  620.  
  621. /** 
  622. * Handles Member list actions. 
  623. * 
  624. * @since 1.0.0 
  625. * 
  626. * @param string $action The action to execute. 
  627. * @param object[] $members Array of members. 
  628. * @param int $membership_id The Membership to apply action to. 
  629. */ 
  630. public function member_list_do_action( $action, $members, $membership_id = null ) { 
  631. $msg = MS_Helper_Member::MSG_MEMBER_NOT_UPDATED; 
  632. if ( ! $this->is_admin_user() ) { 
  633. return $msg; 
  634.  
  635. foreach ( $members as $member_id ) { 
  636. // Member Model 
  637. $member = MS_Factory::load( 'MS_Model_Member', $member_id ); 
  638. switch ( $action ) { 
  639. case 'add': 
  640. $member->add_membership( $membership_id ); 
  641. $msg = MS_Helper_Member::MSG_MEMBER_ADDED; 
  642. break; 
  643.  
  644. case 'drop': 
  645. $member->drop_membership( $membership_id ); 
  646. $msg = MS_Helper_Member::MSG_MEMBER_DELETED; 
  647. break; 
  648.  
  649. case 'move': 
  650. if ( ! empty( $_POST['membership_move_from_id'] ) ) { 
  651. $member->move_membership( 
  652. $_POST['membership_move_from_id'],  
  653. $_POST['membership_id'] 
  654. ); 
  655. $msg = MS_Helper_Member::MSG_MEMBER_UPDATED; 
  656. break; 
  657.  
  658. case 'edit_date': 
  659. if ( is_array( $membership_id ) ) { 
  660. foreach ( $membership_id as $id ) { 
  661. $subscription = $member->get_subscriptions( $id ); 
  662. if ( ! empty( $_POST[ 'start_date_' . $id ] ) ) { 
  663. $subscription->start_date = $_POST[ 'start_date_' . $id ]; 
  664. $subscription->set_trial_expire_date(); 
  665.  
  666. if ( ! empty( $_POST[ 'expire_date_' . $id ] ) ) { 
  667. $subscription->expire_date = $_POST[ 'expire_date_' . $id ]; 
  668. $subscription->save(); 
  669. $msg = MS_Helper_Member::MSG_MEMBER_UPDATED; 
  670. break; 
  671. $member->save(); 
  672.  
  673. return apply_filters( 
  674. 'ms_controller_member_member_list_do_action',  
  675. $msg,  
  676. $action,  
  677. $members,  
  678. $membership_id,  
  679. $this 
  680. ); 
  681.  
  682. /** 
  683. * Load Member manager specific styles. 
  684. * 
  685. * @since 1.0.0 
  686. */ 
  687. public function enqueue_styles() { 
  688. lib3()->ui->add( 'jquery-ui' ); 
  689.  
  690. /** 
  691. * Load Member specific scripts for the LIST view. 
  692. * 
  693. * @since 1.0.0 
  694. */ 
  695. public function enqueue_scripts_list() { 
  696. $data = array( 
  697. 'ms_init' => array(),  
  698. ); 
  699. lib3()->array->equip_get( 'action' ); 
  700.  
  701. if ( 'edit_date' == $_GET['action'] ) { 
  702. // Start and expire date edit 
  703. wp_enqueue_script( 'jquery-ui-datepicker' ); 
  704. $data['ms_init'][] = 'view_member_date'; 
  705. } else { 
  706. // Members list 
  707. $data['ms_init'][] = 'view_member_list'; 
  708. $data['lang'] = array( 
  709. 'select_user' => __( 'Select an User', 'membership2' ),  
  710. ); 
  711.  
  712. lib3()->ui->data( 'ms_data', $data ); 
  713. wp_enqueue_script( 'ms-admin' ); 
  714.  
  715. /** 
  716. * Load Member specific scripts for ADD/EDIT screen. 
  717. * 
  718. * @since 1.0.1.0 
  719. */ 
  720. public function enqueue_scripts_editor() { 
  721. $data = array( 
  722. 'ms_init' => array(),  
  723. ); 
  724.  
  725. $data['ms_init'][] = 'view_member_editor'; 
  726.  
  727. lib3()->ui->data( 'ms_data', $data ); 
  728. wp_enqueue_script( 'ms-admin' ); 
  729.  
.