/app/helper/class-ms-helper-membership.php

  1. <?php 
  2. /** 
  3. * @copyright Incsub (http://incsub.com/) 
  4. * 
  5. * @license http://opensource.org/licenses/GPL-2.0 GNU General Public License, version 2 (GPL-2.0) 
  6. * 
  7. * This program is free software; you can redistribute it and/or modify 
  8. * it under the terms of the GNU General Public License, version 2, as 
  9. * published by the Free Software Foundation. 
  10. * 
  11. * This program is distributed in the hope that it will be useful,  
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of 
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
  14. * GNU General Public License for more details. 
  15. * 
  16. * You should have received a copy of the GNU General Public License 
  17. * along with this program; if not, write to the Free Software 
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,  
  19. * MA 02110-1301 USA 
  20. * 
  21. */ 
  22.  
  23. class MS_Helper_Membership extends MS_Helper { 
  24.  
  25. const MEMBERSHIP_ACTION_SIGNUP = 'membership_signup'; 
  26. const MEMBERSHIP_ACTION_MOVE = 'membership_move'; 
  27. const MEMBERSHIP_ACTION_CANCEL = 'membership_cancel'; 
  28. const MEMBERSHIP_ACTION_RENEW = 'membership_renew'; 
  29. const MEMBERSHIP_ACTION_PAY = 'membership_pay'; 
  30.  
  31. const MEMBERSHIP_MSG_ADDED = 1; 
  32. const MEMBERSHIP_MSG_DELETED = 2; 
  33. const MEMBERSHIP_MSG_UPDATED = 3; 
  34. const MEMBERSHIP_MSG_ACTIVATION_TOGGLED = 4; 
  35. const MEMBERSHIP_MSG_STATUS_TOGGLED = 5; 
  36. const MEMBERSHIP_MSG_BULK_UPDATED = 6; 
  37. const MEMBERSHIP_MSG_NOT_ADDED = -1; 
  38. const MEMBERSHIP_MSG_NOT_DELETED = -2; 
  39. const MEMBERSHIP_MSG_NOT_UPDATED = -3; 
  40. const MEMBERSHIP_MSG_ACTIVATION_NOT_TOGGLED = -4; 
  41. const MEMBERSHIP_MSG_STATUS_NOT_TOGGLED = -5; 
  42. const MEMBERSHIP_MSG_BULK_NOT_UPDATED = -6; 
  43. const MEMBERSHIP_MSG_PARTIALLY_UPDATED = -8; 
  44.  
  45. public static function get_admin_messages( $msg = 0 ) { 
  46. $messages = apply_filters( 
  47. 'ms_helper_membership_get_admin_messages',  
  48. array( 
  49. self::MEMBERSHIP_MSG_ADDED => __( 'You have successfully set up your <b>%s</b> Membership.', MS_TEXT_DOMAIN ),  
  50. self::MEMBERSHIP_MSG_DELETED => __( 'Membership deleted.', MS_TEXT_DOMAIN ),  
  51. self::MEMBERSHIP_MSG_UPDATED => __( 'Membership <b>%s</b> updated.', MS_TEXT_DOMAIN ),  
  52. self::MEMBERSHIP_MSG_ACTIVATION_TOGGLED => __( 'Membership activation toggled.', MS_TEXT_DOMAIN ),  
  53. self::MEMBERSHIP_MSG_STATUS_TOGGLED => __( 'Membership status toggled.', MS_TEXT_DOMAIN ),  
  54. self::MEMBERSHIP_MSG_BULK_UPDATED => __( 'Memberships bulk updated.', MS_TEXT_DOMAIN ),  
  55. self::MEMBERSHIP_MSG_NOT_ADDED => __( 'Membership not added.', MS_TEXT_DOMAIN ),  
  56. self::MEMBERSHIP_MSG_NOT_DELETED => __( 'Membership not deleted.', MS_TEXT_DOMAIN ),  
  57. self::MEMBERSHIP_MSG_NOT_UPDATED => __( 'Membership not updated.', MS_TEXT_DOMAIN ),  
  58. self::MEMBERSHIP_MSG_ACTIVATION_NOT_TOGGLED => __( 'Membership activation not toggled.', MS_TEXT_DOMAIN ),  
  59. self::MEMBERSHIP_MSG_STATUS_NOT_TOGGLED => __( 'Membership status not toggled.', MS_TEXT_DOMAIN ),  
  60. self::MEMBERSHIP_MSG_BULK_NOT_UPDATED => __( 'Memberships bulk not updated.', MS_TEXT_DOMAIN ),  
  61. self::MEMBERSHIP_MSG_PARTIALLY_UPDATED => __( 'Memberships partially updated. Some fields could not be changed after members have signed up.', MS_TEXT_DOMAIN ),  
  62. ); 
  63.  
  64. if ( array_key_exists( $msg, $messages ) ) { 
  65. return $messages[ $msg ]; 
  66. } else { 
  67. return null; 
  68.  
  69. public static function print_admin_message() { 
  70. $msg = self::get_msg_id(); 
  71.  
  72. $class = ( $msg > 0 ) ? 'updated' : 'error'; 
  73.  
  74. if ( $msg = self::get_admin_messages( $msg ) ) { 
  75. lib2()->ui->admin_message( $msg, $class ); 
  76.  
  77. public static function get_admin_message( $args = null, $membership = null ) { 
  78. $msg = ''; 
  79. $msg_id = self::get_msg_id(); 
  80.  
  81. if ( $msg = self::get_admin_messages( $msg_id ) ) { 
  82. if ( ! empty( $args ) ) { 
  83. $msg = vsprintf( $msg, $args ); 
  84.  
  85. // When the first membership was created show a popup to the user 
  86. $is_first = true; 
  87. if ( $is_first 
  88. && self::MEMBERSHIP_MSG_ADDED == $msg_id 
  89. && ! empty( $membership ) 
  90. ) { 
  91. $url = MS_Controller_Plugin::get_admin_settings_url(); 
  92.  
  93. self::show_setup_note( $membership ); 
  94.  
  95. return apply_filters( 
  96. 'ms_helper_membership_get_admin_message',  
  97. $msg 
  98. ); 
  99.  
  100. public static function get_admin_title() { 
  101. $title = __( 'Memberships', MS_TEXT_DOMAIN ); 
  102.  
  103. $msg = self::get_msg_id(); 
  104. if ( self::MEMBERSHIP_MSG_ADDED == $msg ) { 
  105. $title = __( 'Congratulations!', MS_TEXT_DOMAIN ); 
  106. return apply_filters( 'ms_helper_membership_get_admin_title', $title ); 
  107.  
  108. public static function get_msg_id() { 
  109. $msg = ! empty( $_GET['msg'] ) ? (int) $_GET['msg'] : 0; 
  110. return apply_filters( 'ms_helper_membership_get_msg_id', $msg ); 
  111.  
  112. /** 
  113. * Displays a PopUp to the user that shows a sumary of the setup wizard 
  114. * including possible next steps for configuration. 
  115. * 
  116. * @since 1.1.0 
  117. * @param MS_Model_Membership $membership The membership that was created. 
  118. */ 
  119. public static function show_setup_note( $membership ) { 
  120. $popup = array(); 
  121.  
  122. $popup['title'] = sprintf( 
  123. '<i class="dashicons dashicons-yes"></i> %1$s<div class="subtitle">%2$s</div>',  
  124. __( 'Congratulations!', MS_TEXT_DOMAIN ),  
  125. sprintf( 
  126. __( 'You have successfully set up your <b>%1$s</b> Membership.', MS_TEXT_DOMAIN ),  
  127. $membership->name 
  128. ); 
  129.  
  130. $setup = MS_Factory::create( 'MS_View_Settings_Page_Setup' ); 
  131.  
  132. $popup['modal'] = true; 
  133. $popup['close'] = false; 
  134. $popup['sticky'] = false; 
  135. $popup['class'] = 'ms-setup-done'; 
  136. $popup['body'] = $setup->to_html(); 
  137. $popup['height'] = $setup->dialog_height(); 
  138.  
  139. $popup['body'] .= sprintf( 
  140. '<div class="buttons">' . 
  141. '<a href="%s" class="button">%s</a> ' . 
  142. '<button type="button" class="button-primary close">%s</button>' . 
  143. '</div>',  
  144. MS_Controller_Plugin::get_admin_url( 'protection' ),  
  145. __( 'Set-up Access Levels', MS_TEXT_DOMAIN ),  
  146. __( 'Finish', MS_TEXT_DOMAIN ) 
  147. ); 
  148.  
  149. lib2()->html->popup( $popup ); 
  150.  
  151. $settings = MS_Plugin::instance()->settings; 
  152. $settings->is_first_membership = false; 
  153. if ( ! $membership->is_free ) { 
  154. $settings->is_first_paid_membership = false; 
  155. $settings->save(); 
.