MS_View_Member_Editor

Display an edit form where a single member can be added or details of a member can be edited.

Defined (1)

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

/app/view/member/class-ms-view-member-editor.php  
  1. class MS_View_Member_Editor extends MS_View { 
  2.  
  3. /** 
  4. * Create view output. 
  5. * @since 1.0.1.0 
  6. * @return string 
  7. */ 
  8. public function to_html() { 
  9.  
  10. if ( 'add' == $this->data['action'] ) { 
  11. $title = __( 'Add or Select Member', 'membership2' ); 
  12. $groups = $this->prepare_fields_add(); 
  13. } else { 
  14. $title = __( 'Edit Member', 'membership2' ); 
  15. $groups = $this->prepare_fields_edit(); 
  16.  
  17. ob_start(); 
  18. ?> 
  19. <div class="ms-wrap ms-add-member"> 
  20. <?php 
  21. MS_Helper_Html::settings_header( 
  22. array( 
  23. 'title_icon_class' => 'wpmui-fa wpmui-fa-user',  
  24. 'title' => $title,  
  25. 'desc' => '',  
  26. ); 
  27. ?> 
  28. <div class="ms-settings ms-add-member"> 
  29. <?php foreach ( $groups as $class => $fields ) : ?> 
  30. <div class="ms-field-group ms-group-<?php echo esc_attr( $class ); ?>"> 
  31. <div class="ms-field-group-inner"> 
  32. <form method="post"> 
  33. <?php 
  34. foreach ( $fields as $field ) { 
  35. MS_Helper_Html::html_element( $field ); 
  36. ?> 
  37. </div></div> 
  38. </form> 
  39. <?php endforeach; ?> 
  40. </div> 
  41. </div> 
  42. <?php 
  43. $html = ob_get_clean(); 
  44.  
  45. return $html; 
  46.  
  47. /** 
  48. * Input fields displayed in the "Add or Select Member" screen. 
  49. * @since 1.0.1.0 
  50. * @return array 
  51. */ 
  52. public function prepare_fields_add() { 
  53. $action_add = MS_Controller_Member::ACTION_ADD_MEMBER; 
  54. $action_select = MS_Controller_Member::ACTION_SELECT_MEMBER; 
  55.  
  56. $fields = array(); 
  57. $fields['create'] = array( 
  58. 'title' => array( 
  59. 'type' => MS_Helper_Html::TYPE_HTML_TEXT,  
  60. 'class' => 'group-title',  
  61. 'value' => __( 'Create a new WordPress user', 'membership2' ),  
  62. ),  
  63. 'username' => array( 
  64. 'id' => 'username',  
  65. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  66. 'title' => __( 'User name', 'membership2' ) . ' *',  
  67. 'after' => ' ',  
  68. 'class' => 'required ms-text-medium',  
  69. ),  
  70. 'email' => array( 
  71. 'id' => 'email',  
  72. 'type' => MS_Helper_Html::INPUT_TYPE_EMAIL,  
  73. 'title' => __( 'Email address', 'membership2' ) . ' *',  
  74. 'after' => ' ',  
  75. 'class' => 'required ms-text-medium',  
  76. ),  
  77. 'first_name' => array( 
  78. 'id' => 'first_name',  
  79. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  80. 'title' => __( 'First name', 'membership2' ),  
  81. 'class' => 'ms-text-medium',  
  82. ),  
  83. 'last_name' => array( 
  84. 'id' => 'last_name',  
  85. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  86. 'title' => __( 'Last name', 'membership2' ),  
  87. 'class' => 'ms-text-medium',  
  88. ),  
  89. 'password' => array( 
  90. 'id' => 'password',  
  91. 'type' => MS_Helper_Html::INPUT_TYPE_PASSWORD,  
  92. 'title' => __( 'Password', 'membership2' ),  
  93. 'class' => 'ms-text-medium',  
  94. ),  
  95. 'info' => array( 
  96. 'type' => MS_Helper_Html::TYPE_HTML_TEXT,  
  97. 'value' => __( 'We create a new WordPress user without sending a confirmation email.', 'membership2' ),  
  98. 'class' => 'info-field',  
  99. ),  
  100. 'sep' => array( 
  101. 'type' => MS_Helper_Html::TYPE_HTML_SEPARATOR,  
  102. ),  
  103. 'button' => array( 
  104. 'id' => 'btn_create',  
  105. 'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT,  
  106. 'value' => __( 'Create user', 'membership2' ) . ' »',  
  107. ),  
  108. 'action' => array( 
  109. 'id' => 'action',  
  110. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  111. 'value' => $action_add,  
  112. ),  
  113. '_wpnonce' => array( 
  114. 'id' => '_wpnonce',  
  115. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  116. 'value' => wp_create_nonce( $action_add ),  
  117. ),  
  118. ); 
  119.  
  120. $fields['select'] = array( 
  121. 'title' => array( 
  122. 'type' => MS_Helper_Html::TYPE_HTML_TEXT,  
  123. 'class' => 'group-title',  
  124. 'value' => __( 'Select an existing WordPress user', 'membership2' ),  
  125. ),  
  126. 'select_user' => array( 
  127. 'id' => 'user_id',  
  128. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  129. 'title' => __( 'Existing WordPress users', 'membership2' ),  
  130. 'class' => 'manual-init no-auto-init widefat',  
  131. ),  
  132. 'sep' => array( 
  133. 'type' => MS_Helper_Html::TYPE_HTML_SEPARATOR,  
  134. ),  
  135. 'button' => array( 
  136. 'id' => 'btn_select',  
  137. 'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT,  
  138. 'value' => __( 'Select', 'membership2' ) . ' »',  
  139. ),  
  140. 'action' => array( 
  141. 'id' => 'action',  
  142. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  143. 'value' => $action_select,  
  144. ),  
  145. '_wpnonce' => array( 
  146. 'id' => '_wpnonce',  
  147. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  148. 'value' => wp_create_nonce( $action_select ),  
  149. ),  
  150. ); 
  151.  
  152. return apply_filters( 
  153. 'ms_view_member_editor_fields_add',  
  154. $fields 
  155. ); 
  156.  
  157. /** 
  158. * Input fields displayed in the "Edit Member" screen. 
  159. * @since 1.0.1.0 
  160. * @return array 
  161. */ 
  162. public function prepare_fields_edit() { 
  163. $action_update = MS_Controller_Member::ACTION_UPDATE_MEMBER; 
  164. $action_modify = MS_Controller_Member::ACTION_MODIFY_SUBSCRIPTIONS; 
  165.  
  166. $user_id = $this->data['user_id']; 
  167. $user = MS_Factory::load( 'MS_Model_Member', $user_id ); 
  168. $unused_memberships = array(); 
  169. $temp_memberships = MS_Model_Membership::get_memberships( 
  170. array( 'include_guest' => 0 ) 
  171. ); 
  172. foreach ( $temp_memberships as $membership ) { 
  173. $unused_memberships[$membership->id] = $membership; 
  174.  
  175. $fields = array(); 
  176. $fields['editor'] = array( 
  177. 'title' => array( 
  178. 'type' => MS_Helper_Html::TYPE_HTML_TEXT,  
  179. 'class' => 'group-title',  
  180. 'value' => __( 'Basic Profile details', 'membership2' ),  
  181. ),  
  182. 'username' => array( 
  183. 'id' => 'username',  
  184. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  185. 'title' => __( 'Username', 'membership2' ),  
  186. 'value' => $user->username,  
  187. 'class' => 'ms-text-medium',  
  188. 'config' => array( 
  189. 'disabled' => 'disabled',  
  190. ),  
  191. ),  
  192. 'email' => array( 
  193. 'id' => 'email',  
  194. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  195. 'title' => __( 'Email', 'membership2' ),  
  196. 'value' => $user->email,  
  197. 'class' => 'ms-text-medium',  
  198. ),  
  199. 'first_name' => array( 
  200. 'id' => 'first_name',  
  201. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  202. 'title' => __( 'First Name', 'membership2' ),  
  203. 'value' => $user->first_name,  
  204. 'class' => 'ms-text-medium',  
  205. ),  
  206. 'last_name' => array( 
  207. 'id' => 'last_name',  
  208. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  209. 'title' => __( 'Last Name', 'membership2' ),  
  210. 'value' => $user->last_name,  
  211. 'class' => 'ms-text-medium',  
  212. ),  
  213. 'displayname' => array( 
  214. 'id' => 'displayname',  
  215. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  216. 'title' => __( 'Display Name', 'membership2' ),  
  217. 'value' => $user->get_user()->display_name,  
  218. 'class' => 'ms-text-medium',  
  219. ),  
  220. 'sep' => array( 
  221. 'type' => MS_Helper_Html::TYPE_HTML_SEPARATOR,  
  222. ),  
  223. 'user_id' => array( 
  224. 'id' => 'user_id',  
  225. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  226. 'value' => $user->id,  
  227. ),  
  228. 'button' => array( 
  229. 'id' => 'btn_save',  
  230. 'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT,  
  231. 'value' => __( 'Save', 'membership2' ),  
  232. ),  
  233. 'profile' => array( 
  234. 'id' => 'user_profile',  
  235. 'type' => MS_Helper_Html::TYPE_HTML_LINK,  
  236. 'value' => __( 'Full User Profile', 'membership2' ) . ' »',  
  237. 'url' => admin_url( 'user-edit.php?user_id=' . $user->id ),  
  238. 'class' => 'button wpmui-field-input',  
  239. ),  
  240. 'action' => array( 
  241. 'id' => 'action',  
  242. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  243. 'value' => $action_update,  
  244. ),  
  245. '_wpnonce' => array( 
  246. 'id' => '_wpnonce',  
  247. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  248. 'value' => wp_create_nonce( $action_update ),  
  249. ),  
  250. ); 
  251.  
  252. $fields['subscriptions'] = array(); 
  253.  
  254. // Section: Edit existing subscriptions. 
  255. $fields['subscriptions'][] = array( 
  256. 'type' => MS_Helper_Html::TYPE_HTML_TEXT,  
  257. 'class' => 'group-title',  
  258. 'value' => __( 'Manage Subscriptions', 'membership2' ),  
  259. ); 
  260. if ( $user->subscriptions ) { 
  261. $gateways = MS_Model_Gateway::get_gateway_names( false, true ); 
  262.  
  263. foreach ( $user->subscriptions as $subscription ) { 
  264. if ( MS_Model_Relationship::STATUS_DEACTIVATED == $subscription->status ) { 
  265. continue; 
  266.  
  267. $the_membership = $subscription->get_membership(); 
  268. unset( $unused_memberships[$the_membership->id] ); 
  269.  
  270. $status_options = array( 
  271. MS_Model_Relationship::STATUS_PENDING => __( 'Pending (activate on next payment)', 'membership2' ),  
  272. MS_Model_Relationship::STATUS_WAITING => __( 'Waiting (activate on start date)', 'membership2' ),  
  273. MS_Model_Relationship::STATUS_TRIAL => __( 'Trial Active', 'membership2' ),  
  274. MS_Model_Relationship::STATUS_ACTIVE => __( 'Active', 'membership2' ),  
  275. MS_Model_Relationship::STATUS_CANCELED => __( 'Cancelled (deactivate on expire date)', 'membership2' ),  
  276. MS_Model_Relationship::STATUS_TRIAL_EXPIRED => __( 'Trial Expired (activate on next payment)', 'membership2' ),  
  277. MS_Model_Relationship::STATUS_EXPIRED => __( 'Expired (no access) ', 'membership2' ),  
  278. MS_Model_Relationship::STATUS_DEACTIVATED => __( 'Deactivated (no access)', 'membership2' ),  
  279. ); 
  280.  
  281. if ( ! $the_membership->has_trial() ) { 
  282. unset( $status_options[MS_Model_Relationship::STATUS_TRIAL] ); 
  283. unset( $status_options[MS_Model_Relationship::STATUS_TRIAL_EXPIRED] ); 
  284.  
  285. if ( isset( $gateways[ $subscription->gateway_id ] ) ) { 
  286. $gateway_name = $gateways[ $subscription->gateway_id ]; 
  287. } elseif ( empty( $subscription->gateway_id ) ) { 
  288. $gateway_name = __( '- No Gateway -', 'membership2' ); 
  289. } else { 
  290. $gateway_name = '(' . $subscription->gateway_id . ')'; 
  291.  
  292. $field_start = array( 
  293. 'name' => 'mem_' . $the_membership->id . '[start]',  
  294. 'type' => MS_Helper_Html::INPUT_TYPE_DATEPICKER,  
  295. 'value' => $subscription->start_date,  
  296. ); 
  297. $field_expire = array( 
  298. 'name' => 'mem_' . $the_membership->id . '[expire]',  
  299. 'type' => MS_Helper_Html::INPUT_TYPE_DATEPICKER,  
  300. 'value' => $subscription->expire_date,  
  301. ); 
  302. $field_status = array( 
  303. 'name' => 'mem_' . $the_membership->id . '[status]',  
  304. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  305. 'value' => $subscription->status,  
  306. 'field_options' => $status_options,  
  307. ); 
  308.  
  309. $fields['subscriptions'][] = array( 
  310. 'name' => 'memberships[]',  
  311. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  312. 'value' => $the_membership->id,  
  313. ); 
  314.  
  315. $fields['subscriptions'][] = array( 
  316. 'title' => $the_membership->get_name_tag(),  
  317. 'type' => MS_Helper_Html::TYPE_HTML_TABLE,  
  318. 'value' => array( 
  319. array( 
  320. __( 'Subscription ID', 'membership2' ),  
  321. $subscription->id,  
  322. ),  
  323. array( 
  324. __( 'Payment Gateway', 'membership2' ),  
  325. $gateway_name,  
  326. ),  
  327. array( 
  328. __( 'Payment Type', 'membership2' ),  
  329. $subscription->get_payment_description( null, true ),  
  330. ),  
  331. array( 
  332. __( 'Start Date', 'membership2' ) . ' <sup>*)</sup>',  
  333. MS_Helper_Html::html_element( $field_start, true ),  
  334. ),  
  335. array( 
  336. __( 'Expire Date', 'membership2' ) . ' <sup>*)</sup>',  
  337. MS_Helper_Html::html_element( $field_expire, true ),  
  338. ),  
  339. array( 
  340. __( 'Status', 'membership2' ) . ' <sup>*)</sup>',  
  341. MS_Helper_Html::html_element( $field_status, true ),  
  342. ),  
  343. ),  
  344. 'field_options' => array( 
  345. 'head_col' => true,  
  346. ),  
  347. ); 
  348. } else { 
  349. $fields['subscriptions'][] = array( 
  350. 'type' => MS_Helper_Html::TYPE_HTML_TEXT,  
  351. 'value' => __( 'This user does not have any subscriptions yet.', 'membership2' ),  
  352. ); 
  353.  
  354. // Section: Add new subscription. 
  355. if ( count( $unused_memberships ) ) { 
  356. $options = array(); 
  357.  
  358. if ( MS_Model_Addon::is_enabled( MS_Model_Addon::ADDON_MULTI_MEMBERSHIPS ) ) { 
  359. $field_type = MS_Helper_Html::INPUT_TYPE_CHECKBOX; 
  360. $group_title = __( 'Add Subscriptions', 'membership2' ); 
  361. } else { 
  362. $field_type = MS_Helper_Html::INPUT_TYPE_RADIO; 
  363. $group_title = __( 'Set Subscription', 'membership2' ); 
  364.  
  365. $fields['subscriptions'][] = array( 
  366. 'type' => MS_Helper_Html::TYPE_HTML_SEPARATOR,  
  367. ); 
  368. $fields['subscriptions'][] = array( 
  369. 'type' => MS_Helper_Html::TYPE_HTML_TEXT,  
  370. 'class' => 'group-title',  
  371. 'value' => $group_title,  
  372. ); 
  373. foreach ( $unused_memberships as $the_membership ) { 
  374. $options[$the_membership->id] = $the_membership->get_name_tag(); 
  375. $fields['subscriptions'][] = array( 
  376. 'id' => 'subscribe',  
  377. 'type' => $field_type,  
  378. 'field_options' => $options,  
  379. ); 
  380. $fields['subscriptions'][] = array( 
  381. 'id' => 'user_id',  
  382. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  383. 'value' => $user->id,  
  384. ); 
  385.  
  386. if ( $user->subscriptions ) { 
  387. $fields['subscriptions'][] = array( 
  388. 'type' => MS_Helper_Html::TYPE_HTML_SEPARATOR,  
  389. ); 
  390. $fields['subscriptions'][] = array( 
  391. 'type' => MS_Helper_Html::TYPE_HTML_TEXT,  
  392. 'value' => '<sup>*)</sup> ' . __( 'Subscription Dates and Status are validated when saved and might result in a different value then the one specified above.', 'membership2' ),  
  393. 'class' => 'info-field',  
  394. ); 
  395. $fields['subscriptions'][] = array( 
  396. 'id' => 'btn_modify',  
  397. 'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT,  
  398. 'value' => __( 'Save Changes', 'membership2' ),  
  399. ); 
  400. $fields['subscriptions'][] = array( 
  401. 'id' => 'history',  
  402. 'type' => MS_Helper_Html::TYPE_HTML_LINK,  
  403. 'value' => '<i class="dashicons dashicons-id"></i>' . __( 'History and logs', 'membership2' ),  
  404. 'url' => '#history',  
  405. 'class' => 'button wpmui-field-input',  
  406. 'config' => array( 
  407. 'data-ms-dialog' => 'View_Member_Dialog',  
  408. 'data-ms-data' => array( 'member_id' => $user->id ),  
  409. ),  
  410. ); 
  411. $fields['subscriptions'][] = array( 
  412. 'id' => 'action',  
  413. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  414. 'value' => $action_modify,  
  415. ); 
  416.  
  417. $fields['subscriptions'][] = array( 
  418. 'id' => '_wpnonce',  
  419. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  420. 'value' => wp_create_nonce( $action_modify ),  
  421. ); 
  422.  
  423. return apply_filters( 
  424. 'ms_view_member_editor_fields_edit',  
  425. $fields 
  426. );