MS_View_Membership_Tab_Upgrade

Tab: Edit Upgrade Paths.

Defined (1)

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

/app/view/membership/tab/class-ms-view-membership-tab-upgrade.php  
  1. class MS_View_Membership_Tab_Upgrade 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. $fields = $this->get_fields(); 
  10. $membership = $this->data['membership']; 
  11.  
  12. ob_start(); 
  13. ?> 
  14. <div> 
  15. <p> 
  16. <?php 
  17. printf( 
  18. __( 'Here you can define which members are allowed to subscribe to %s. By default anyone can subscribe.', 'membership2' ),  
  19. $membership->get_name_tag() 
  20. ); 
  21. ?> 
  22. </p> 
  23. <?php 
  24. foreach ( $fields as $field ) { 
  25. MS_Helper_Html::html_element( $field ); 
  26. ?> 
  27. </div> 
  28. <?php 
  29. $html = ob_get_clean(); 
  30.  
  31. return apply_filters( 'ms_view_membership_upgrades_to_html', $html ); 
  32.  
  33. /** 
  34. * Prepares fields for the edit form. 
  35. * @since 1.0.1.0 
  36. * @return array 
  37. */ 
  38. protected function get_fields() { 
  39. $args = array( 'include_guest' => false ); 
  40. $memberships = MS_Model_Membership::get_memberships( $args ); 
  41. $membership = $this->data['membership']; 
  42. $action = MS_Controller_Membership::AJAX_ACTION_UPDATE_MEMBERSHIP; 
  43. $nonce = wp_create_nonce( $action ); 
  44.  
  45. $fields = array(); 
  46.  
  47. /** 
  48. * The value of "allow_val" is negated, because the radio-slider is 
  49. * reversed. So allow_val == false means that upgrading is allowed. 
  50. * This is just a UI tweak, the function ->update_allowed() returns true 
  51. * when upgrading is allowed. 
  52. */ 
  53. $list = array(); 
  54. $list['guest'] = array( 
  55. 'allow' => __( 'Users without Membership can subscribe', 'membership2' ),  
  56. 'allow_val' => ! $membership->update_allowed( 'guest' ),  
  57. ); 
  58. foreach ( $memberships as $item ) { 
  59. if ( $item->id == $membership->id ) { continue; } 
  60.  
  61. $list[$item->id] = array( 
  62. 'allow' => sprintf( 
  63. __( 'Members of %s can subscribe', 'membership2' ),  
  64. $item->get_name_tag() 
  65. ),  
  66. 'allow_val' => ! $membership->update_allowed( $item->id ),  
  67. ); 
  68.  
  69. if ( MS_Model_Addon::is_enabled( MS_Model_Addon::ADDON_MULTI_MEMBERSHIPS ) ) { 
  70. $list[$item->id]['replace'] = sprintf( 
  71. __( 'Cancel %s on subscription', 'membership2' ),  
  72. $item->get_name_tag() 
  73. ); 
  74. $list[$item->id]['replace_val'] = $membership->update_replaces( $item->id ); 
  75.  
  76. foreach ( $list as $id => $data ) { 
  77. $fields[] = array( 
  78. 'id' => 'deny_update[' . $id . ']',  
  79. 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER,  
  80. 'title' => $data['allow'],  
  81. 'value' => $data['allow_val'],  
  82. 'before' => __( 'Allow', 'membership2' ),  
  83. 'after' => __( 'Deny', 'membership2' ),  
  84. 'class' => 'reverse',  
  85. 'wrapper_class' => 'ms-block inline-label ms-allow',  
  86. 'ajax_data' => array( 1 ),  
  87. ); 
  88.  
  89. if ( ! empty( $data['replace'] ) ) { 
  90. if ( MS_Addon_Prorate::is_active() ) { 
  91. $after_label = __( 'Cancel and Pro-Rate', 'membership2' ); 
  92. } else { 
  93. $after_label = __( 'Cancel', 'membership2' ); 
  94.  
  95. $fields[] = array( 
  96. 'id' => 'replace_update[' . $id . ']',  
  97. 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER,  
  98. 'title' => $data['replace'],  
  99. 'value' => $data['replace_val'],  
  100. 'before' => __( 'Keep', 'membership2' ),  
  101. 'after' => $after_label,  
  102. 'class' => 'reverse',  
  103. 'wrapper_class' => 'ms-block inline-label ms-update-replace',  
  104. 'ajax_data' => array( 1 ),  
  105. ); 
  106. $fields[] = array( 
  107. 'type' => MS_Helper_Html::TYPE_HTML_SEPARATOR,  
  108. ); 
  109.  
  110. foreach ( $fields as $key => $field ) { 
  111. if ( ! empty( $field['ajax_data'] ) ) { 
  112. if ( ! empty( $field['ajax_data']['action'] ) ) { 
  113. continue; 
  114.  
  115. if ( ! isset( $fields[ $key ]['ajax_data']['field'] ) ) { 
  116. $fields[ $key ]['ajax_data']['field'] = $fields[ $key ]['id']; 
  117. $fields[ $key ]['ajax_data']['_wpnonce'] = $nonce; 
  118. $fields[ $key ]['ajax_data']['action'] = $action; 
  119. $fields[ $key ]['ajax_data']['membership_id'] = $membership->id; 
  120.  
  121. return $fields; 
  122.  
  123. };