/app/view/settings/page/class-ms-view-settings-page-messages.php

  1. <?php 
  2.  
  3. class MS_View_Settings_Page_Messages extends MS_View_Settings_Edit { 
  4.  
  5. /** 
  6. * Return the HTML form. 
  7. * 
  8. * @since 1.0.0 
  9. * @return string 
  10. */ 
  11. public function to_html() { 
  12. $fields = $this->get_fields(); 
  13.  
  14. // TODO: Fix that condition again. 
  15. $has_more = true; 
  16. $title = __( 'Protection Messages', 'membership2' ); 
  17.  
  18. if ( isset( $this->data['membership'] ) ) { 
  19. $membership = $this->data['membership']; 
  20. } else { 
  21. $membership = false; 
  22.  
  23. if ( $membership instanceof MS_Model_Membership ) { 
  24. $settings_url = MS_Controller_Plugin::get_admin_url( 
  25. 'settings',  
  26. array( 'tab' => MS_Controller_Settings::TAB_MESSAGES ) 
  27. ); 
  28. $desc = sprintf( 
  29. __( 'Here you can override %sdefault settings%s for this membership.', 'membership2' ),  
  30. '<a href="' . $settings_url . '">',  
  31. '</a>' 
  32. ); 
  33. } else { 
  34. $desc = ''; 
  35.  
  36. ob_start(); 
  37. MS_Helper_Html::settings_tab_header( 
  38. array( 'title' => $title, 'desc' => $desc ) 
  39. ); 
  40. ?> 
  41. <form class="ms-form" action="" method="post"> 
  42. <?php 
  43. $subtitle = apply_filters( 
  44. 'ms_translation_flag',  
  45. __( 'Content protection message', 'membership2' ),  
  46. 'message-protected' 
  47. ); 
  48. MS_Helper_Html::settings_box( 
  49. $fields['content'],  
  50. $subtitle,  
  51. '',  
  52. 'open' 
  53. ); 
  54.  
  55. $subtitle = apply_filters( 
  56. 'ms_translation_flag',  
  57. __( 'Shortcode protection message', 'membership2' ),  
  58. 'message-shortcode' 
  59. ); 
  60. MS_Helper_Html::settings_box( 
  61. $fields['shortcode'],  
  62. $subtitle,  
  63. '',  
  64. 'open' 
  65. ); 
  66.  
  67. if ( $has_more ) { 
  68. $subtitle = apply_filters( 
  69. 'ms_translation_flag',  
  70. __( 'More tag protection message', 'membership2' ),  
  71. 'message-more_tag' 
  72. ); 
  73. MS_Helper_Html::settings_box( 
  74. $fields['more_tag'],  
  75. $subtitle,  
  76. '',  
  77. 'open' 
  78. ); 
  79. ?> 
  80. </form> 
  81. <?php 
  82. $html = ob_get_clean(); 
  83. return $html; 
  84.  
  85. /** 
  86. * Prepare the fields that are displayed in the form. 
  87. * 
  88. * @since 1.0.1.0 
  89. * @return array 
  90. */ 
  91. protected function get_fields() { 
  92. $settings = $this->data['settings']; 
  93.  
  94. if ( isset( $this->data['membership'] ) ) { 
  95. $membership = $this->data['membership']; 
  96. } else { 
  97. $membership = false; 
  98.  
  99. $action = MS_Controller_Settings::AJAX_ACTION_UPDATE_PROTECTION_MSG; 
  100. $nonce = wp_create_nonce( $action ); 
  101. $groups = array(); 
  102.  
  103. $message_content = $settings->get_protection_message( 
  104. MS_Model_Settings::PROTECTION_MSG_CONTENT,  
  105. $membership,  
  106. $override_content 
  107. ); 
  108.  
  109. $groups['content'] = array( 
  110. 'description' => array( 
  111. 'type' => MS_Helper_Html::TYPE_HTML_TEXT,  
  112. 'value' => __( 'Message displayed when the whole page is protected via shortcode <code>[ms-protection-message]</code>.', 'membership2' ),  
  113. 'wrapper_class' => 'ms-block ms-tcenter',  
  114. ),  
  115. 'override' => array( 
  116. 'id' => 'override_content',  
  117. 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER,  
  118. 'value' => $override_content,  
  119. 'before' => __( 'Use default message', 'membership2' ),  
  120. 'after' => __( 'Define custom message', 'membership2' ),  
  121. 'wrapper_class' => 'ms-block ms-tcenter ms-spaced',  
  122. 'class' => 'override-slider',  
  123. 'ajax_data' => array( 1 ),  
  124. ),  
  125. 'editor' => array( 
  126. 'id' => 'content',  
  127. 'type' => MS_Helper_Html::INPUT_TYPE_WP_EDITOR,  
  128. 'value' => $message_content,  
  129. 'field_options' => array( 'editor_class' => 'ms-field-wp-editor' ),  
  130. ),  
  131. 'save' => array( 
  132. 'id' => 'save_content',  
  133. 'type' => MS_Helper_Html::INPUT_TYPE_BUTTON,  
  134. 'value' => __( 'Save', 'membership2' ),  
  135. 'class' => 'button-primary',  
  136. 'ajax_data' => array( 'type' => 'content' ),  
  137. ),  
  138. ); 
  139.  
  140. $message_shortcode = $settings->get_protection_message( 
  141. MS_Model_Settings::PROTECTION_MSG_SHORTCODE,  
  142. $membership,  
  143. $override_shortcode 
  144. ); 
  145.  
  146. $groups['shortcode'] = array( 
  147. 'description' => array( 
  148. 'type' => MS_Helper_Html::TYPE_HTML_TEXT,  
  149. 'value' => __( 'Message displayed in place of a protected shortcode output.', 'membership2' ),  
  150. 'wrapper_class' => 'ms-block ms-tcenter',  
  151. ),  
  152. 'override' => array( 
  153. 'id' => 'override_shortcode',  
  154. 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER,  
  155. 'value' => $override_shortcode,  
  156. 'before' => __( 'Use default message', 'membership2' ),  
  157. 'after' => __( 'Define custom message', 'membership2' ),  
  158. 'wrapper_class' => 'ms-block ms-tcenter ms-spaced',  
  159. 'class' => 'override-slider',  
  160. 'ajax_data' => array( 1 ),  
  161. ),  
  162. 'editor' => array( 
  163. 'id' => 'shortcode',  
  164. 'type' => MS_Helper_Html::INPUT_TYPE_WP_EDITOR,  
  165. 'value' => $message_shortcode,  
  166. 'field_options' => array( 'editor_class' => 'ms-field-wp-editor' ),  
  167. ),  
  168. 'save' => array( 
  169. 'id' => 'save_content',  
  170. 'type' => MS_Helper_Html::INPUT_TYPE_BUTTON,  
  171. 'value' => __( 'Save', 'membership2' ),  
  172. 'class' => 'button-primary',  
  173. 'ajax_data' => array( 'type' => 'shortcode' ),  
  174. ),  
  175. ); 
  176.  
  177. $message_more_tag = $settings->get_protection_message( 
  178. MS_Model_Settings::PROTECTION_MSG_MORE_TAG,  
  179. $membership,  
  180. $override_more_tag 
  181. ); 
  182.  
  183. $groups['more_tag'] = array( 
  184. 'description' => array( 
  185. 'type' => MS_Helper_Html::TYPE_HTML_TEXT,  
  186. 'value' => __( 'Message displayed in place of the read-more contents.', 'membership2' ),  
  187. 'wrapper_class' => 'ms-block ms-tcenter',  
  188. ),  
  189. 'override' => array( 
  190. 'id' => 'override_content',  
  191. 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER,  
  192. 'value' => $override_more_tag,  
  193. 'before' => __( 'Use default message', 'membership2' ),  
  194. 'after' => __( 'Define custom message', 'membership2' ),  
  195. 'wrapper_class' => 'ms-block ms-tcenter ms-spaced',  
  196. 'class' => 'override-slider',  
  197. 'ajax_data' => array( 1 ),  
  198. ),  
  199. 'editor' => array( 
  200. 'id' => 'more_tag',  
  201. 'type' => MS_Helper_Html::INPUT_TYPE_WP_EDITOR,  
  202. 'value' => $message_more_tag,  
  203. 'field_options' => array( 'editor_class' => 'ms-field-wp-editor' ),  
  204. ),  
  205. 'save' => array( 
  206. 'id' => 'save_content',  
  207. 'type' => MS_Helper_Html::INPUT_TYPE_BUTTON,  
  208. 'value' => __( 'Save', 'membership2' ),  
  209. 'class' => 'button-primary',  
  210. 'ajax_data' => array( 'type' => 'more_tag' ),  
  211. ),  
  212. ); 
  213.  
  214. foreach ( $groups as $key => $fields ) { 
  215. if ( ! ( $membership instanceof MS_Model_Membership ) ) { 
  216. unset( $fields['override'] ); 
  217.  
  218. foreach ( $fields as $id => $field ) { 
  219. if ( empty( $field['ajax_data'] ) ) { 
  220. continue; 
  221. if ( ! empty( $field['ajax_data']['action'] ) ) { 
  222. continue; 
  223.  
  224. if ( ! isset( $fields[ $id ]['ajax_data']['field'] ) ) { 
  225. $fields[ $id ]['ajax_data']['field'] = $fields[ $id ]['id']; 
  226. $fields[ $id ]['ajax_data']['_wpnonce'] = $nonce; 
  227. $fields[ $id ]['ajax_data']['action'] = $action; 
  228.  
  229. if ( $membership instanceof MS_Model_Membership ) { 
  230. $fields[$id]['ajax_data']['membership_id'] = $membership->id; 
  231.  
  232. $groups[$key] = $fields; 
  233.  
  234. return apply_filters( 
  235. 'ms_view_settings_prepare_pages_fields',  
  236. $groups 
  237. ); 
.