MS_View_Settings_Page_Messages

The Membership 2 MS View Settings Page Messages class.

Defined (1)

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

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