MS_Controller_Shortcode

Controller for managing Plugin Shortcodes.

Defined (1)

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

/app/controller/class-ms-controller-shortcode.php  
  1. class MS_Controller_Shortcode extends MS_Controller { 
  2.  
  3. /** 
  4. * Prepare the shortcode hooks. 
  5. * @since 1.0.0 
  6. */ 
  7. public function __construct() { 
  8. parent::__construct(); 
  9. $this->run_action( 'init', 'init' ); 
  10.  
  11. /** 
  12. * Initialize the Shortcodes after we have determined the current user. 
  13. * @since 1.0.0 
  14. */ 
  15. public function init() { 
  16. // By default assume no content for the protected-content code 
  17. add_shortcode( 
  18. MS_Helper_Shortcode::SCODE_PROTECTED,  
  19. array( $this, '__return_null' ) 
  20. ); 
  21.  
  22. if ( MS_Plugin::is_enabled() ) { 
  23. add_shortcode( 
  24. MS_Helper_Shortcode::SCODE_REGISTER_USER,  
  25. array( $this, 'membership_register_user' ) 
  26. ); 
  27.  
  28. add_shortcode( 
  29. MS_Helper_Shortcode::SCODE_SIGNUP,  
  30. array( $this, 'membership_signup' ) 
  31. ); 
  32.  
  33. add_shortcode( 
  34. MS_Helper_Shortcode::SCODE_MS_TITLE,  
  35. array( $this, 'membership_title' ) 
  36. ); 
  37.  
  38. add_shortcode( 
  39. MS_Helper_Shortcode::SCODE_MS_PRICE,  
  40. array( $this, 'membership_price' ) 
  41. ); 
  42.  
  43. add_shortcode( 
  44. MS_Helper_Shortcode::SCODE_MS_BUY,  
  45. array( $this, 'membership_buy' ) 
  46. ); 
  47.  
  48. add_shortcode( 
  49. MS_Helper_Shortcode::SCODE_MS_DETAILS,  
  50. array( $this, 'membership_details' ) 
  51. ); 
  52.  
  53. add_shortcode( 
  54. MS_Helper_Shortcode::SCODE_LOGIN,  
  55. array( $this, 'membership_login' ) 
  56. ); 
  57.  
  58. add_shortcode( 
  59. MS_Helper_Shortcode::SCODE_LOGOUT,  
  60. array( $this, 'membership_logout' ) 
  61. ); 
  62.  
  63. add_shortcode( 
  64. MS_Helper_Shortcode::SCODE_MS_ACCOUNT,  
  65. array( $this, 'membership_account' ) 
  66. ); 
  67.  
  68. add_shortcode( 
  69. MS_Helper_Shortcode::SCODE_MS_ACCOUNT_LINK,  
  70. array( $this, 'membership_account_link' ) 
  71. ); 
  72.  
  73. add_shortcode( 
  74. MS_Helper_Shortcode::SCODE_MS_INVOICE,  
  75. array( $this, 'membership_invoice' ) 
  76. ); 
  77.  
  78. add_shortcode( 
  79. MS_Helper_Shortcode::SCODE_NOTE,  
  80. array( $this, 'ms_note' ) 
  81. ); 
  82.  
  83. add_shortcode( 
  84. MS_Helper_Shortcode::SCODE_GREEN_NOTE,  
  85. array( $this, 'ms_green_note' ) 
  86. ); 
  87.  
  88. add_shortcode( 
  89. MS_Helper_Shortcode::SCODE_RED_NOTE,  
  90. array( $this, 'ms_red_note' ) 
  91. ); 
  92.  
  93. add_shortcode( 
  94. MS_Helper_Shortcode::SCODE_USER,  
  95. array( $this, 'show_to_user' ) 
  96. ); 
  97.  
  98. add_shortcode( 
  99. MS_Helper_Shortcode::SCODE_MEMBER_INFO,  
  100. array( $this, 'ms_member_info' ) 
  101. ); 
  102.  
  103. if ( MS_Model_Member::is_normal_admin() ) { 
  104. add_shortcode( 
  105. MS_Rule_Shortcode_Model::PROTECT_CONTENT_SHORTCODE,  
  106. array( 'MS_Rule_Shortcode_Model', 'debug_protect_content_shortcode') 
  107. ); 
  108. } else { 
  109. $shortcodes = array( 
  110. MS_Helper_Shortcode::SCODE_REGISTER_USER,  
  111. MS_Helper_Shortcode::SCODE_SIGNUP,  
  112. MS_Helper_Shortcode::SCODE_MS_TITLE,  
  113. MS_Helper_Shortcode::SCODE_MS_PRICE,  
  114. MS_Helper_Shortcode::SCODE_MS_DETAILS,  
  115. MS_Helper_Shortcode::SCODE_LOGIN,  
  116. MS_Helper_Shortcode::SCODE_LOGOUT,  
  117. MS_Helper_Shortcode::SCODE_MS_ACCOUNT,  
  118. MS_Helper_Shortcode::SCODE_MS_ACCOUNT_LINK,  
  119. MS_Helper_Shortcode::SCODE_MS_INVOICE,  
  120. MS_Helper_Shortcode::SCODE_NOTE,  
  121. MS_Helper_Shortcode::SCODE_GREEN_NOTE,  
  122. MS_Helper_Shortcode::SCODE_RED_NOTE,  
  123. ); 
  124.  
  125. foreach ( $shortcodes as $shortcode ) { 
  126. add_shortcode( $shortcode, array( $this, 'ms_no_value' ) ); 
  127.  
  128. add_shortcode( 
  129. MS_Rule_Shortcode_Model::PROTECT_CONTENT_SHORTCODE,  
  130. array( $this, 'hide_shortcode') 
  131. ); 
  132.  
  133. add_shortcode( 
  134. MS_Helper_Shortcode::SCODE_USER,  
  135. array( $this, 'hide_shortcode') 
  136. ); 
  137.  
  138. /** 
  139. * Set up the protected-content shortcode to display the protection message. 
  140. * This function is only called from the Frontend-Controller when the 
  141. * Membership Page "Membership2" is displayed. 
  142. * @since 1.0.0 
  143. */ 
  144. public function page_is_protected() { 
  145. remove_shortcode( 
  146. MS_Helper_Shortcode::SCODE_PROTECTED,  
  147. array( $this, '__return_null' ) 
  148. ); 
  149.  
  150. add_shortcode( 
  151. MS_Helper_Shortcode::SCODE_PROTECTED,  
  152. array( $this, 'protected_content' ) 
  153. ); 
  154.  
  155.  
  156. /**========================================*\ 
  157. ============================================ 
  158. == == 
  159. == SHORTCODE HANDLERS == 
  160. == == 
  161. ============================================ 
  162. \*========================================*/ 
  163.  
  164.  
  165.  
  166. /** 
  167. * Membership register callback function. 
  168. * @since 1.0.0 
  169. * @param mixed[] $atts Shortcode attributes. 
  170. */ 
  171. public function membership_register_user( $atts ) { 
  172. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_REGISTER_USER ); 
  173.  
  174. lib3()->array->equip_request( 
  175. 'first_name',  
  176. 'last_name',  
  177. 'username',  
  178. 'email',  
  179. 'membership_id' 
  180. ); 
  181.  
  182. $data = apply_filters( 
  183. 'ms_controller_shortcode_membership_register_user_atts',  
  184. shortcode_atts( 
  185. array( 
  186. 'first_name' => substr( trim( $_REQUEST['first_name'] ), 0, 50 ),  
  187. 'last_name' => substr( trim( $_REQUEST['last_name'] ), 0, 50 ),  
  188. 'username' => substr( trim( $_REQUEST['username'] ), 0, 50 ),  
  189. 'email' => substr( trim( $_REQUEST['email'] ), 0, 50 ),  
  190. 'membership_id' => trim( $_REQUEST['membership_id'] ),  
  191. 'label_first_name' => __( 'First Name', 'membership2' ),  
  192. 'label_last_name' => __( 'Last Name', 'membership2' ),  
  193. 'label_username' => __( 'Choose a Username', 'membership2' ),  
  194. 'label_email' => __( 'Email Address', 'membership2' ),  
  195. 'label_password' => __( 'Password', 'membership2' ),  
  196. 'label_password2' => __( 'Confirm Password', 'membership2' ),  
  197. 'label_register' => __( 'Register My Account', 'membership2' ),  
  198. 'hint_first_name' => '',  
  199. 'hint_last_name' => '',  
  200. 'hint_username' => '',  
  201. 'hint_email' => '',  
  202. 'hint_password' => '',  
  203. 'hint_password2' => '',  
  204. 'title' => __( 'Create an Account', 'membership2' ),  
  205. 'loginlink' => true,  
  206. ),  
  207. $atts 
  208. ); 
  209. $data['action'] = 'register_user'; 
  210. $data['step'] = MS_Controller_Frontend::STEP_REGISTER_SUBMIT; 
  211. $data['loginlink'] = lib3()->is_true( $data['loginlink'] ); 
  212.  
  213. $view = MS_Factory::create( 'MS_View_Shortcode_RegisterUser' ); 
  214. $view->data = apply_filters( 'ms_view_shortcode_registeruser_data', $data, $this ); 
  215.  
  216. return $view->to_html(); 
  217.  
  218. /** 
  219. * Membership signup callback function. 
  220. * @since 1.0.0 
  221. * @param mixed[] $atts Shortcode attributes. 
  222. */ 
  223. public function membership_signup( $atts ) { 
  224. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_SIGNUP ); 
  225.  
  226. $data = apply_filters( 
  227. 'ms_controller_shortcode_membership_signup_atts',  
  228. shortcode_atts( 
  229. array( 
  230. MS_Helper_Membership::MEMBERSHIP_ACTION_SIGNUP . '_text' => __( 'Signup', 'membership2' ),  
  231. MS_Helper_Membership::MEMBERSHIP_ACTION_MOVE . '_text' => __( 'Change', 'membership2' ),  
  232. MS_Helper_Membership::MEMBERSHIP_ACTION_CANCEL . '_text' => __( 'Cancel', 'membership2' ),  
  233. MS_Helper_Membership::MEMBERSHIP_ACTION_RENEW . '_text' => __( 'Renew', 'membership2' ),  
  234. MS_Helper_Membership::MEMBERSHIP_ACTION_PAY . '_text' => __( 'Complete Payment', 'membership2' ),  
  235. ),  
  236. $atts 
  237. ); 
  238.  
  239. $member = MS_Model_Member::get_current_member(); 
  240. $data['member'] = $member; 
  241. $data['subscriptions'] = array(); 
  242. $exclude = array(); 
  243.  
  244. if ( $member->is_valid() ) { 
  245. // Get member's memberships, including pending relationships. 
  246. $data['subscriptions'] = MS_Model_Relationship::get_subscriptions( 
  247. array( 
  248. 'user_id' => $data['member']->id,  
  249. 'status' => 'valid',  
  250. ); 
  251.  
  252. foreach ( $data['subscriptions'] as $key => $subscription ) { 
  253. $exclude[] = $subscription->membership_id; 
  254. if ( ! $member->can_subscribe_to( $subscription->membership_id ) ) { 
  255. unset( $data['subscriptions'][$key] ); 
  256.  
  257. $memberships = MS_Model_Membership::get_signup_membership_list( 
  258. null,  
  259. $exclude 
  260. ); 
  261.  
  262. $data['memberships'] = $memberships; 
  263. $move_from_ids = array(); 
  264.  
  265. // When Multiple memberships is not enabled, a member should move to another membership. 
  266. if ( ! MS_Model_Addon::is_enabled( MS_Model_Addon::ADDON_MULTI_MEMBERSHIPS ) ) { 
  267. // Membership Relationship status which can move to another one 
  268. $valid_status = array( 
  269. MS_Model_Relationship::STATUS_TRIAL,  
  270. MS_Model_Relationship::STATUS_ACTIVE,  
  271. MS_Model_Relationship::STATUS_EXPIRED,  
  272. ); 
  273.  
  274. foreach ( $data['member']->subscriptions as $subscription ) { 
  275. if ( $subscription->is_system() ) { continue; } 
  276.  
  277. if ( in_array( $subscription->status, $valid_status ) ) { 
  278. $move_from_ids[] = $subscription->membership_id; 
  279. foreach ( $data['memberships'] as $key => $membership ) { 
  280. $data['memberships'][$key]->_move_from = $move_from_ids; 
  281. } else { 
  282. foreach ( $data['memberships'] as $key => $membership ) { 
  283. $move_from_ids = $member->cancel_ids_on_subscription( 
  284. $membership->id 
  285. ); 
  286.  
  287. $data['memberships'][$key]->_move_from = $move_from_ids; 
  288.  
  289. $data['action'] = MS_Helper_Membership::MEMBERSHIP_ACTION_SIGNUP; 
  290. $data['step'] = MS_Controller_Frontend::STEP_PAYMENT_TABLE; 
  291.  
  292. $view = MS_Factory::create( 'MS_View_Shortcode_MembershipSignup' ); 
  293. $view->data = apply_filters( 
  294. 'ms_view_shortcode_membershipsignup_data',  
  295. $data,  
  296. $this 
  297. ); 
  298.  
  299. return $view->to_html(); 
  300.  
  301. /** 
  302. * Membership title shortcode callback function. 
  303. * @since 1.0.0 
  304. * @param mixed[] $atts Shortcode attributes. 
  305. */ 
  306. public function membership_title( $atts ) { 
  307. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MS_TITLE ); 
  308.  
  309. $code = ''; 
  310.  
  311. $data = apply_filters( 
  312. 'ms_controller_shortcode_membership_title_atts',  
  313. shortcode_atts( 
  314. array( 
  315. 'id' => 0,  
  316. 'label' => __( 'Membership title:', 'membership2' ),  
  317. 'title' => '', // deprecated @since 1.0.0 
  318. ),  
  319. $atts 
  320. ); 
  321. extract( $data ); 
  322.  
  323. if ( ! empty( $id ) ) { 
  324. $membership = MS_Factory::load( 'MS_Model_Membership', $id ); 
  325. $code = sprintf( 
  326. '%1$s %2$s',  
  327. $label,  
  328. $membership->name 
  329. ); 
  330.  
  331. $code = trim( $code ); 
  332. } else { 
  333. $code = $title; 
  334.  
  335. $code = sprintf( 
  336. '<span class="ms-membership-title ms-membership-%1$s">%2$s</span>',  
  337. esc_attr( $id ),  
  338. $code 
  339. ); 
  340.  
  341. return apply_filters( 
  342. 'ms_controller_shortcode_membership_title',  
  343. $code,  
  344. $atts,  
  345. $this 
  346. ); 
  347.  
  348. /** 
  349. * Membership price shortcode callback function. 
  350. * @since 1.0.0 
  351. * @param mixed[] $atts Shortcode attributes. 
  352. */ 
  353. public function membership_price( $atts ) { 
  354. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MS_PRICE ); 
  355.  
  356. $code = 0; 
  357.  
  358. $data = apply_filters( 
  359. 'ms_controller_shortcode_membership_price_atts',  
  360. shortcode_atts( 
  361. array( 
  362. 'id' => 0,  
  363. 'currency' => true,  
  364. 'label' => __( 'Membership price:', 'membership2' ),  
  365. ),  
  366. $atts 
  367. ); 
  368. extract( $data ); 
  369.  
  370. if ( ! empty( $id ) ) { 
  371. if ( lib3()->is_true( $currency ) ) { 
  372. $settings = MS_Factory::load( 'MS_Model_Settings' ); 
  373. $currency = $settings->currency; 
  374. } else { 
  375. $currency = ''; 
  376.  
  377. $membership = MS_Factory::load( 'MS_Model_Membership', $id ); 
  378. $code = sprintf( 
  379. '%1$s %2$s %3$s',  
  380. $label,  
  381. $currency,  
  382. $membership->total_price 
  383. ); 
  384.  
  385. $code = trim( $code ); 
  386.  
  387. $code = sprintf( 
  388. '<span class="ms-membership-price ms-membership-%1$s price">%2$s</span>',  
  389. esc_attr( $id ),  
  390. $code 
  391. ); 
  392.  
  393. do_action( 'ms_show_prices' ); 
  394. return apply_filters( 
  395. 'ms_controller_shortcode_membership_price',  
  396. $code,  
  397. $atts,  
  398. $this 
  399. ); 
  400.  
  401. /** 
  402. * Buy membership button. 
  403. * @since 1.0.0 
  404. * @param mixed[] $atts Shortcode attributes. 
  405. */ 
  406. public function membership_buy( $atts ) { 
  407. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MS_BUY ); 
  408.  
  409. $code = ''; 
  410.  
  411. $data = apply_filters( 
  412. 'ms_controller_shortcode_membership_buy_atts',  
  413. shortcode_atts( 
  414. array( 
  415. 'id' => 0,  
  416. 'label' => __( 'Signup', 'membership2' ),  
  417. ),  
  418. $atts 
  419. ); 
  420. extract( $data ); 
  421.  
  422. if ( ! empty( $id ) ) { 
  423. $membership = MS_Factory::load( 'MS_Model_Membership', $id ); 
  424. $data['action'] = MS_Helper_Membership::MEMBERSHIP_ACTION_SIGNUP; 
  425. $data['step'] = MS_Controller_Frontend::STEP_PAYMENT_TABLE; 
  426.  
  427. $view = MS_Factory::create( 'MS_View_Shortcode_MembershipSignup' ); 
  428. $view->data = apply_filters( 
  429. 'ms_view_shortcode_membershipsignup_data',  
  430. $data,  
  431. $this 
  432. ); 
  433.  
  434. $code = $view->signup_form( $membership, $label ); 
  435.  
  436. $code = sprintf( 
  437. '<span class="ms-membership-buy ms-membership-%1$s">%2$s</span>',  
  438. esc_attr( $id ),  
  439. $code 
  440. ); 
  441.  
  442. return apply_filters( 
  443. 'ms_controller_shortcode_membership_buy',  
  444. $code,  
  445. $atts,  
  446. $this 
  447. ); 
  448.  
  449. /** 
  450. * Membership details shortcode callback function. 
  451. * @since 1.0.0 
  452. * @param mixed[] $atts Shortcode attributes. 
  453. */ 
  454. public function membership_details( $atts ) { 
  455. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MS_DETAILS ); 
  456.  
  457. $code = ''; 
  458.  
  459. $data = apply_filters( 
  460. 'ms_controller_shortcode_membership_details_atts',  
  461. shortcode_atts( 
  462. array( 
  463. 'id' => 0,  
  464. 'label' => __( 'Membership details:', 'membership2' ),  
  465. ),  
  466. $atts 
  467. ); 
  468. extract( $data ); 
  469.  
  470. if ( ! empty( $id ) ) { 
  471. $membership = MS_Factory::load( 'MS_Model_Membership', $id ); 
  472. $code = sprintf( 
  473. '%1$s %2$s',  
  474. $label,  
  475. $membership->get_description() 
  476. ); 
  477.  
  478. $code = trim( $code ); 
  479.  
  480. $code = sprintf( 
  481. '<span class="ms-membership-details ms-membership-%1$s">%2$s</span>',  
  482. esc_attr( $id ),  
  483. $code 
  484. ); 
  485.  
  486. return apply_filters( 
  487. 'ms_controller_shortcode_membership_details',  
  488. $code,  
  489. $atts,  
  490. $this 
  491. ); 
  492.  
  493. /** 
  494. * Display the "Membership2" message. 
  495. * @since 1.0.0 
  496. * @param mixed[] $atts Shortcode attributes. 
  497. */ 
  498. public function protected_content( $atts ) { 
  499. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_PROTECTED ); 
  500.  
  501. global $post; 
  502.  
  503. $setting = MS_Plugin::instance()->settings; 
  504. $member = MS_Model_Member::get_current_member(); 
  505.  
  506. if ( count( $member->subscriptions ) ) { 
  507. $sub = $member->get_subscription( 'priority' ); 
  508. $protection_msg = $setting->get_protection_message( 
  509. MS_Model_Settings::PROTECTION_MSG_CONTENT,  
  510. $sub->membership_id 
  511. ); 
  512. } else { 
  513. $protection_msg = $setting->get_protection_message( 
  514. MS_Model_Settings::PROTECTION_MSG_CONTENT 
  515. ); 
  516.  
  517. $html = '<div class="ms-protected-content">'; 
  518. if ( ! empty( $protection_msg ) ) { 
  519. $html .= $protection_msg; 
  520.  
  521. if ( ! MS_Model_Member::is_logged_in() ) { 
  522. $has_login_form = MS_Helper_Shortcode::has_shortcode( 
  523. MS_Helper_Shortcode::SCODE_LOGIN,  
  524. $post->post_content 
  525. ); 
  526.  
  527. if ( ! $has_login_form ) { 
  528. $scode = '[' . MS_Helper_Shortcode::SCODE_LOGIN . ']'; 
  529. $html .= do_shortcode( $scode ); 
  530. $html .= '</div>'; 
  531.  
  532. return apply_filters( 
  533. 'ms_controller_shortcode_protected_content',  
  534. $html,  
  535. $this 
  536. ); 
  537.  
  538. /** 
  539. * Membership login shortcode callback function. 
  540. * @since 1.0.0 
  541. * @param mixed[] $atts Shortcode attributes. 
  542. */ 
  543. public function membership_login( $atts ) { 
  544. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_LOGIN ); 
  545.  
  546. $data = apply_filters( 
  547. 'ms_controller_shortcode_membership_login_atts',  
  548. shortcode_atts( 
  549. array( 
  550. 'holder' => 'div',  
  551. 'holderclass' => 'ms-login-form',  
  552. 'item' => '',  
  553. 'itemclass' => '',  
  554. 'postfix' => '',  
  555. 'prefix' => '',  
  556. 'wrapwith' => '',  
  557. 'wrapwithclass' => '',  
  558. 'redirect_login' => MS_Model_Pages::get_url_after_login(),  
  559. 'redirect_logout' => MS_Model_Pages::get_url_after_logout(),  
  560. 'header' => true,  
  561. 'register' => true,  
  562. 'title' => '',  
  563. 'show_note' => true, // Show the "you are not logged in" note? 
  564. 'form' => '', // [login|lost|reset|logout] 
  565. 'show_labels' => false,  
  566. 'autofocus' => true,  
  567. 'nav_pos' => 'top', // [top|bottom] 
  568.  
  569. // form="login" 
  570. 'show_remember' => true,  
  571. 'label_username' => __( 'Username', 'membership2' ),  
  572. 'label_password' => __( 'Password', 'membership2' ),  
  573. 'label_remember' => __( 'Remember Me', 'membership2' ),  
  574. 'label_log_in' => __( 'Log In', 'membership2' ),  
  575. 'id_login_form' => 'loginform',  
  576. 'id_username' => 'user_login',  
  577. 'id_password' => 'user_pass',  
  578. 'id_remember' => 'rememberme',  
  579. 'id_login' => 'wp-submit',  
  580. 'value_username' => '',  
  581. 'value_remember' => false,  
  582.  
  583. // form="lost" 
  584. 'label_lost_username' => __( 'Username or E-mail', 'membership2' ),  
  585. 'label_lostpass' => __( 'Reset Password', 'membership2' ),  
  586. 'id_lost_form' => 'lostpasswordform',  
  587. 'id_lost_username' => 'user_login',  
  588. 'id_lostpass' => 'wp-submit',  
  589. 'value_username' => '',  
  590. ),  
  591. $atts 
  592. ); 
  593.  
  594. $data['header'] = lib3()->is_true( $data['header'] ); 
  595. $data['register'] = lib3()->is_true( $data['register'] ); 
  596. $data['show_note'] = lib3()->is_true( $data['show_note'] ); 
  597. $data['show_labels'] = lib3()->is_true( $data['show_labels'] ); 
  598. $data['show_remember'] = lib3()->is_true( $data['show_remember'] ); 
  599. $data['value_remember'] = lib3()->is_true( $data['value_remember'] ); 
  600. $data['autofocus'] = lib3()->is_true( $data['autofocus'] ); 
  601.  
  602. $view = MS_Factory::create( 'MS_View_Shortcode_Login' ); 
  603. $view->data = apply_filters( 'ms_view_shortcode_login_data', $data, $this ); 
  604.  
  605. return $view->to_html(); 
  606.  
  607. /** 
  608. * Membership logout shortcode callback function. 
  609. * @since 1.0.0 
  610. * @param mixed[] $atts Shortcode attributes. 
  611. */ 
  612. public function membership_logout( $atts ) { 
  613. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_LOGOUT ); 
  614.  
  615. $data = apply_filters( 
  616. 'ms_controller_shortcode_membership_logout_atts',  
  617. shortcode_atts( 
  618. array( 
  619. 'holder' => 'div',  
  620. 'holderclass' => 'ms-logout-form',  
  621. 'redirect' => MS_Model_Pages::get_url_after_logout(),  
  622. ),  
  623. $atts 
  624. ); 
  625.  
  626. // The form attribute triggers the logout-link to be displayed. 
  627. $data['form'] = 'logout'; 
  628. $data['redirect_logout'] = $data['redirect']; 
  629.  
  630. $view = MS_Factory::create( 'MS_View_Shortcode_Login' ); 
  631. $view->data = apply_filters( 'ms_view_shortcode_logout_data', $data, $this ); 
  632.  
  633. return $view->to_html(); 
  634.  
  635. /** 
  636. * Membership account page shortcode callback function. 
  637. * @since 1.0.0 
  638. * @param mixed[] $atts Shortcode attributes. 
  639. */ 
  640. public function membership_account( $atts ) { 
  641. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MS_ACCOUNT ); 
  642.  
  643. $data = apply_filters( 
  644. 'ms_controller_shortcode_membership_account_atts',  
  645. shortcode_atts( 
  646. array( 
  647. 'show_membership' => true,  
  648. 'show_membership_change' => true,  
  649. 'membership_title' => __( 'Your Membership', 'membership2' ),  
  650. 'membership_change_label' => __( 'Change', 'membership2' ),  
  651. 'show_profile' => true,  
  652. 'show_profile_change' => true,  
  653. 'profile_title' => __( 'Personal details', 'membership2' ),  
  654. 'profile_change_label' => __( 'Edit', 'membership2' ),  
  655. 'show_invoices' => true,  
  656. 'limit_invoices' => 10,  
  657. 'show_all_invoices' => true,  
  658. 'invoices_title' => __( 'Invoices', 'membership2' ),  
  659. 'invoices_details_label' => __( 'View all', 'membership2' ),  
  660. 'show_activity' => true,  
  661. 'limit_activities' => 10,  
  662. 'show_all_activities' => true,  
  663. 'activity_title' => __( 'Activities', 'membership2' ),  
  664. 'activity_details_label' => __( 'View all', 'membership2' ),  
  665. ),  
  666. $atts 
  667. ); 
  668.  
  669. $data['show_membership'] = lib3()->is_true( $data['show_membership'] ); 
  670. $data['show_membership_change'] = lib3()->is_true( $data['show_membership_change'] ); 
  671. $data['show_profile'] = lib3()->is_true( $data['show_profile'] ); 
  672. $data['show_profile_change'] = lib3()->is_true( $data['show_profile_change'] ); 
  673. $data['show_invoices'] = lib3()->is_true( $data['show_invoices'] ); 
  674. $data['show_all_invoices'] = lib3()->is_true( $data['show_all_invoices'] ); 
  675. $data['show_activity'] = lib3()->is_true( $data['show_activity'] ); 
  676. $data['show_all_activities'] = lib3()->is_true( $data['show_all_activities'] ); 
  677.  
  678. $data['limit_invoices'] = absint( $data['limit_invoices'] ); 
  679. $data['limit_activities'] = absint( $data['limit_activities'] ); 
  680.  
  681. $data['member'] = MS_Model_Member::get_current_member(); 
  682. $data['membership'] = array(); 
  683.  
  684. $subscriptions = MS_Model_Relationship::get_subscriptions( 
  685. array( 
  686. 'user_id' => $data['member']->id,  
  687. 'status' => 'all',  
  688. ); 
  689. if ( is_array( $subscriptions ) ) { 
  690. foreach ( $subscriptions as $subscription ) { 
  691. // Do not display system-memberships in Account 
  692. if ( $subscription->is_system() ) { continue; } 
  693.  
  694. // Do not display deactivated memberships in Account 
  695. if ( $subscription->get_status() == MS_Model_Relationship::STATUS_DEACTIVATED ) { continue; } 
  696.  
  697. $data['subscription'][] = $subscription; 
  698.  
  699. $data['invoices'] = MS_Model_Invoice::get_public_invoices( 
  700. $data['member']->id,  
  701. $data['limit_invoices'] 
  702. ); 
  703.  
  704. $data['events'] = MS_Model_Event::get_events( 
  705. array( 
  706. 'author' => $data['member']->id,  
  707. 'posts_per_page' => $data['limit_activities'],  
  708. ); 
  709.  
  710. $view = MS_Factory::create( 'MS_View_Shortcode_Account' ); 
  711. $view->data = apply_filters( 
  712. 'ms_view_shortcode_account_data',  
  713. $data,  
  714. $this 
  715. ); 
  716.  
  717. return $view->to_html(); 
  718.  
  719. /** 
  720. * Link to the Membership account page shortcode. 
  721. * @since 1.0.0 
  722. * @param mixed[] $atts Shortcode attributes. 
  723. */ 
  724. public function membership_account_link( $atts ) { 
  725. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MS_ACCOUNT_LINK ); 
  726.  
  727. $html = ''; 
  728.  
  729. $data = apply_filters( 
  730. 'ms_controller_shortcode_membership_account_link_atts',  
  731. shortcode_atts( 
  732. array( 
  733. 'label' => __( 'Visit your account page for more information.', 'membership2' ),  
  734. ),  
  735. $atts 
  736. ); 
  737.  
  738. $html = sprintf( 
  739. '<a href="%1$s">%2$s</a>',  
  740. MS_Model_Pages::get_page_url( MS_Model_Pages::MS_PAGE_ACCOUNT ),  
  741. $data['label'] 
  742. ); 
  743.  
  744. return apply_filters( 
  745. 'ms_controller_shortcode_protected_content',  
  746. $html,  
  747. $this 
  748. ); 
  749.  
  750. /** 
  751. * Membership invoice shortcode callback function. 
  752. * @since 1.0.0 
  753. * @param mixed[] $atts Shortcode attributes. 
  754. */ 
  755. public function membership_invoice( $atts ) { 
  756. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MS_INVOICE ); 
  757.  
  758. $data = apply_filters( 
  759. 'ms_controller_shortcode_invoice_atts',  
  760. shortcode_atts( 
  761. array( 
  762. 'post_id' => 0,  
  763. 'id' => 0,  
  764. 'pay_button' => 1,  
  765. ),  
  766. $atts,  
  767. MS_Helper_Shortcode::SCODE_MS_INVOICE 
  768. ); 
  769.  
  770. if ( ! empty( $data['id'] ) ) { 
  771. $data['post_id'] = $data['id']; 
  772.  
  773. if ( ! empty( $data['post_id'] ) ) { 
  774. $invoice = MS_Factory::load( 'MS_Model_Invoice', $data['post_id'] ); 
  775. $subscription = MS_Factory::load( 'MS_Model_Relationship', $invoice->ms_relationship_id ); 
  776.  
  777. $data['invoice'] = $invoice; 
  778. $data['member'] = MS_Factory::load( 'MS_Model_Member', $invoice->user_id ); 
  779. $data['ms_relationship'] = $subscription; 
  780. $data['membership'] = $subscription->get_membership(); 
  781. $data['gateway'] = MS_Model_Gateway::factory( $invoice->gateway_id ); 
  782.  
  783. $view = MS_Factory::create( 'MS_View_Shortcode_Invoice' ); 
  784. $view->data = apply_filters( 
  785. 'ms_view_shortcode_invoice_data',  
  786. $data,  
  787. $this 
  788. ); 
  789.  
  790. return $view->to_html(); 
  791.  
  792. /** 
  793. * Text note shortcode callback function. 
  794. * @since 1.0.0 
  795. * @param mixed[] $atts Shortcode attributes. 
  796. */ 
  797. public function ms_note( $atts, $content = '' ) { 
  798. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_NOTE ); 
  799.  
  800. $atts = apply_filters( 
  801. 'ms_controller_shortcode_note_atts',  
  802. shortcode_atts( 
  803. array( 
  804. 'type' => 'info',  
  805. 'class' => '',  
  806. ),  
  807. $atts,  
  808. MS_Helper_Shortcode::SCODE_NOTE 
  809. ); 
  810.  
  811. $class = $atts['class']; 
  812.  
  813. switch ( $atts['type'] ) { 
  814. case 'info': 
  815. case 'success': 
  816. $class .= ' ms-alert-success'; 
  817. break; 
  818.  
  819. case 'error': 
  820. case 'warning': 
  821. $class .= ' ms-alert-error'; 
  822. break; 
  823.  
  824. /** 
  825. * The $content of the notice is translated! 
  826. * This gives translators the option to translate even custom messages 
  827. * that are entered into the shortcode! 
  828. * @since 1.0.0 
  829. */ 
  830. $content = sprintf( 
  831. '<p class="ms-alert-box %1$s">%2$s</p> ',  
  832. $class,  
  833. __( $content, 'membership2' ) 
  834. ); 
  835.  
  836. $content = do_shortcode( $content ); 
  837.  
  838. return apply_filters( 
  839. 'ms_controller_shortcode_ms_note',  
  840. $content,  
  841. $this 
  842. ); 
  843.  
  844. /** 
  845. * Display a green text note. 
  846. * @since 1.0.0 
  847. * @deprecated since 1.0.4.5 
  848. * @param mixed[] $atts Shortcode attributes. 
  849. */ 
  850. public function ms_green_note( $atts, $content = '' ) { 
  851. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_GREEN_NOTE ); 
  852.  
  853. $content = $this->ms_note( array( 'type' => 'info' ), $content ); 
  854.  
  855. return apply_filters( 
  856. 'ms_controller_shortcode_ms_green_note',  
  857. $content,  
  858. $this 
  859. ); 
  860.  
  861. /** 
  862. * Display a red text note. 
  863. * @since 1.0.0 
  864. * @deprecated since 1.0.4.5 
  865. * @param mixed[] $atts Shortcode attributes. 
  866. */ 
  867. public function ms_red_note( $atts, $content = '' ) { 
  868. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_RED_NOTE ); 
  869.  
  870. $content = $this->ms_note( array( 'type' => 'warning' ), $content ); 
  871.  
  872. return apply_filters( 
  873. 'ms_controller_shortcode_ms_red_note',  
  874. $content,  
  875. $this 
  876. ); 
  877.  
  878. /** 
  879. * Shortcode callback: Show message only to certain users. 
  880. * @since 1.0.0 
  881. * @param mixed[] $atts Shortcode attributes. 
  882. */ 
  883. public function show_to_user( $atts, $content = '' ) { 
  884. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_USER ); 
  885.  
  886. $data = apply_filters( 
  887. 'ms_controller_shortcode_show_to_user_atts',  
  888. shortcode_atts( 
  889. array( 
  890. 'type' => 'loggedin',  
  891. 'msg' => '',  
  892. ),  
  893. $atts 
  894. ); 
  895.  
  896. extract( $data ); 
  897. $access = false; 
  898.  
  899. $user_type = 'guest'; 
  900. if ( is_user_logged_in() ) { 
  901. $user_type = 'loggedin'; 
  902.  
  903. if ( MS_Model_Member::is_admin_user() ) { 
  904. $user_type = 'admin'; 
  905.  
  906. $class = 'ms-user-is-' . $user_type; 
  907.  
  908. switch ( $type ) { 
  909. case 'all': 
  910. $access = true; 
  911. break; 
  912.  
  913. case 'loggedin': 
  914. case 'login': 
  915. $access = in_array( $user_type, array( 'loggedin', 'admin' ) ); 
  916. break; 
  917.  
  918. case 'guest': 
  919. $access = ($user_type === 'guest' ); 
  920. break; 
  921.  
  922. case 'admin': 
  923. $access = ( $user_type === 'admin' ); 
  924. break; 
  925.  
  926. if ( ! $access ) { 
  927. $content = $msg; 
  928. $class .= ' ms-user-not-' . $type; 
  929.  
  930. $content = sprintf( 
  931. '<div class="ms-user %1$s">%2$s</div>',  
  932. esc_attr( $class ),  
  933. do_shortcode( $content ) 
  934. ); 
  935.  
  936. return apply_filters( 
  937. 'ms_controller_shortcode_show_to_user',  
  938. $content,  
  939. $this 
  940. ); 
  941.  
  942. /** 
  943. * Shortcode callback: Show member infos. 
  944. * @since 1.0.0 
  945. * @param mixed[] $atts Shortcode attributes. 
  946. */ 
  947. public function ms_member_info( $atts, $content = '' ) { 
  948. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MEMBER_INFO ); 
  949.  
  950. $data = apply_filters( 
  951. 'ms_controller_shortcode_member_info_atts',  
  952. shortcode_atts( 
  953. array( 
  954. 'value' => 'fullname',  
  955. 'before' => '<span>',  
  956. 'after' => '</span>',  
  957. 'default' => '',  
  958. 'custom_field' => '', // used for: custom 
  959. 'list_before' => '', // used for: membership 
  960. 'list_after' => '', // used for: membership 
  961. 'list_separator' => ', ', // used for: membership 
  962. 'user' => 0, // user-id; 0 = current user 
  963. ),  
  964. $atts 
  965. ); 
  966.  
  967. $data['user'] = intval( $data['user'] ); 
  968. if ( $data['user'] < 1 ) { 
  969. $data['user'] = get_current_user_id(); 
  970. $member = MS_Factory::load( 'MS_Model_Member', $data['user'] ); 
  971. $content = ''; 
  972.  
  973. switch ( $data['value'] ) { 
  974. case 'email': 
  975. $content = $member->email; 
  976. break; 
  977.  
  978. case 'firstname': 
  979. case 'first name': 
  980. $content = $member->first_name; 
  981. break; 
  982.  
  983. case 'lastname': 
  984. case 'last name': 
  985. $content = $member->last_name; 
  986. break; 
  987.  
  988. case 'fullname': 
  989. case 'full name': 
  990. $content = $member->first_name . ' ' . $member->last_name; 
  991. break; 
  992.  
  993. case 'memberships': 
  994. case 'membership': 
  995. $ids = $member->get_membership_ids(); 
  996. $content = array(); 
  997. foreach ( $ids as $id ) { 
  998. $membership = MS_Factory::load( 'MS_Model_Membership', $id ); 
  999. if ( $membership->is_system() ) { continue; } 
  1000. $content[] = $membership->name; 
  1001. break; 
  1002.  
  1003. case 'custom': 
  1004. $content = $member->get_custom_data( $data['custom_field'] ); 
  1005. break; 
  1006.  
  1007. if ( is_array( $content ) ) { 
  1008. if ( $content ) { 
  1009. $content = 
  1010. $data['list_before'] . 
  1011. implode( $data['list_separator'], $content ) . 
  1012. $data['list_after']; 
  1013. } else { 
  1014. $content = ''; 
  1015. } else { 
  1016. $content = (string) $content; 
  1017.  
  1018. $content = trim( $content ); 
  1019. if ( $content ) { 
  1020. $content = $data['before'] . 
  1021. $content . 
  1022. $data['after']; 
  1023. } else { 
  1024. $content = $data['default']; 
  1025.  
  1026. return apply_filters( 
  1027. 'ms_controller_shortcode_member_info',  
  1028. $content,  
  1029. $this 
  1030. ); 
  1031.  
  1032.  
  1033. /** 
  1034. * Special Shortcode Callback: Replace shortcodes with empty value. 
  1035. * All Shortcodes use this callback function 
  1036. * when Content Protection is DISABLED! 
  1037. * @since 1.0.0 
  1038. * @param mixed[] $atts Shortcode attributes. 
  1039. * @param string $content 
  1040. * @return string 
  1041. */ 
  1042. public function ms_no_value( $atts, $content = '' ) { 
  1043. static $Done = false; 
  1044.  
  1045. if ( $Done ) { return ''; } 
  1046. $Done = true; 
  1047.  
  1048. if ( MS_Model_Member::is_admin_user() ) { 
  1049. $content = sprintf( 
  1050. '<p class="ms-alert-box ms-alert-error ms-unprotected">%s<br /><br /><em>(%s)</em></p>',  
  1051. __( 
  1052. 'Content Protection is disabled. Please enable the protection to see this shortcode.',  
  1053. 'membership2' 
  1054. ),  
  1055. __( 
  1056. 'This message is only displayed to Site Administrators',  
  1057. 'membership2' 
  1058. ); 
  1059. } else { 
  1060. $content = ''; 
  1061.  
  1062. return apply_filters( 
  1063. 'ms_controller_shortcode_ms_no_value',  
  1064. $content,  
  1065. $this 
  1066. ); 
  1067.  
  1068. /** 
  1069. * Special Shortcode Callback: Strip the shortcode tag without changing the 
  1070. * original content. 
  1071. * This is used for Admin users to strip all content-protection tags. 
  1072. * @since 1.0.0 
  1073. * @param mixed[] $atts Shortcode attributes. 
  1074. * @param string $content 
  1075. * @return string 
  1076. */ 
  1077. public function hide_shortcode( $atts, $content = '' ) { 
  1078. return do_shortcode( $content ); 
  1079.