MS_Helper_Membership

Helper for the Membership class.

Defined (1)

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

/app/helper/class-ms-helper-membership.php  
  1. class MS_Helper_Membership extends MS_Helper { 
  2.  
  3. const MEMBERSHIP_ACTION_SIGNUP = 'membership_signup'; 
  4. const MEMBERSHIP_ACTION_MOVE = 'membership_move'; 
  5. const MEMBERSHIP_ACTION_CANCEL = 'membership_cancel'; 
  6. const MEMBERSHIP_ACTION_RENEW = 'membership_renew'; 
  7. const MEMBERSHIP_ACTION_PAY = 'membership_pay'; 
  8.  
  9. const MEMBERSHIP_MSG_ADDED = 1; 
  10. const MEMBERSHIP_MSG_DELETED = 2; 
  11. const MEMBERSHIP_MSG_UPDATED = 3; 
  12. const MEMBERSHIP_MSG_ACTIVATION_TOGGLED = 4; 
  13. const MEMBERSHIP_MSG_STATUS_TOGGLED = 5; 
  14. const MEMBERSHIP_MSG_BULK_UPDATED = 6; 
  15. const MEMBERSHIP_MSG_NOT_ADDED = -1; 
  16. const MEMBERSHIP_MSG_NOT_DELETED = -2; 
  17. const MEMBERSHIP_MSG_NOT_UPDATED = -3; 
  18. const MEMBERSHIP_MSG_ACTIVATION_NOT_TOGGLED = -4; 
  19. const MEMBERSHIP_MSG_STATUS_NOT_TOGGLED = -5; 
  20. const MEMBERSHIP_MSG_BULK_NOT_UPDATED = -6; 
  21. const MEMBERSHIP_MSG_PARTIALLY_UPDATED = -8; 
  22.  
  23. public static function get_admin_messages( $msg = 0 ) { 
  24. $messages = apply_filters( 
  25. 'ms_helper_membership_get_admin_messages',  
  26. array( 
  27. self::MEMBERSHIP_MSG_ADDED => __( 'You have successfully set up your <b>%s</b> Membership.', 'membership2' ),  
  28. self::MEMBERSHIP_MSG_DELETED => __( 'Membership deleted.', 'membership2' ),  
  29. self::MEMBERSHIP_MSG_UPDATED => __( 'Membership <b>%s</b> updated.', 'membership2' ),  
  30. self::MEMBERSHIP_MSG_ACTIVATION_TOGGLED => __( 'Membership activation toggled.', 'membership2' ),  
  31. self::MEMBERSHIP_MSG_STATUS_TOGGLED => __( 'Membership status toggled.', 'membership2' ),  
  32. self::MEMBERSHIP_MSG_BULK_UPDATED => __( 'Memberships bulk updated.', 'membership2' ),  
  33. self::MEMBERSHIP_MSG_NOT_ADDED => __( 'Membership not added.', 'membership2' ),  
  34. self::MEMBERSHIP_MSG_NOT_DELETED => __( 'Membership not deleted.', 'membership2' ),  
  35. self::MEMBERSHIP_MSG_NOT_UPDATED => __( 'Membership not updated.', 'membership2' ),  
  36. self::MEMBERSHIP_MSG_ACTIVATION_NOT_TOGGLED => __( 'Membership activation not toggled.', 'membership2' ),  
  37. self::MEMBERSHIP_MSG_STATUS_NOT_TOGGLED => __( 'Membership status not toggled.', 'membership2' ),  
  38. self::MEMBERSHIP_MSG_BULK_NOT_UPDATED => __( 'Memberships bulk not updated.', 'membership2' ),  
  39. self::MEMBERSHIP_MSG_PARTIALLY_UPDATED => __( 'Memberships partially updated. Some fields could not be changed after members have signed up.', 'membership2' ),  
  40. ); 
  41.  
  42. if ( array_key_exists( $msg, $messages ) ) { 
  43. return $messages[ $msg ]; 
  44. } else { 
  45. return null; 
  46.  
  47. public static function print_admin_message() { 
  48. $msg = self::get_msg_id(); 
  49.  
  50. $class = ( $msg > 0 ) ? 'updated' : 'error'; 
  51.  
  52. if ( $msg = self::get_admin_messages( $msg ) ) { 
  53. lib3()->ui->admin_message( $msg, $class ); 
  54.  
  55. public static function get_admin_message( $args = null, $membership = null ) { 
  56. $msg = ''; 
  57. $msg_id = self::get_msg_id(); 
  58.  
  59. if ( $msg = self::get_admin_messages( $msg_id ) ) { 
  60. if ( ! empty( $args ) ) { 
  61. $msg = vsprintf( $msg, $args ); 
  62.  
  63. // When the first membership was created show a popup to the user 
  64. $is_first = true; 
  65. if ( $is_first 
  66. && self::MEMBERSHIP_MSG_ADDED == $msg_id 
  67. && ! empty( $membership ) 
  68. ) { 
  69. $url = MS_Controller_Plugin::get_admin_settings_url(); 
  70.  
  71. self::show_setup_note( $membership ); 
  72.  
  73. return apply_filters( 
  74. 'ms_helper_membership_get_admin_message',  
  75. $msg 
  76. ); 
  77.  
  78. public static function get_admin_title() { 
  79. $title = __( 'Memberships', 'membership2' ); 
  80.  
  81. $msg = self::get_msg_id(); 
  82. if ( self::MEMBERSHIP_MSG_ADDED == $msg ) { 
  83. $title = __( 'Congratulations!', 'membership2' ); 
  84. return apply_filters( 'ms_helper_membership_get_admin_title', $title ); 
  85.  
  86. public static function get_msg_id() { 
  87. $msg = ! empty( $_GET['msg'] ) ? (int) $_GET['msg'] : 0; 
  88. return apply_filters( 'ms_helper_membership_get_msg_id', $msg ); 
  89.  
  90. /** 
  91. * Displays a PopUp to the user that shows a sumary of the setup wizard 
  92. * including possible next steps for configuration. 
  93. * @since 1.0.0 
  94. * @param MS_Model_Membership $membership The membership that was created. 
  95. */ 
  96. public static function show_setup_note( $membership ) { 
  97. $popup = array(); 
  98.  
  99. $popup['title'] = sprintf( 
  100. '<i class="dashicons dashicons-yes"></i> %1$s<div class="subtitle">%2$s</div>',  
  101. __( 'Congratulations!', 'membership2' ),  
  102. sprintf( 
  103. __( 'You have successfully set up your <b>%1$s</b> Membership.', 'membership2' ),  
  104. $membership->name 
  105. ); 
  106.  
  107. $setup = MS_Factory::create( 'MS_View_Settings_Page_Setup' ); 
  108.  
  109. $popup['modal'] = true; 
  110. $popup['close'] = false; 
  111. $popup['sticky'] = false; 
  112. $popup['class'] = 'ms-setup-done'; 
  113. $popup['body'] = $setup->to_html(); 
  114. $popup['height'] = $setup->dialog_height(); 
  115.  
  116. $popup['body'] .= sprintf( 
  117. '<div class="buttons">' . 
  118. '<a href="%s" class="button">%s</a> ' . 
  119. '<button type="button" class="button-primary close">%s</button>' . 
  120. '</div>',  
  121. MS_Controller_Plugin::get_admin_url( 'protection' ),  
  122. __( 'Set-up Access Levels', 'membership2' ),  
  123. __( 'Finish', 'membership2' ) 
  124. ); 
  125.  
  126. lib3()->html->popup( $popup ); 
  127.  
  128. $settings = MS_Plugin::instance()->settings; 
  129. $settings->is_first_membership = false; 
  130. if ( ! $membership->is_free ) { 
  131. $settings->is_first_paid_membership = false; 
  132. $settings->save();