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. if ( ! $member->is_valid() || ! $member->has_membership() ) { 
  263. foreach( $memberships as $key => $membership ) { 
  264. if( isset( $membership->update_denied['guest'] ) && lib3()->is_true( $membership->update_denied['guest'] ) ) { 
  265. unset( $memberships[$key] ); 
  266.  
  267.  
  268. $data['memberships'] = $memberships; 
  269. $move_from_ids = array(); 
  270.  
  271. // When Multiple memberships is not enabled, a member should move to another membership. 
  272. if ( ! MS_Model_Addon::is_enabled( MS_Model_Addon::ADDON_MULTI_MEMBERSHIPS ) ) { 
  273. // Membership Relationship status which can move to another one 
  274. $valid_status = array( 
  275. MS_Model_Relationship::STATUS_TRIAL,  
  276. MS_Model_Relationship::STATUS_ACTIVE,  
  277. MS_Model_Relationship::STATUS_EXPIRED,  
  278. ); 
  279.  
  280. foreach ( $data['member']->subscriptions as $subscription ) { 
  281. if ( $subscription->is_system() ) { continue; } 
  282.  
  283. if ( in_array( $subscription->status, $valid_status ) ) { 
  284. $move_from_ids[] = $subscription->membership_id; 
  285. foreach ( $data['memberships'] as $key => $membership ) { 
  286. $data['memberships'][$key]->_move_from = $move_from_ids; 
  287. } else { 
  288. foreach ( $data['memberships'] as $key => $membership ) { 
  289. $move_from_ids = $member->cancel_ids_on_subscription( 
  290. $membership->id 
  291. ); 
  292.  
  293. $data['memberships'][$key]->_move_from = $move_from_ids; 
  294.  
  295. $data['action'] = MS_Helper_Membership::MEMBERSHIP_ACTION_SIGNUP; 
  296. $data['step'] = MS_Controller_Frontend::STEP_PAYMENT_TABLE; 
  297.  
  298. $view = MS_Factory::create( 'MS_View_Shortcode_MembershipSignup' ); 
  299. $view->data = apply_filters( 
  300. 'ms_view_shortcode_membershipsignup_data',  
  301. $data,  
  302. $this 
  303. ); 
  304.  
  305. return $view->to_html(); 
  306.  
  307. /** 
  308. * Membership title shortcode callback function. 
  309. * @since 1.0.0 
  310. * @param mixed[] $atts Shortcode attributes. 
  311. */ 
  312. public function membership_title( $atts ) { 
  313. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MS_TITLE ); 
  314.  
  315. $code = ''; 
  316.  
  317. $data = apply_filters( 
  318. 'ms_controller_shortcode_membership_title_atts',  
  319. shortcode_atts( 
  320. array( 
  321. 'id' => 0,  
  322. 'label' => __( 'Membership title:', 'membership2' ),  
  323. 'title' => '', // deprecated @since 1.0.0 
  324. ),  
  325. $atts 
  326. ); 
  327. extract( $data ); 
  328.  
  329. if ( ! empty( $id ) ) { 
  330. $membership = MS_Factory::load( 'MS_Model_Membership', $id ); 
  331. $code = sprintf( 
  332. '%1$s %2$s',  
  333. $label,  
  334. $membership->name 
  335. ); 
  336.  
  337. $code = trim( $code ); 
  338. } else { 
  339. $code = $title; 
  340.  
  341. $code = sprintf( 
  342. '<span class="ms-membership-title ms-membership-%1$s">%2$s</span>',  
  343. esc_attr( $id ),  
  344. $code 
  345. ); 
  346.  
  347. return apply_filters( 
  348. 'ms_controller_shortcode_membership_title',  
  349. $code,  
  350. $atts,  
  351. $this 
  352. ); 
  353.  
  354. /** 
  355. * Membership price shortcode callback function. 
  356. * @since 1.0.0 
  357. * @param mixed[] $atts Shortcode attributes. 
  358. */ 
  359. public function membership_price( $atts ) { 
  360. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MS_PRICE ); 
  361.  
  362. $code = 0; 
  363.  
  364. $data = apply_filters( 
  365. 'ms_controller_shortcode_membership_price_atts',  
  366. shortcode_atts( 
  367. array( 
  368. 'id' => 0,  
  369. 'currency' => true,  
  370. 'label' => __( 'Membership price:', 'membership2' ),  
  371. ),  
  372. $atts 
  373. ); 
  374. extract( $data ); 
  375.  
  376. if ( ! empty( $id ) ) { 
  377. if ( lib3()->is_true( $currency ) ) { 
  378. $settings = MS_Factory::load( 'MS_Model_Settings' ); 
  379. $currency = $settings->currency; 
  380. } else { 
  381. $currency = ''; 
  382.  
  383. $membership = MS_Factory::load( 'MS_Model_Membership', $id ); 
  384. $code = sprintf( 
  385. '%1$s %2$s %3$s',  
  386. $label,  
  387. $currency,  
  388. $membership->total_price 
  389. ); 
  390.  
  391. $code = trim( $code ); 
  392.  
  393. $code = sprintf( 
  394. '<span class="ms-membership-price ms-membership-%1$s price">%2$s</span>',  
  395. esc_attr( $id ),  
  396. $code 
  397. ); 
  398.  
  399. do_action( 'ms_show_prices' ); 
  400. return apply_filters( 
  401. 'ms_controller_shortcode_membership_price',  
  402. $code,  
  403. $atts,  
  404. $this 
  405. ); 
  406.  
  407. /** 
  408. * Buy membership button. 
  409. * @since 1.0.0 
  410. * @param mixed[] $atts Shortcode attributes. 
  411. */ 
  412. public function membership_buy( $atts ) { 
  413. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MS_BUY ); 
  414.  
  415. $code = ''; 
  416.  
  417. $data = apply_filters( 
  418. 'ms_controller_shortcode_membership_buy_atts',  
  419. shortcode_atts( 
  420. array( 
  421. 'id' => 0,  
  422. 'label' => __( 'Signup', 'membership2' ),  
  423. ),  
  424. $atts 
  425. ); 
  426. extract( $data ); 
  427.  
  428. if ( ! empty( $id ) ) { 
  429. $membership = MS_Factory::load( 'MS_Model_Membership', $id ); 
  430. $data['action'] = MS_Helper_Membership::MEMBERSHIP_ACTION_SIGNUP; 
  431. $data['step'] = MS_Controller_Frontend::STEP_PAYMENT_TABLE; 
  432.  
  433. $view = MS_Factory::create( 'MS_View_Shortcode_MembershipSignup' ); 
  434. $view->data = apply_filters( 
  435. 'ms_view_shortcode_membershipsignup_data',  
  436. $data,  
  437. $this 
  438. ); 
  439.  
  440. $code = $view->signup_form( $membership, $label ); 
  441.  
  442. $code = sprintf( 
  443. '<span class="ms-membership-buy ms-membership-%1$s">%2$s</span>',  
  444. esc_attr( $id ),  
  445. $code 
  446. ); 
  447.  
  448. return apply_filters( 
  449. 'ms_controller_shortcode_membership_buy',  
  450. $code,  
  451. $atts,  
  452. $this 
  453. ); 
  454.  
  455. /** 
  456. * Membership details shortcode callback function. 
  457. * @since 1.0.0 
  458. * @param mixed[] $atts Shortcode attributes. 
  459. */ 
  460. public function membership_details( $atts ) { 
  461. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MS_DETAILS ); 
  462.  
  463. $code = ''; 
  464.  
  465. $data = apply_filters( 
  466. 'ms_controller_shortcode_membership_details_atts',  
  467. shortcode_atts( 
  468. array( 
  469. 'id' => 0,  
  470. 'label' => __( 'Membership details:', 'membership2' ),  
  471. ),  
  472. $atts 
  473. ); 
  474. extract( $data ); 
  475.  
  476. if ( ! empty( $id ) ) { 
  477. $membership = MS_Factory::load( 'MS_Model_Membership', $id ); 
  478. $code = sprintf( 
  479. '%1$s %2$s',  
  480. $label,  
  481. $membership->get_description() 
  482. ); 
  483.  
  484. $code = trim( $code ); 
  485.  
  486. $code = sprintf( 
  487. '<span class="ms-membership-details ms-membership-%1$s">%2$s</span>',  
  488. esc_attr( $id ),  
  489. $code 
  490. ); 
  491.  
  492. return apply_filters( 
  493. 'ms_controller_shortcode_membership_details',  
  494. $code,  
  495. $atts,  
  496. $this 
  497. ); 
  498.  
  499. /** 
  500. * Display the "Membership2" message. 
  501. * @since 1.0.0 
  502. * @param mixed[] $atts Shortcode attributes. 
  503. */ 
  504. public function protected_content( $atts ) { 
  505. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_PROTECTED ); 
  506.  
  507. global $post; 
  508.  
  509. $setting = MS_Plugin::instance()->settings; 
  510. $member = MS_Model_Member::get_current_member(); 
  511.  
  512. if( defined( 'MS_PROTECTED_MESSAGE_REVERSE_RULE' ) && MS_PROTECTED_MESSAGE_REVERSE_RULE && isset( $_REQUEST['membership_id'] ) ) { 
  513. $protection_msg = $setting->get_protection_message( 
  514. MS_Model_Settings::PROTECTION_MSG_CONTENT,  
  515. $_REQUEST['membership_id'] 
  516. ); 
  517. }else{ 
  518. if ( count( $member->subscriptions ) ) { 
  519. $sub = $member->get_subscription( 'priority' ); 
  520. $protection_msg = $setting->get_protection_message( 
  521. MS_Model_Settings::PROTECTION_MSG_CONTENT,  
  522. $sub->membership_id 
  523. ); 
  524. } else { 
  525. $protection_msg = $setting->get_protection_message( 
  526. MS_Model_Settings::PROTECTION_MSG_CONTENT 
  527. ); 
  528.  
  529. $html = '<div class="ms-protected-content">'; 
  530. if ( ! empty( $protection_msg ) ) { 
  531. $html .= $protection_msg; 
  532.  
  533. if ( ! MS_Model_Member::is_logged_in() ) { 
  534. $has_login_form = MS_Helper_Shortcode::has_shortcode( 
  535. MS_Helper_Shortcode::SCODE_LOGIN,  
  536. $post->post_content 
  537. ); 
  538.  
  539. if ( ! $has_login_form ) { 
  540. $scode = '[' . MS_Helper_Shortcode::SCODE_LOGIN . ']'; 
  541. $html .= do_shortcode( $scode ); 
  542. $html .= '</div>'; 
  543.  
  544. return apply_filters( 
  545. 'ms_controller_shortcode_protected_content',  
  546. $html,  
  547. $this 
  548. ); 
  549.  
  550. /** 
  551. * Membership login shortcode callback function. 
  552. * @since 1.0.0 
  553. * @param mixed[] $atts Shortcode attributes. 
  554. */ 
  555. public function membership_login( $atts ) { 
  556. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_LOGIN ); 
  557.  
  558. $data = apply_filters( 
  559. 'ms_controller_shortcode_membership_login_atts',  
  560. shortcode_atts( 
  561. array( 
  562. 'holder' => 'div',  
  563. 'holderclass' => 'ms-login-form',  
  564. 'item' => '',  
  565. 'itemclass' => '',  
  566. 'postfix' => '',  
  567. 'prefix' => '',  
  568. 'wrapwith' => '',  
  569. 'wrapwithclass' => '',  
  570. 'redirect_login' => MS_Model_Pages::get_url_after_login(),  
  571. 'redirect_logout' => MS_Model_Pages::get_url_after_logout(),  
  572. 'header' => true,  
  573. 'register' => true,  
  574. 'title' => '',  
  575. 'show_note' => true, // Show the "you are not logged in" note? 
  576. 'form' => '', // [login|lost|reset|logout] 
  577. 'show_labels' => false,  
  578. 'autofocus' => true,  
  579. 'nav_pos' => 'top', // [top|bottom] 
  580.  
  581. // form="login" 
  582. 'show_remember' => true,  
  583. 'label_username' => __( 'Username', 'membership2' ),  
  584. 'label_password' => __( 'Password', 'membership2' ),  
  585. 'label_remember' => __( 'Remember Me', 'membership2' ),  
  586. 'label_log_in' => __( 'Log In', 'membership2' ),  
  587. 'id_login_form' => 'loginform',  
  588. 'id_username' => 'user_login',  
  589. 'id_password' => 'user_pass',  
  590. 'id_remember' => 'rememberme',  
  591. 'id_login' => 'wp-submit',  
  592. 'value_username' => '',  
  593. 'value_remember' => false,  
  594.  
  595. // form="lost" 
  596. 'label_lost_username' => __( 'Username or E-mail', 'membership2' ),  
  597. 'label_lostpass' => __( 'Reset Password', 'membership2' ),  
  598. 'id_lost_form' => 'lostpasswordform',  
  599. 'id_lost_username' => 'user_login',  
  600. 'id_lostpass' => 'wp-submit',  
  601. 'value_username' => '',  
  602. ),  
  603. $atts 
  604. ); 
  605.  
  606. $data['header'] = lib3()->is_true( $data['header'] ); 
  607. $data['register'] = lib3()->is_true( $data['register'] ); 
  608. $data['show_note'] = lib3()->is_true( $data['show_note'] ); 
  609. $data['show_labels'] = lib3()->is_true( $data['show_labels'] ); 
  610. $data['show_remember'] = lib3()->is_true( $data['show_remember'] ); 
  611. $data['value_remember'] = lib3()->is_true( $data['value_remember'] ); 
  612. $data['autofocus'] = lib3()->is_true( $data['autofocus'] ); 
  613.  
  614. $view = MS_Factory::create( 'MS_View_Shortcode_Login' ); 
  615. $view->data = apply_filters( 'ms_view_shortcode_login_data', $data, $this ); 
  616.  
  617. return $view->to_html(); 
  618.  
  619. /** 
  620. * Membership logout shortcode callback function. 
  621. * @since 1.0.0 
  622. * @param mixed[] $atts Shortcode attributes. 
  623. */ 
  624. public function membership_logout( $atts ) { 
  625. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_LOGOUT ); 
  626.  
  627. $data = apply_filters( 
  628. 'ms_controller_shortcode_membership_logout_atts',  
  629. shortcode_atts( 
  630. array( 
  631. 'holder' => 'div',  
  632. 'holderclass' => 'ms-logout-form',  
  633. 'redirect' => MS_Model_Pages::get_url_after_logout(),  
  634. ),  
  635. $atts 
  636. ); 
  637.  
  638. // The form attribute triggers the logout-link to be displayed. 
  639. $data['form'] = 'logout'; 
  640. $data['redirect_logout'] = $data['redirect']; 
  641.  
  642. $view = MS_Factory::create( 'MS_View_Shortcode_Login' ); 
  643. $view->data = apply_filters( 'ms_view_shortcode_logout_data', $data, $this ); 
  644.  
  645. return $view->to_html(); 
  646.  
  647. /** 
  648. * Membership account page shortcode callback function. 
  649. * @since 1.0.0 
  650. * @param mixed[] $atts Shortcode attributes. 
  651. */ 
  652. public function membership_account( $atts ) { 
  653. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MS_ACCOUNT ); 
  654.  
  655. $data = apply_filters( 
  656. 'ms_controller_shortcode_membership_account_atts',  
  657. shortcode_atts( 
  658. array( 
  659. 'show_membership' => true,  
  660. 'show_membership_change' => true,  
  661. 'membership_title' => __( 'Your Membership', 'membership2' ),  
  662. 'membership_change_label' => __( 'Change', 'membership2' ),  
  663. 'show_profile' => true,  
  664. 'show_profile_change' => true,  
  665. 'profile_title' => __( 'Personal details', 'membership2' ),  
  666. 'profile_change_label' => __( 'Edit', 'membership2' ),  
  667. 'show_invoices' => true,  
  668. 'limit_invoices' => 10,  
  669. 'show_all_invoices' => true,  
  670. 'invoices_title' => __( 'Invoices', 'membership2' ),  
  671. 'invoices_details_label' => __( 'View all', 'membership2' ),  
  672. 'show_activity' => true,  
  673. 'limit_activities' => 10,  
  674. 'show_all_activities' => true,  
  675. 'activity_title' => __( 'Activities', 'membership2' ),  
  676. 'activity_details_label' => __( 'View all', 'membership2' ),  
  677. ),  
  678. $atts 
  679. ); 
  680.  
  681. $data['show_membership'] = lib3()->is_true( $data['show_membership'] ); 
  682. $data['show_membership_change'] = lib3()->is_true( $data['show_membership_change'] ); 
  683. $data['show_profile'] = lib3()->is_true( $data['show_profile'] ); 
  684. $data['show_profile_change'] = lib3()->is_true( $data['show_profile_change'] ); 
  685. $data['show_invoices'] = lib3()->is_true( $data['show_invoices'] ); 
  686. $data['show_all_invoices'] = lib3()->is_true( $data['show_all_invoices'] ); 
  687. $data['show_activity'] = lib3()->is_true( $data['show_activity'] ); 
  688. $data['show_all_activities'] = lib3()->is_true( $data['show_all_activities'] ); 
  689.  
  690. $data['limit_invoices'] = absint( $data['limit_invoices'] ); 
  691. $data['limit_activities'] = absint( $data['limit_activities'] ); 
  692.  
  693. $data['member'] = MS_Model_Member::get_current_member(); 
  694. $data['membership'] = array(); 
  695.  
  696. $subscriptions = MS_Model_Relationship::get_subscriptions( 
  697. array( 
  698. 'user_id' => $data['member']->id,  
  699. 'status' => 'all',  
  700. ); 
  701. if ( is_array( $subscriptions ) ) { 
  702. foreach ( $subscriptions as $subscription ) { 
  703. // Do not display system-memberships in Account 
  704. if ( $subscription->is_system() ) { continue; } 
  705.  
  706. // Do not display deactivated memberships in Account 
  707. if ( $subscription->get_status() == MS_Model_Relationship::STATUS_DEACTIVATED ) { continue; } 
  708.  
  709. $data['subscription'][] = $subscription; 
  710.  
  711. $data['invoices'] = MS_Model_Invoice::get_public_invoices( 
  712. $data['member']->id,  
  713. $data['limit_invoices'] 
  714. ); 
  715.  
  716. $data['events'] = MS_Model_Event::get_events( 
  717. array( 
  718. 'author' => $data['member']->id,  
  719. 'posts_per_page' => $data['limit_activities'],  
  720. ); 
  721.  
  722. $view = MS_Factory::create( 'MS_View_Shortcode_Account' ); 
  723. $view->data = apply_filters( 
  724. 'ms_view_shortcode_account_data',  
  725. $data,  
  726. $this 
  727. ); 
  728.  
  729. return $view->to_html(); 
  730.  
  731. /** 
  732. * Link to the Membership account page shortcode. 
  733. * @since 1.0.0 
  734. * @param mixed[] $atts Shortcode attributes. 
  735. */ 
  736. public function membership_account_link( $atts ) { 
  737. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MS_ACCOUNT_LINK ); 
  738.  
  739. $html = ''; 
  740.  
  741. $data = apply_filters( 
  742. 'ms_controller_shortcode_membership_account_link_atts',  
  743. shortcode_atts( 
  744. array( 
  745. 'label' => __( 'Visit your account page for more information.', 'membership2' ),  
  746. ),  
  747. $atts 
  748. ); 
  749.  
  750. $html = sprintf( 
  751. '<a href="%1$s">%2$s</a>',  
  752. MS_Model_Pages::get_page_url( MS_Model_Pages::MS_PAGE_ACCOUNT ),  
  753. $data['label'] 
  754. ); 
  755.  
  756. return apply_filters( 
  757. 'ms_controller_shortcode_protected_content',  
  758. $html,  
  759. $this 
  760. ); 
  761.  
  762. /** 
  763. * Membership invoice shortcode callback function. 
  764. * @since 1.0.0 
  765. * @param mixed[] $atts Shortcode attributes. 
  766. */ 
  767. public function membership_invoice( $atts ) { 
  768. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MS_INVOICE ); 
  769.  
  770. $data = apply_filters( 
  771. 'ms_controller_shortcode_invoice_atts',  
  772. shortcode_atts( 
  773. array( 
  774. 'post_id' => 0,  
  775. 'id' => 0,  
  776. 'pay_button' => 1,  
  777. ),  
  778. $atts,  
  779. MS_Helper_Shortcode::SCODE_MS_INVOICE 
  780. ); 
  781.  
  782. if ( ! empty( $data['id'] ) ) { 
  783. $data['post_id'] = $data['id']; 
  784.  
  785. if ( ! empty( $data['post_id'] ) ) { 
  786. $invoice = MS_Factory::load( 'MS_Model_Invoice', $data['post_id'] ); 
  787. $subscription = MS_Factory::load( 'MS_Model_Relationship', $invoice->ms_relationship_id ); 
  788.  
  789. $data['invoice'] = $invoice; 
  790. $data['member'] = MS_Factory::load( 'MS_Model_Member', $invoice->user_id ); 
  791. $data['ms_relationship'] = $subscription; 
  792. $data['membership'] = $subscription->get_membership(); 
  793. $data['gateway'] = MS_Model_Gateway::factory( $invoice->gateway_id ); 
  794.  
  795. $view = MS_Factory::create( 'MS_View_Shortcode_Invoice' ); 
  796. $view->data = apply_filters( 
  797. 'ms_view_shortcode_invoice_data',  
  798. $data,  
  799. $this 
  800. ); 
  801.  
  802. return $view->to_html(); 
  803.  
  804. /** 
  805. * Text note shortcode callback function. 
  806. * @since 1.0.0 
  807. * @param mixed[] $atts Shortcode attributes. 
  808. */ 
  809. public function ms_note( $atts, $content = '' ) { 
  810. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_NOTE ); 
  811.  
  812. lib3()->ui->css( 'ms-styles' ); 
  813.  
  814. $atts = apply_filters( 
  815. 'ms_controller_shortcode_note_atts',  
  816. shortcode_atts( 
  817. array( 
  818. 'type' => 'info',  
  819. 'class' => '',  
  820. ),  
  821. $atts,  
  822. MS_Helper_Shortcode::SCODE_NOTE 
  823. ); 
  824.  
  825. $class = $atts['class']; 
  826.  
  827. switch ( $atts['type'] ) { 
  828. case 'info': 
  829. case 'success': 
  830. $class .= ' ms-alert-success'; 
  831. break; 
  832.  
  833. case 'error': 
  834. case 'warning': 
  835. $class .= ' ms-alert-error'; 
  836. break; 
  837.  
  838. /** 
  839. * The $content of the notice is translated! 
  840. * This gives translators the option to translate even custom messages 
  841. * that are entered into the shortcode! 
  842. * @since 1.0.0 
  843. */ 
  844. $content = sprintf( 
  845. '<p class="ms-alert-box %1$s">%2$s</p> ',  
  846. $class,  
  847. __( $content, 'membership2' ) 
  848. ); 
  849.  
  850. $content = do_shortcode( $content ); 
  851.  
  852. return apply_filters( 
  853. 'ms_controller_shortcode_ms_note',  
  854. $content,  
  855. $this 
  856. ); 
  857.  
  858. /** 
  859. * Display a green text note. 
  860. * @since 1.0.0 
  861. * @deprecated since 1.0.4.5 
  862. * @param mixed[] $atts Shortcode attributes. 
  863. */ 
  864. public function ms_green_note( $atts, $content = '' ) { 
  865. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_GREEN_NOTE ); 
  866.  
  867. $content = $this->ms_note( array( 'type' => 'info' ), $content ); 
  868.  
  869. return apply_filters( 
  870. 'ms_controller_shortcode_ms_green_note',  
  871. $content,  
  872. $this 
  873. ); 
  874.  
  875. /** 
  876. * Display a red text note. 
  877. * @since 1.0.0 
  878. * @deprecated since 1.0.4.5 
  879. * @param mixed[] $atts Shortcode attributes. 
  880. */ 
  881. public function ms_red_note( $atts, $content = '' ) { 
  882. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_RED_NOTE ); 
  883.  
  884. $content = $this->ms_note( array( 'type' => 'warning' ), $content ); 
  885.  
  886. return apply_filters( 
  887. 'ms_controller_shortcode_ms_red_note',  
  888. $content,  
  889. $this 
  890. ); 
  891.  
  892. /** 
  893. * Shortcode callback: Show message only to certain users. 
  894. * @since 1.0.0 
  895. * @param mixed[] $atts Shortcode attributes. 
  896. */ 
  897. public function show_to_user( $atts, $content = '' ) { 
  898. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_USER ); 
  899.  
  900. $data = apply_filters( 
  901. 'ms_controller_shortcode_show_to_user_atts',  
  902. shortcode_atts( 
  903. array( 
  904. 'type' => 'loggedin',  
  905. 'msg' => '',  
  906. ),  
  907. $atts 
  908. ); 
  909.  
  910. extract( $data ); 
  911. $access = false; 
  912.  
  913. $user_type = 'guest'; 
  914. if ( is_user_logged_in() ) { 
  915. $user_type = 'loggedin'; 
  916.  
  917. if ( MS_Model_Member::is_admin_user() ) { 
  918. $user_type = 'admin'; 
  919.  
  920. $class = 'ms-user-is-' . $user_type; 
  921.  
  922. switch ( $type ) { 
  923. case 'all': 
  924. $access = true; 
  925. break; 
  926.  
  927. case 'loggedin': 
  928. case 'login': 
  929. $access = in_array( $user_type, array( 'loggedin', 'admin' ) ); 
  930. break; 
  931.  
  932. case 'guest': 
  933. $access = ($user_type == 'guest' ); 
  934. break; 
  935.  
  936. case 'admin': 
  937. $access = ( $user_type == 'admin' ); 
  938. break; 
  939.  
  940. case 'non-admin': 
  941. $access = ( $user_type != 'admin' ); 
  942. break; 
  943.  
  944. if ( ! $access ) { 
  945. $content = $msg; 
  946. $class .= ' ms-user-not-' . $type; 
  947.  
  948. $content = sprintf( 
  949. '<div class="ms-user %1$s">%2$s</div>',  
  950. esc_attr( $class ),  
  951. do_shortcode( $content ) 
  952. ); 
  953.  
  954. return apply_filters( 
  955. 'ms_controller_shortcode_show_to_user',  
  956. $content,  
  957. $this 
  958. ); 
  959.  
  960. /** 
  961. * Shortcode callback: Show member infos. 
  962. * @since 1.0.0 
  963. * @param mixed[] $atts Shortcode attributes. 
  964. */ 
  965. public function ms_member_info( $atts, $content = '' ) { 
  966. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MEMBER_INFO ); 
  967.  
  968. $data = apply_filters( 
  969. 'ms_controller_shortcode_member_info_atts',  
  970. shortcode_atts( 
  971. array( 
  972. 'value' => 'fullname',  
  973. 'before' => '<span>',  
  974. 'after' => '</span>',  
  975. 'default' => '',  
  976. 'custom_field' => '', // used for: custom 
  977. 'list_before' => '', // used for: membership 
  978. 'list_after' => '', // used for: membership 
  979. 'list_separator' => ', ', // used for: membership 
  980. 'user' => 0, // user-id; 0 = current user 
  981. ),  
  982. $atts 
  983. ); 
  984.  
  985. $data['user'] = intval( $data['user'] ); 
  986. if ( $data['user'] < 1 ) { 
  987. $data['user'] = get_current_user_id(); 
  988. $member = MS_Factory::load( 'MS_Model_Member', $data['user'] ); 
  989. $content = ''; 
  990.  
  991. switch ( $data['value'] ) { 
  992. case 'email': 
  993. $content = $member->email; 
  994. break; 
  995.  
  996. case 'firstname': 
  997. case 'first name': 
  998. $content = $member->first_name; 
  999. break; 
  1000.  
  1001. case 'lastname': 
  1002. case 'last name': 
  1003. $content = $member->last_name; 
  1004. break; 
  1005.  
  1006. case 'fullname': 
  1007. case 'full name': 
  1008. $content = $member->first_name . ' ' . $member->last_name; 
  1009. break; 
  1010.  
  1011. case 'memberships': 
  1012. case 'membership': 
  1013. $ids = $member->get_membership_ids(); 
  1014. $content = array(); 
  1015. foreach ( $ids as $id ) { 
  1016. $membership = MS_Factory::load( 'MS_Model_Membership', $id ); 
  1017. if ( $membership->is_system() ) { continue; } 
  1018. $content[] = $membership->name; 
  1019. break; 
  1020.  
  1021. case 'custom': 
  1022. $content = $member->get_custom_data( $data['custom_field'] ); 
  1023. break; 
  1024.  
  1025. if ( is_array( $content ) ) { 
  1026. if ( $content ) { 
  1027. $content = 
  1028. $data['list_before'] . 
  1029. implode( $data['list_separator'], $content ) . 
  1030. $data['list_after']; 
  1031. } else { 
  1032. $content = ''; 
  1033. } else { 
  1034. $content = (string) $content; 
  1035.  
  1036. $content = trim( $content ); 
  1037. if ( $content ) { 
  1038. $content = $data['before'] . 
  1039. $content . 
  1040. $data['after']; 
  1041. } else { 
  1042. $content = $data['default']; 
  1043.  
  1044. return apply_filters( 
  1045. 'ms_controller_shortcode_member_info',  
  1046. $content,  
  1047. $this 
  1048. ); 
  1049.  
  1050.  
  1051. /** 
  1052. * Special Shortcode Callback: Replace shortcodes with empty value. 
  1053. * All Shortcodes use this callback function 
  1054. * when Content Protection is DISABLED! 
  1055. * @since 1.0.0 
  1056. * @param mixed[] $atts Shortcode attributes. 
  1057. * @param string $content 
  1058. * @return string 
  1059. */ 
  1060. public function ms_no_value( $atts, $content = '' ) { 
  1061. static $Done = false; 
  1062.  
  1063. if ( $Done ) { return ''; } 
  1064. $Done = true; 
  1065.  
  1066. if ( MS_Model_Member::is_admin_user() ) { 
  1067. $content = sprintf( 
  1068. '<p class="ms-alert-box ms-alert-error ms-unprotected">%s<br /><br /><em>(%s)</em></p>',  
  1069. __( 
  1070. 'Content Protection is disabled. Please enable the protection to see this shortcode.',  
  1071. 'membership2' 
  1072. ),  
  1073. __( 
  1074. 'This message is only displayed to Site Administrators',  
  1075. 'membership2' 
  1076. ); 
  1077. } else { 
  1078. $content = ''; 
  1079.  
  1080. return apply_filters( 
  1081. 'ms_controller_shortcode_ms_no_value',  
  1082. $content,  
  1083. $this 
  1084. ); 
  1085.  
  1086. /** 
  1087. * Special Shortcode Callback: Strip the shortcode tag without changing the 
  1088. * original content. 
  1089. * This is used for Admin users to strip all content-protection tags. 
  1090. * @since 1.0.0 
  1091. * @param mixed[] $atts Shortcode attributes. 
  1092. * @param string $content 
  1093. * @return string 
  1094. */ 
  1095. public function hide_shortcode( $atts, $content = '' ) { 
  1096. return do_shortcode( $content ); 
  1097.