MS_View_Membership_Add

The Membership 2 MS View Membership Add class.

Defined (1)

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

/app/view/membership/class-ms-view-membership-add.php  
  1. class MS_View_Membership_Add extends MS_View { 
  2.  
  3. /** 
  4. * Create view output. 
  5. * @since 1.0.0 
  6. * @return string 
  7. */ 
  8. public function to_html() { 
  9. $fields = $this->prepare_fields(); 
  10. $cols = count( $fields['type']['field_options'] ); 
  11. if ( $cols < 2 ) { $cols = 2; } 
  12. if ( $cols > 3 ) { $cols = 2; } 
  13.  
  14. ob_start(); 
  15. ?> 
  16. <div class="ms-wrap"> 
  17. <?php 
  18. MS_Helper_Html::settings_header( 
  19. array( 
  20. 'title' => __( 'Create New Membership', 'membership2' ),  
  21. 'desc' => __( 'First up, choose a name and a type for your membership site.', 'membership2' ),  
  22. ); 
  23. ?> 
  24. <div class="ms-settings ms-membership-add ms-cols-<?php echo esc_attr( $cols ); ?>"> 
  25. <form method="post" id="ms-choose-type-form"> 
  26. <div class="ms-settings-row cf"> 
  27. <h3><?php _e( 'Choose a membership type:', 'membership2' ); ?></h3> 
  28. <?php MS_Helper_Html::html_element( $fields['type'] ); ?> 
  29. </div> 
  30. <div class="ms-settings-row cf"> 
  31. <?php MS_Helper_Html::html_element( $fields['name'] ); ?> 
  32. </div> 
  33. <div class="ms-settings-row cf"> 
  34. <div class="ms-options-wrapper"> 
  35. <?php 
  36. foreach ( $fields['config_fields'] as $field ) { 
  37. echo '<span class="opt">'; 
  38. MS_Helper_Html::html_element( $field ); 
  39. echo '</span>'; 
  40. ?> 
  41. </div> 
  42. </div> 
  43. <div class="ms-control-fields-wrapper"> 
  44. <?php 
  45. foreach ( $fields['control_fields'] as $field ) { 
  46. MS_Helper_Html::html_element( $field ); 
  47. ?> 
  48. </div> 
  49. </form> 
  50. </div> 
  51. </div> 
  52. <?php 
  53. $html = ob_get_clean(); 
  54.  
  55. return $html; 
  56.  
  57. /** 
  58. * Prepare the fields displayed in the form. 
  59. * @since 1.0.0 
  60. * @return array 
  61. */ 
  62. public function prepare_fields() { 
  63. $membership = $this->data['membership']; 
  64.  
  65. $fields = array( 
  66. 'type' => array( 
  67. 'id' => 'type',  
  68. 'type' => MS_Helper_Html::INPUT_TYPE_RADIO,  
  69. 'value' => ( $membership->type ) ? $membership->type : MS_Model_Membership::TYPE_STANDARD,  
  70. 'class' => 'ms-choose-type',  
  71. 'field_options' => array( 
  72. MS_Model_Membership::TYPE_STANDARD => array( 
  73. 'text' => __( 'Standard Membership', 'membership2' ),  
  74. 'desc' => __( 'Make your content available to Members and hidden to Guests (logged-out users).', 'membership2' ),  
  75. ),  
  76. MS_Model_Membership::TYPE_DRIPPED => array( 
  77. 'text' => __( 'Dripped Content Membership.', 'membership2' ),  
  78. 'desc' => __( 'Set-up membership content to be released / made available in intervals.', 'membership2' ),  
  79. ),  
  80. MS_Model_Membership::TYPE_GUEST => array( 
  81. 'text' => __( 'Guest Membership', 'membership2' ),  
  82. 'desc' => __( 'Make your content available only to Guests (logged-out users).', 'membership2' ),  
  83. ),  
  84. MS_Model_Membership::TYPE_USER => array( 
  85. 'text' => __( 'Default Membership', 'membership2' ),  
  86. 'desc' => __( 'Content is available to all logged-in users that did not join any other Membership yet.', 'membership2' ),  
  87. ),  
  88. ),  
  89. ),  
  90.  
  91. 'name' => array( 
  92. 'id' => 'name',  
  93. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  94. 'title' => __( 'Name Your Membership:', 'membership2' ),  
  95. 'value' => $membership->name,  
  96. 'class' => 'ms-text-large',  
  97. 'placeholder' => __( 'Choose a name that will identify this membership...', 'membership2' ),  
  98. 'label_type' => 'h3',  
  99. 'wrapper_class' => 'opt',  
  100. 'after' => sprintf( 
  101. '<span class="locked-info">%1$s</span>',  
  102. __( 'Not available for this Membership', 'membership2' ) 
  103. ),  
  104. ),  
  105.  
  106. 'config_fields' => array( 
  107. 'public' => array( 
  108. 'id' => 'public',  
  109. 'type' => MS_Helper_Html::INPUT_TYPE_CHECKBOX,  
  110. 'title' => __( 'Allow users to register for this membership.', 'membership2' ),  
  111. 'desc' => __( 'If selected, registration experience will be added to your site. Do not tick if you want to make this a private membership.', 'membership2' ),  
  112. 'after' => sprintf( 
  113. '<span class="locked-info">%1$s</span>',  
  114. __( 'Not available for this Membership', 'membership2' ) 
  115. ),  
  116. 'value' => ! $membership->private,  
  117. ),  
  118. 'public_flag' => array( 
  119. // See MS_Controller_Membership->membership_admin_page_process() 
  120. 'id' => 'set_public_flag',  
  121. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  122. 'value' => 1,  
  123. ),  
  124. 'paid' => array( 
  125. 'id' => 'paid',  
  126. 'type' => MS_Helper_Html::INPUT_TYPE_CHECKBOX,  
  127. 'title' => __( 'This is a paid membership.', 'membership2' ),  
  128. 'desc' => __( 'Choose this if you want to receive payments from members via Payment Gateways.', 'membership2' ),  
  129. 'after' => sprintf( 
  130. '<span class="locked-info">%1$s</span>',  
  131. __( 'Not available for this Membership', 'membership2' ) 
  132. ),  
  133. 'value' => ! $membership->is_free(),  
  134. ),  
  135. 'paid_flag' => array( 
  136. // See MS_Controller_Membership->membership_admin_page_process() 
  137. 'id' => 'set_paid_flag',  
  138. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  139. 'value' => 1,  
  140. ),  
  141. ),  
  142.  
  143. 'control_fields' => array( 
  144. 'membership_id' => array( 
  145. 'id' => 'membership_id',  
  146. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  147. 'value' => $membership->id,  
  148. ),  
  149. 'step' => array( 
  150. 'id' => 'step',  
  151. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  152. 'value' => $this->data['step'],  
  153. ),  
  154. 'action' => array( 
  155. 'id' => 'action',  
  156. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  157. 'value' => $this->data['action'],  
  158. ),  
  159. '_wpnonce' => array( 
  160. 'id' => '_wpnonce',  
  161. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  162. 'value' => wp_create_nonce( $this->data['action'] ),  
  163. ),  
  164. 'cancel' => array( 
  165. 'id' => 'cancel',  
  166. 'type' => MS_Helper_Html::INPUT_TYPE_BUTTON,  
  167. 'value' => __( 'Cancel', 'membership2' ),  
  168. 'data_ms' => array( 
  169. 'action' => MS_Controller_Settings::AJAX_ACTION_UPDATE_SETTING,  
  170. 'field' => 'initial_setup',  
  171. 'value' => '0',  
  172. ),  
  173. 'save' => array( 
  174. 'id' => 'save',  
  175. 'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT,  
  176. 'value' => __( 'Save and continue', 'membership2' ) . ' »',  
  177. ),  
  178. ),  
  179. ); 
  180.  
  181. // Only one Guest Membership can be added 
  182. if ( MS_Model_Membership::get_guest()->is_valid() ) { 
  183. unset( $fields['type']['field_options'][MS_Model_Membership::TYPE_GUEST] ); 
  184.  
  185. // Only one User Membership can be added 
  186. if ( MS_Model_Membership::get_user()->is_valid() ) { 
  187. unset( $fields['type']['field_options'][MS_Model_Membership::TYPE_USER] ); 
  188.  
  189. // Wizard can only be cancelled when at least one membership exists in DB. 
  190. $count = MS_Model_Membership::get_membership_count(); 
  191. if ( ! $count ) { 
  192. unset( $fields['control_fields']['cancel'] ); 
  193.  
  194. return $fields;