MS_View_Settings_Page_Communications

The Membership 2 MS View Settings Page Communications class.

Defined (1)

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

/app/view/settings/page/class-ms-view-settings-page-communications.php  
  1. class MS_View_Settings_Page_Communications 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. $comm = $this->data['comm']; 
  10. $fields = $this->get_fields(); 
  11.  
  12. $this->add_action( 'admin_footer', 'wp_footer' ); 
  13. $title = __( 'Automated Email Responses', '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_EMAILS ) 
  24. ); 
  25. $desc = sprintf( 
  26. __( 'Here you can override %sdefault messages%s for this membership.', 'membership2' ),  
  27. '<a href="' . $settings_url . '">',  
  28. '</a>' 
  29. ); 
  30. } else { 
  31. $desc = ''; 
  32.  
  33. ob_start(); 
  34.  
  35. MS_Helper_Html::settings_tab_header( 
  36. array( 'title' => $title, 'desc' => $desc ) 
  37. ); 
  38. ?> 
  39.  
  40. <form id="ms-comm-type-form" action="" method="post"> 
  41. <?php 
  42. MS_Helper_Html::html_element( $fields['load_action'] ); 
  43. MS_Helper_Html::html_element( $fields['load_nonce'] ); 
  44. MS_Helper_Html::html_element( $fields['comm_type'] ); 
  45. MS_Helper_Html::html_element( $fields['switch_comm_type'] ); 
  46. ?> 
  47. </form> 
  48.  
  49. <?php 
  50. MS_Helper_Html::html_separator(); 
  51. if ( ! empty( $fields['override'] ) ) { 
  52. MS_Helper_Html::html_element( $fields['override'] ); 
  53. ?> 
  54.  
  55. <form action="" method="post" class="ms-editor-form"> 
  56. <?php 
  57. if ( ! empty( $fields['membership_id'] ) ) { 
  58. MS_Helper_Html::html_separator(); 
  59. MS_Helper_Html::html_element( $fields['membership_id'] ); 
  60. MS_Helper_Html::html_element( $fields['action'] ); 
  61. MS_Helper_Html::html_element( $fields['nonce'] ); 
  62. MS_Helper_Html::html_element( $fields['type'] ); 
  63.  
  64. if ( is_a( $comm, 'MS_Model_Communication' ) ) { 
  65. printf( 
  66. '<h3>%1$s %2$s: %3$s</h3><div class="ms-description" style="margin-bottom:20px;">%4$s</div>',  
  67. $comm->get_title(),  
  68. __( 'Message', 'membership2' ),  
  69. MS_Helper_Html::html_element( $fields['enabled'], true ),  
  70. $comm->get_description() 
  71. ); 
  72.  
  73. if ( $comm->period_enabled ) { 
  74. echo '<div class="ms-period-wrapper clear">'; 
  75. $fields['period_unit'] = $comm->set_period_name( $fields['period_unit'] ); 
  76. MS_Helper_Html::html_element( $fields['period_unit'] ); 
  77. MS_Helper_Html::html_element( $fields['period_type'] ); 
  78. echo '</div>'; 
  79.  
  80. MS_Helper_Html::html_element( $fields['subject'] ); 
  81. MS_Helper_Html::html_element( $fields['email_body'] ); 
  82.  
  83. MS_Helper_Html::html_element( $fields['cc_enabled'] ); 
  84. echo '   '; 
  85. MS_Helper_Html::html_element( $fields['cc_email'] ); 
  86. MS_Helper_Html::html_separator(); 
  87. MS_Helper_Html::html_element( $fields['save_email'] ); 
  88. ?> 
  89. </form> 
  90. <?php 
  91.  
  92. return ob_get_clean(); 
  93.  
  94. /** 
  95. * Add short JS values in page footer. 
  96. * @since 1.0.0 
  97. */ 
  98. public function wp_footer() { 
  99. $comm = $this->data['comm']; 
  100. $vars = $comm->comm_vars; 
  101. $vars = lib3()->array->get( $vars ); 
  102.  
  103. /** 
  104. * Print JS details for the custom TinyMCE "Insert Variable" button 
  105. * @see class-ms-controller-settings.php (function add_mce_buttons) 
  106. * @see ms-view-settings-automated-msg.js 
  107. */ 
  108. $var_button = array( 
  109. 'title' => __( 'Insert Membership Variables', 'membership2' ),  
  110. 'items' => $vars,  
  111. ); 
  112.  
  113. printf( 
  114. '<script>window.ms_data.var_button = %1$s;window.ms_data.lang_confirm = %2$s</script>',  
  115. json_encode( $var_button ),  
  116. json_encode( 
  117. __( 'You have made changes that are not saved yet. Do you want to discard those changes?', 'membership2' ) 
  118. ); 
  119.  
  120. /** 
  121. * Prepare the fields that are displayed in the form. 
  122. * @since 1.0.1.0 
  123. * @return array 
  124. */ 
  125. protected function get_fields() { 
  126. $comm = $this->data['comm']; 
  127. $membership = false; 
  128. $membership_id = 0; 
  129.  
  130. if ( isset( $this->data['membership'] ) ) { 
  131. $membership = $this->data['membership']; 
  132.  
  133. if ( $membership instanceof MS_Model_Membership ) { 
  134. $membership_id = $membership->id; 
  135. } else { 
  136. $membership = false; 
  137.  
  138. lib3()->array->equip( 
  139. $comm,  
  140. 'type',  
  141. 'enabled',  
  142. 'period',  
  143. 'subject',  
  144. 'description',  
  145. 'cc_enabled',  
  146. 'cc_email' 
  147. ); 
  148.  
  149. $action = MS_Controller_Communication::AJAX_ACTION_UPDATE_COMM; 
  150. $nonce = wp_create_nonce( $action ); 
  151. $comm_titles = MS_Model_Communication::get_communication_type_titles( 
  152. $membership 
  153. ); 
  154.  
  155. $key_active = __( 'Send Email', 'membership2' ); 
  156. $key_inactive = __( 'No Email', 'membership2' ); 
  157. $key_skip = __( 'Use default template', 'membership2' ); 
  158. $titles = array( 
  159. $key_active => array(),  
  160. $key_inactive => array(),  
  161. $key_skip => array(),  
  162. ); 
  163. foreach ( $comm_titles as $type => $title ) { 
  164. $tmp_comm = MS_Model_Communication::get_communication( 
  165. $type,  
  166. $membership,  
  167. true 
  168. ); 
  169.  
  170. if ( $membership && ! $tmp_comm->override ) { 
  171. $titles[$key_skip][$type] = $title; 
  172. } elseif ( $tmp_comm->enabled ) { 
  173. $titles[$key_active][$type] = $title; 
  174. } else { 
  175. $titles[$key_inactive][$type] = $title; 
  176.  
  177. $fields = array( 
  178. 'comm_type' => array( 
  179. 'id' => 'comm_type',  
  180. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  181. 'value' => $comm->type,  
  182. 'field_options' => $titles,  
  183. ),  
  184.  
  185. 'switch_comm_type' => array( 
  186. 'id' => 'switch_comm_type',  
  187. 'type' => MS_Helper_Html::INPUT_TYPE_BUTTON,  
  188. 'value' => __( 'Load Template', 'membership2' ),  
  189. ),  
  190.  
  191. 'override' => array( 
  192. 'id' => 'override',  
  193. 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER,  
  194. 'value' => $comm->override,  
  195. 'before' => __( 'Use default template', 'membership2' ),  
  196. 'after' => __( 'Define custom template', 'membership2' ),  
  197. 'wrapper_class' => 'ms-block ms-tcenter',  
  198. 'class' => 'override-slider',  
  199. 'ajax_data' => array( 
  200. 'type' => $comm->type,  
  201. 'field' => 'override',  
  202. 'action' => $action,  
  203. '_wpnonce' => $nonce,  
  204. 'membership_id' => $membership_id,  
  205. ),  
  206. ),  
  207.  
  208. 'membership_id' => array( 
  209. 'id' => 'membership_id',  
  210. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  211. 'value' => $membership_id,  
  212. ),  
  213.  
  214. 'type' => array( 
  215. 'id' => 'type',  
  216. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  217. 'value' => $comm->type,  
  218. ),  
  219.  
  220. 'enabled' => array( 
  221. 'id' => 'enabled',  
  222. 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER,  
  223. 'value' => $comm->enabled,  
  224. 'class' => 'state-slider',  
  225. 'before' => ' <i class="wpmui-fa wpmui-fa-ban"></i>',  
  226. 'after' => '<i class="wpmui-fa wpmui-fa-envelope"></i> ',  
  227. 'ajax_data' => array( 
  228. 'type' => $comm->type,  
  229. 'field' => 'enabled',  
  230. 'action' => $action,  
  231. '_wpnonce' => $nonce,  
  232. 'membership_id' => $membership_id,  
  233. ),  
  234. ),  
  235.  
  236. // Note: title/desc is overwritten by MS_Model_Communication (below) 
  237. 'period_unit' => array( 
  238. 'id' => 'period_unit',  
  239. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  240. 'title' => __( 'Period after/before', 'membership2' ),  
  241. 'value' => $comm->period['period_unit'],  
  242. ),  
  243.  
  244. 'period_type' => array( 
  245. 'id' => 'period_type',  
  246. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  247. 'value' => $comm->period['period_type'],  
  248. 'field_options' => MS_Helper_Period::get_period_types( 'plural' ),  
  249. ),  
  250.  
  251. 'subject' => array( 
  252. 'id' => 'subject',  
  253. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  254. 'title' => apply_filters( 
  255. 'ms_translation_flag',  
  256. __( 'Message Subject', 'membership2' ),  
  257. 'communication-subject' 
  258. ),  
  259. 'value' => $comm->subject,  
  260. 'class' => 'ms-comm-subject widefat',  
  261. ),  
  262.  
  263. 'email_body' => array( 
  264. 'id' => 'email_body',  
  265. 'type' => MS_Helper_Html::INPUT_TYPE_WP_EDITOR,  
  266. 'title' => apply_filters( 
  267. 'ms_translation_flag',  
  268. '',  
  269. 'communication-body' 
  270. ),  
  271. 'value' => $comm->description,  
  272. 'field_options' => array( 
  273. 'media_buttons' => false,  
  274. 'editor_class' => 'wpmui-ajax-update',  
  275. ),  
  276. ),  
  277.  
  278. 'cc_enabled' => array( 
  279. 'id' => 'cc_enabled',  
  280. 'type' => MS_Helper_Html::INPUT_TYPE_CHECKBOX,  
  281. 'title' => __( 'Send copy to Administrator', 'membership2' ),  
  282. 'value' => $comm->cc_enabled,  
  283. 'class' => 'ms-inline-block',  
  284. ),  
  285.  
  286. 'cc_email' => array( 
  287. 'id' => 'cc_email',  
  288. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  289. 'value' => $comm->cc_email,  
  290. 'field_options' => MS_Model_Member::get_admin_user_emails(),  
  291. ),  
  292.  
  293. 'save_email' => array( 
  294. 'id' => 'save_email',  
  295. 'value' => __( 'Save Changes', 'membership2' ),  
  296. 'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT,  
  297. ),  
  298.  
  299. 'action' => array( 
  300. 'id' => 'action',  
  301. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  302. 'value' => 'save_comm',  
  303. ),  
  304.  
  305. 'nonce' => array( 
  306. 'id' => '_wpnonce',  
  307. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  308. 'value' => wp_create_nonce( 'save_comm' ),  
  309. ),  
  310.  
  311. 'load_action' => array( 
  312. 'id' => 'load_action',  
  313. 'name' => 'action',  
  314. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  315. 'value' => 'load_action',  
  316. ),  
  317.  
  318. 'load_nonce' => array( 
  319. 'id' => '_wpnonce1',  
  320. 'name' => '_wpnonce',  
  321. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  322. 'value' => wp_create_nonce( 'load_action' ),  
  323. ),  
  324. ); 
  325.  
  326. if ( ! ( $membership instanceof MS_Model_Membership ) ) { 
  327. unset( $fields['override'] ); 
  328. unset( $fields['membership_id'] ); 
  329.  
  330. return apply_filters( 
  331. 'ms_view_settings_prepare_email_fields',  
  332. $fields 
  333. );