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