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

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