MS_View_Shortcode_Account

The Membership 2 MS View Shortcode Account class.

Defined (1)

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

/app/view/shortcode/class-ms-view-shortcode-account.php  
  1. class MS_View_Shortcode_Account extends MS_View { 
  2.  
  3. public function to_html() { 
  4. global $post; 
  5.  
  6. /** 
  7. * Provide a customized account page. 
  8. * @since 1.0.0 
  9. */ 
  10. $html = apply_filters( 
  11. 'ms_shortcode_custom_account',  
  12. '',  
  13. $this->data 
  14. ); 
  15.  
  16. if ( ! empty( $html ) ) { 
  17. return $html; 
  18. } else { 
  19. $html = ''; 
  20.  
  21. $member = MS_Model_Member::get_current_member(); 
  22. $fields = $this->prepare_fields(); 
  23.  
  24. // Extract shortcode options. 
  25. extract( $this->data ); 
  26.  
  27. ob_start(); 
  28. ?> 
  29. <div class="ms-account-wrapper"> 
  30. <?php if ( MS_Model_Member::is_logged_in() ) : ?> 
  31.  
  32. <?php 
  33. // ================================================= MEMBERSHIPS 
  34. if ( $show_membership ) : ?> 
  35. <div id="account-membership"> 
  36. <h2> 
  37. <?php 
  38. echo $membership_title; 
  39.  
  40. if ( $show_membership_change ) { 
  41. $signup_url = MS_Model_Pages::get_page_url( MS_Model_Pages::MS_PAGE_REGISTER ); 
  42.  
  43. printf( 
  44. '<a href="%s" class="ms-edit-profile">%s</a>',  
  45. $signup_url,  
  46. $membership_change_label 
  47. ); 
  48. ?> 
  49. </h2> 
  50. <?php 
  51. /** 
  52. * Add custom content right before the memberships list. 
  53. * @since 1.0.0 
  54. */ 
  55. do_action( 'ms_view_account_memberships_top', $member, $this ); 
  56.  
  57. if ( MS_Model_Member::is_admin_user() ) { 
  58. _e( 'You are an admin user and have access to all memberships', 'membership2' ); 
  59. } else { 
  60. if ( ! empty( $this->data['subscription'] ) ) { 
  61. ?> 
  62. <table> 
  63. <tr> 
  64. <th class="ms-col-membership"><?php 
  65. _e( 'Membership name', 'membership2' ); 
  66. ?></th> 
  67. <th class="ms-col-status"><?php 
  68. _e( 'Status', 'membership2' ); 
  69. ?></th> 
  70. <th class="ms-col-expire-date"><?php 
  71. _e( 'Expire date', 'membership2' ); 
  72. ?></th> 
  73. </tr> 
  74. <?php 
  75. $empty = true; 
  76.  
  77. // These subscriptions have no expire date 
  78. $no_expire_list = array( 
  79. MS_Model_Relationship::STATUS_PENDING,  
  80. MS_Model_Relationship::STATUS_WAITING,  
  81. MS_Model_Relationship::STATUS_DEACTIVATED,  
  82. ); 
  83.  
  84. // These subscriptions display the trial-expire date 
  85. $trial_expire_list = array( 
  86. MS_Model_Relationship::STATUS_TRIAL,  
  87. MS_Model_Relationship::STATUS_TRIAL_EXPIRED,  
  88. ); 
  89.  
  90. foreach ( $this->data['subscription'] as $subscription ) : 
  91. $empty = false; 
  92. $membership = $subscription->get_membership(); 
  93. $subs_classes = array( 
  94. 'ms-subscription-' . $subscription->id,  
  95. 'ms-status-' . $subscription->status,  
  96. 'ms-type-' . $membership->type,  
  97. 'ms-payment-' . $membership->payment_type,  
  98. 'ms-gateway-' . $subscription->gateway_id,  
  99. 'ms-membership-' . $subscription->membership_id,  
  100. $subscription->has_trial() ? 'ms-with-trial' : 'ms-no-trial',  
  101. ); 
  102. ?> 
  103. <tr class="<?php echo esc_attr( implode( ' ', $subs_classes ) ); ?>"> 
  104. <td class="ms-col-membership"><?php echo esc_html( $membership->name ); ?></td> 
  105. <td class="ms-col-status"> 
  106. <?php 
  107. if ( MS_Model_Relationship::STATUS_PENDING == $subscription->status ) { 
  108. // Display a "Purchase" link when status is Pending 
  109. $code = sprintf( 
  110. '[%s id="%s" label="%s"]',  
  111. MS_Helper_Shortcode::SCODE_MS_BUY,  
  112. $membership->id,  
  113. __( 'Pending', 'membership2' ) 
  114. ); 
  115. echo do_shortcode( $code ); 
  116. } else { 
  117. echo esc_html( $subscription->status_text() ); 
  118. ?> 
  119. </td> 
  120. <td class="ms-col-expire-date"><?php 
  121. if ( in_array( $subscription->status, $no_expire_list ) ) { 
  122. echo ' '; 
  123. } elseif ( in_array( $subscription->status, $trial_expire_list ) ) { 
  124. echo esc_html( 
  125. MS_Helper_Period::format_date( $subscription->trial_expire_date ) 
  126. ); 
  127. } elseif ( $subscription->expire_date ) { 
  128. echo esc_html( 
  129. MS_Helper_Period::format_date( $subscription->expire_date ) 
  130. ); 
  131. } else { 
  132. _e( 'Never', 'membership2' ); 
  133. ?></td> 
  134. </tr> 
  135. <?php 
  136. endforeach; 
  137.  
  138. if ( $empty ) { 
  139. $cols = 3; 
  140. if ( MS_Model_Addon::is_enabled( MS_Model_Addon::ADDON_TRIAL ) ) { 
  141. $cols += 1; 
  142.  
  143. printf( 
  144. '<tr><td colspan="%1$s">%2$s</td></tr>',  
  145. $cols,  
  146. __( '(No Membership)', 'membership2' ) 
  147. ); 
  148. ?> 
  149. </table> 
  150. <?php 
  151. } else { 
  152. _e( 'No memberships', 'membership2' ); 
  153. /** 
  154. * Add custom content right after the memberships list. 
  155. * @since 1.0.0 
  156. */ 
  157. do_action( 'ms_view_account_memberships_bottom', $member, $this ); 
  158. ?> 
  159. </div> 
  160. <?php 
  161. endif; 
  162. // END: if ( $show_membership ) 
  163. // ============================================================= 
  164. ?> 
  165.  
  166. <?php 
  167. // ===================================================== PROFILE 
  168. if ( $show_profile ) : ?> 
  169. <div id="account-profile"> 
  170. <h2> 
  171. <?php 
  172. echo $profile_title; 
  173.  
  174. if ( $show_profile_change ) { 
  175. $edit_url = esc_url_raw( 
  176. add_query_arg( 
  177. array( 'action' => MS_Controller_Frontend::ACTION_EDIT_PROFILE ) 
  178. ); 
  179.  
  180. printf( 
  181. '<a href="%s" class="ms-edit-profile">%s</a>',  
  182. $edit_url,  
  183. $profile_change_label 
  184. ); 
  185. ?> 
  186. </h2> 
  187. <?php 
  188. /** 
  189. * Add custom content right before the profile overview. 
  190. * @since 1.0.0 
  191. */ 
  192. do_action( 'ms_view_account_profile_top', $member, $this ); 
  193. ?> 
  194. <table> 
  195. <?php foreach ( $fields['personal_info'] as $field => $title ) : ?> 
  196. <tr> 
  197. <th class="ms-label-title"><?php echo esc_html( $title ); ?>: </th> 
  198. <td class="ms-label-field"><?php echo esc_html( $this->data['member']->$field ); ?></td> 
  199. </tr> 
  200. <?php endforeach; ?> 
  201. </table> 
  202. <?php 
  203. do_action( 'ms_view_shortcode_account_card_info', $this->data ); 
  204.  
  205. /** 
  206. * Add custom content right after the profile overview. 
  207. * @since 1.0.0 
  208. */ 
  209. do_action( 'ms_view_account_profile_bottom', $member, $this ); 
  210. ?> 
  211. </div> 
  212. <?php 
  213. endif; 
  214. // END: if ( $show_profile ) 
  215. // ============================================================= 
  216. ?> 
  217.  
  218. <?php 
  219. // ==================================================== INVOICES 
  220. if ( $show_invoices ) : ?> 
  221. <div id="account-invoices"> 
  222. <h2> 
  223. <?php 
  224. echo $invoices_title; 
  225.  
  226. if ( $show_all_invoices ) { 
  227. $detail_url = esc_url_raw( 
  228. add_query_arg( 
  229. array( 'action' => MS_Controller_Frontend::ACTION_VIEW_INVOICES ) 
  230. ); 
  231.  
  232. printf( 
  233. '<a href="%s" class="ms-all-invoices">%s</a>',  
  234. $detail_url,  
  235. $invoices_details_label 
  236. ); 
  237. ?> 
  238. </h2> 
  239. <?php 
  240. /** 
  241. * Add custom content right before the invoice overview list. 
  242. * @since 1.0.0 
  243. */ 
  244. do_action( 'ms_view_account_invoices_top', $member, $this ); 
  245. ?> 
  246. <table> 
  247. <thead> 
  248. <tr> 
  249. <th class="ms-col-invoice-no"><?php 
  250. _e( 'Invoice #', 'membership2' ); 
  251. ?></th> 
  252. <th class="ms-col-invoice-status"><?php 
  253. _e( 'Status', 'membership2' ); 
  254. ?></th> 
  255. <th class="ms-col-invoice-total"><?php 
  256. printf( 
  257. '%s (%s)',  
  258. __( 'Total', 'membership2' ),  
  259. MS_Plugin::instance()->settings->currency 
  260. ); 
  261. ?></th> 
  262. <th class="ms-col-invoice-title"><?php 
  263. _e( 'Membership', 'membership2' ); 
  264. ?></th> 
  265. <th class="ms-col-invoice-due"><?php 
  266. _e( 'Due date', 'membership2' ); 
  267. ?></th> 
  268. </tr> 
  269. </thead> 
  270. <tbody> 
  271. <?php foreach ( $this->data['invoices'] as $invoice ) : 
  272. $inv_membership = MS_Factory::load( 'MS_Model_Membership', $invoice->membership_id ); 
  273. $inv_classes = array( 
  274. 'ms-invoice-' . $invoice->id,  
  275. 'ms-subscription-' . $invoice->ms_relationship_id,  
  276. 'ms-invoice-' . $invoice->status,  
  277. 'ms-gateway-' . $invoice->gateway_id,  
  278. 'ms-membership-' . $invoice->membership_id,  
  279. 'ms-type-' . $inv_membership->type,  
  280. 'ms-payment-' . $inv_membership->payment_type,  
  281. ); 
  282. ?> 
  283. <tr class="<?php echo esc_attr( implode( ' ', $inv_classes ) ); ?>"> 
  284. <td class="ms-col-invoice-no"><?php 
  285. printf( 
  286. '<a href="%s">%s</a>',  
  287. get_permalink( $invoice->id ),  
  288. $invoice->get_invoice_number() 
  289. ); 
  290. ?></td> 
  291. <td class="ms-col-invoice-status"><?php 
  292. echo esc_html( $invoice->status_text() ); 
  293. ?></td> 
  294. <td class="ms-col-invoice-total"><?php 
  295. echo esc_html( MS_Helper_Billing::format_price( $invoice->total ) ); 
  296. ?></td> 
  297. <td class="ms-col-invoice-title"><?php 
  298. echo esc_html( $inv_membership->name ); 
  299. ?></td> 
  300. <td class="ms-col-invoice-due"><?php 
  301. echo esc_html( 
  302. MS_Helper_Period::format_date( 
  303. $invoice->due_date,  
  304. __( 'F j', 'membership2' ) 
  305. ); 
  306. ?></td> 
  307. </tr> 
  308. <?php endforeach; ?> 
  309. </tbody> 
  310. </table> 
  311. <?php 
  312. /** 
  313. * Add custom content right after the invoices overview list. 
  314. * @since 1.0.0 
  315. */ 
  316. do_action( 'ms_view_account_invoices_bottom', $member, $this ); 
  317. ?> 
  318. </div> 
  319. <?php 
  320. endif; 
  321. // END: if ( $show_invoices ) 
  322. // ============================================================= 
  323. ?> 
  324.  
  325. <?php 
  326. // ==================================================== ACTIVITY 
  327. if ( $show_activity ) : ?> 
  328. <div id="account-activity"> 
  329. <h2> 
  330. <?php 
  331. echo $activity_title; 
  332.  
  333. if ( $show_all_activities ) { 
  334. $detail_url = esc_url_raw( 
  335. add_query_arg( 
  336. array( 'action' => MS_Controller_Frontend::ACTION_VIEW_ACTIVITIES ) 
  337. ); 
  338.  
  339. printf( 
  340. '<a href="%s" class="ms-all-activities">%s</a>',  
  341. $detail_url,  
  342. $activity_details_label 
  343. ); 
  344. ?> 
  345. </h2> 
  346. <?php 
  347. /** 
  348. * Add custom content right before the activities overview list. 
  349. * @since 1.0.0 
  350. */ 
  351. do_action( 'ms_view_account_activity_top', $member, $this ); 
  352. ?> 
  353. <table> 
  354. <thead> 
  355. <tr> 
  356. <th class="ms-col-activity-date"><?php 
  357. _e( 'Date', 'membership2' ); 
  358. ?></th> 
  359. <th class="ms-col-activity-title"><?php 
  360. _e( 'Activity', 'membership2' ); 
  361. ?></th> 
  362. </tr> 
  363. </thead> 
  364. <tbody> 
  365. <?php foreach ( $this->data['events'] as $event ) : 
  366. $ev_classes = array( 
  367. 'ms-activity-topic-' . $event->topic,  
  368. 'ms-activity-type-' . $event->type,  
  369. 'ms-membership-' . $event->membership_id,  
  370. ); 
  371. ?> 
  372. <tr class="<?php echo esc_attr( implode( ' ', $ev_classes ) ); ?>"> 
  373. <td class="ms-col-activity-date"><?php 
  374. echo esc_html( 
  375. MS_Helper_Period::format_date( 
  376. $event->post_modified 
  377. ); 
  378. ?></td> 
  379. <td class="ms-col-activity-title"><?php 
  380. echo esc_html( $event->description ); 
  381. ?></td> 
  382. </tr> 
  383. <?php endforeach; ?> 
  384. </tbody> 
  385. </table> 
  386. <?php 
  387. /** 
  388. * Add custom content right after the activities overview list. 
  389. * @since 1.0.0 
  390. */ 
  391. do_action( 'ms_view_account_activity_bottom', $member, $this ); 
  392. ?> 
  393. </div> 
  394. <?php 
  395. endif; 
  396. // END: if ( $show_activity ) 
  397. // ============================================================= 
  398. ?> 
  399.  
  400. <?php else : 
  401. $has_login_form = MS_Helper_Shortcode::has_shortcode( 
  402. MS_Helper_Shortcode::SCODE_LOGIN,  
  403. $post->post_content 
  404. ); 
  405.  
  406. if ( ! $has_login_form ) { 
  407. $redirect = esc_url_raw( add_query_arg( array() ) ); 
  408. $title = __( 'Your account', 'membership2' ); 
  409. $scode = sprintf( 
  410. '[%1$s redirect="%2$s" title="%3$s"]',  
  411. MS_Helper_Shortcode::SCODE_LOGIN,  
  412. esc_url( $redirect ),  
  413. esc_attr( $title ) 
  414. ); 
  415. echo do_shortcode( $scode ); 
  416. endif; ?> 
  417. </div> 
  418. <?php 
  419. $html = ob_get_clean(); 
  420. $html = apply_filters( 'ms_compact_code', $html ); 
  421.  
  422. return apply_filters( 
  423. 'ms_shortcode_account',  
  424. $html,  
  425. $this->data 
  426. ); 
  427.  
  428. /** 
  429. * Prepare some fields that are displayed in the account overview. 
  430. * @since 1.0.0 
  431. * @return array 
  432. */ 
  433. public function prepare_fields() { 
  434. $fields = array( 
  435. 'personal_info' => array( 
  436. 'first_name' => __( 'First name', 'membership2' ),  
  437. 'last_name' => __( 'Last name', 'membership2' ),  
  438. 'username' => __( 'Username', 'membership2' ),  
  439. 'email' => __( 'Email', 'membership2' ),  
  440. ); 
  441.  
  442. $fields = apply_filters( 
  443. 'ms_shortcode_account_fields',  
  444. $fields,  
  445. $this 
  446. ); 
  447.  
  448. return $fields; 
  449.