MS_View_Membership_Tab_Details

Tab: Edit Membership Details.

Defined (1)

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

/app/view/membership/tab/class-ms-view-membership-tab-details.php  
  1. class MS_View_Membership_Tab_Details extends MS_View { 
  2.  
  3. /** 
  4. * Returns the contens of the dialog 
  5. * @since 1.0.0 
  6. * @return object 
  7. */ 
  8. public function to_html() { 
  9. $field = $this->get_fields(); 
  10. $membership = $this->data['membership']; 
  11.  
  12. ob_start(); 
  13. ?> 
  14. <div> 
  15. <form class="ms-form wpmui-ajax-update ms-edit-membership" data-wpmui-ajax="<?php echo esc_attr( 'save' ); ?>"> 
  16. <div class="ms-form wpmui-form wpmui-grid-8"> 
  17. <div class="col-5"> 
  18. <?php 
  19. MS_Helper_Html::html_element( $field['name'] ); 
  20. if ( ! $membership->is_system() ) { 
  21. MS_Helper_Html::html_element( $field['description'] ); 
  22. ?> 
  23. </div> 
  24. <div class="col-3"> 
  25. <?php 
  26. MS_Helper_Html::html_element( $field['active'] ); 
  27. if ( ! $membership->is_system() ) { 
  28. MS_Helper_Html::html_element( $field['public'] ); 
  29. MS_Helper_Html::html_element( $field['paid'] ); 
  30. ?> 
  31. </div> 
  32. </div> 
  33. <div class="ms-form wpmui-form wpmui-grid-8"> 
  34. <div class="col-8"> 
  35. <?php 
  36. if ( ! $membership->is_system() ) { 
  37. MS_Helper_Html::html_element( $field['priority'] ); 
  38. ?> 
  39. </div> 
  40. </div> 
  41. </form> 
  42. </div> 
  43. <?php 
  44. $html = ob_get_clean(); 
  45.  
  46. return apply_filters( 'ms_view_membership_edit_to_html', $html ); 
  47.  
  48. /** 
  49. * Prepares fields for the edit form. 
  50. * @since 1.0.1.0 
  51. * @return array 
  52. */ 
  53. protected function get_fields() { 
  54. $membership = $this->data['membership']; 
  55. $action = MS_Controller_Membership::AJAX_ACTION_UPDATE_MEMBERSHIP; 
  56. $nonce = wp_create_nonce( $action ); 
  57.  
  58. $fields = array(); 
  59.  
  60. // Prepare the form fields. 
  61. $fields['name'] = array( 
  62. 'id' => 'name',  
  63. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  64. 'title' => apply_filters( 
  65. 'ms_translation_flag',  
  66. __( 'Name:', 'membership2' ),  
  67. 'membership-name' 
  68. ),  
  69. 'value' => $membership->name,  
  70. 'ajax_data' => array( 1 ),  
  71. ); 
  72.  
  73. $fields['description'] = array( 
  74. 'id' => 'description',  
  75. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT_AREA,  
  76. 'title' => apply_filters( 
  77. 'ms_translation_flag',  
  78. __( 'Description:', 'membership2' ),  
  79. 'membership-name' 
  80. ),  
  81. 'value' => $membership->description,  
  82. 'ajax_data' => array( 1 ),  
  83. ); 
  84.  
  85. $fields['active'] = array( 
  86. 'id' => 'active',  
  87. 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER,  
  88. 'title' => __( 'This membership is active', 'membership2' ),  
  89. 'before' => __( 'No', 'membership2' ),  
  90. 'after' => __( 'Yes', 'membership2' ),  
  91. 'class' => 'ms-active',  
  92. 'value' => $membership->active,  
  93. 'ajax_data' => array( 1 ),  
  94. ); 
  95.  
  96. $fields['public'] = array( 
  97. 'id' => 'public',  
  98. 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER,  
  99. 'title' => __( 'This membership is public', 'membership2' ),  
  100. 'desc' => __( 'Users can see it listed on your site and can register for it', 'membership2' ),  
  101. 'before' => __( 'No', 'membership2' ),  
  102. 'after' => __( 'Yes', 'membership2' ),  
  103. 'class' => 'ms-public',  
  104. 'value' => $membership->public,  
  105. 'ajax_data' => array( 1 ),  
  106. ); 
  107.  
  108. $fields['paid'] = array( 
  109. 'id' => 'is_paid',  
  110. 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER,  
  111. 'title' => __( 'This is a paid membership', 'membership2' ),  
  112. 'before' => __( 'No', 'membership2' ),  
  113. 'after' => __( 'Yes', 'membership2' ),  
  114. 'class' => 'ms-paid',  
  115. 'value' => $membership->is_paid,  
  116. 'ajax_data' => array( 1 ),  
  117. ); 
  118.  
  119. $priority_list = array(); 
  120. $args = array( 'include_guest' => 0 ); 
  121. $count = MS_Model_Membership::get_membership_count( $args ); 
  122. for ( $i = 1; $i <= $count; $i += 1 ) { 
  123. $priority_list[$i] = $i; 
  124. $priority_list[$membership->priority] = $membership->priority; 
  125.  
  126. $fields['priority'] = array( 
  127. 'id' => 'priority',  
  128. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  129. 'title' => __( 'Membership order', 'membership2' ),  
  130. 'desc' => __( 'This defines the display order on the Membership Page.', 'membership2' ),  
  131. 'class' => 'ms-priority',  
  132. 'before' => __( 'Order', 'membership2' ),  
  133. 'value' => $membership->priority,  
  134. 'field_options' => $priority_list,  
  135. 'ajax_data' => array( 1 ),  
  136. ); 
  137.  
  138. if ( MS_Model_Addon::is_enabled( MS_Model_Addon::ADDON_MULTI_MEMBERSHIPS ) ) { 
  139. $fields['priority']['desc'] .= '<br>' . 
  140. __( 'It also controlls which Protection Message is used in case a member has multiple memberships (the lowest value wins)', 'membership2' ); 
  141.  
  142. foreach ( $fields as $key => $field ) { 
  143. if ( ! empty( $field['ajax_data'] ) ) { 
  144. if ( ! empty( $field['ajax_data']['action'] ) ) { 
  145. continue; 
  146.  
  147. if ( ! isset( $fields[ $key ]['ajax_data']['field'] ) ) { 
  148. $fields[ $key ]['ajax_data']['field'] = $fields[ $key ]['id']; 
  149. $fields[ $key ]['ajax_data']['_wpnonce'] = $nonce; 
  150. $fields[ $key ]['ajax_data']['action'] = $action; 
  151. $fields[ $key ]['ajax_data']['membership_id'] = $membership->id; 
  152.  
  153. return $fields; 
  154.  
  155. };