MS_Addon_Mailchimp_View

The Membership 2 MS Addon Mailchimp View class.

Defined (1)

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

/app/addon/mailchimp/class-ms-addon-mailchimp-view.php  
  1. class MS_Addon_Mailchimp_View extends MS_View { 
  2.  
  3. /** 
  4. * Returns the HTML code of the Settings form. 
  5. * @since 1.0.0 
  6. * @return string 
  7. */ 
  8. public function render_tab() { 
  9. $fields = $this->prepare_fields(); 
  10. ob_start(); 
  11. ?> 
  12. <div class="ms-addon-wrap"> 
  13. <?php 
  14. MS_Helper_Html::settings_tab_header( 
  15. array( 'title' => __( 'MailChimp Settings', 'membership2' ) ) 
  16. ); 
  17.  
  18. foreach ( $fields as $field ) { 
  19. MS_Helper_Html::html_element( $field ); 
  20. ?> 
  21. </div> 
  22. <?php 
  23. $html = ob_get_clean(); 
  24. echo $html; 
  25.  
  26. /** 
  27. * Prepare fields that are displayed in the form. 
  28. * @since 1.0.1.0 
  29. * @return array 
  30. */ 
  31. protected function prepare_fields() { 
  32. $api_status = MS_Addon_Mailchimp::get_api_status(); 
  33. $settings = $this->data['settings']; 
  34.  
  35. $action = MS_Controller_Settings::AJAX_ACTION_UPDATE_CUSTOM_SETTING; 
  36. $auto_opt_in = $settings->get_custom_setting( 'mailchimp', 'auto_opt_in' ); 
  37. $auto_opt_in = lib3()->is_true( $auto_opt_in ); 
  38.  
  39. $fields = array( 
  40. 'mailchimp_api_test' => array( 
  41. 'id' => 'mailchimp_api_test',  
  42. 'type' => MS_Helper_Html::TYPE_HTML_TEXT,  
  43. 'title' => __( 'MailChimp API test status: ', 'membership2' ),  
  44. 'value' => ( $api_status ) ? __( 'Verified', 'membership2' ) : __( 'Failed', 'membership2' ),  
  45. 'class' => ( $api_status ) ? 'ms-ok' : 'ms-nok',  
  46. ),  
  47.  
  48. 'mailchimp_api_key' => array( 
  49. 'id' => 'mailchimp_api_key',  
  50. 'name' => 'custom[mailchimp][api_key]',  
  51. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  52. 'title' => __( 'MailChimp API Key', 'membership2' ),  
  53. 'desc' => sprintf( 
  54. '<div>' . __( 'Visit <a href="%1$s">your API dashboard</a> to create an API Key.', 'membership2' ) . '</div>',  
  55. 'http://admin.mailchimp.com/account/api" target="_blank' 
  56. ),  
  57. 'value' => $settings->get_custom_setting( 'mailchimp', 'api_key' ),  
  58. 'class' => 'ms-text-medium',  
  59. 'ajax_data' => array( 
  60. 'group' => 'mailchimp',  
  61. 'field' => 'api_key',  
  62. 'action' => $action,  
  63. ),  
  64. ),  
  65.  
  66. 'separator' => array( 
  67. 'type' => MS_Helper_Html::TYPE_HTML_SEPARATOR,  
  68. ),  
  69.  
  70. 'auto_opt_in' => array( 
  71. 'id' => 'auto_opt_in',  
  72. 'name' => 'custom[mailchimp][auto_opt_in]',  
  73. 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER,  
  74. 'title' => __( 'Automatically opt-in new users to the mailing list.', 'membership2' ),  
  75. 'desc' => __( 'Users will not receive an email confirmation. You are responsible to inform your users.', 'membership2' ),  
  76. 'value' => $auto_opt_in,  
  77. 'class' => 'inp-before',  
  78. 'ajax_data' => array( 
  79. 'group' => 'mailchimp',  
  80. 'field' => 'auto_opt_in',  
  81. 'action' => $action,  
  82. ),  
  83. ),  
  84.  
  85. 'separator1' => array( 
  86. 'type' => MS_Helper_Html::TYPE_HTML_SEPARATOR,  
  87. ),  
  88.  
  89. 'mail_list_registered' => array( 
  90. 'id' => 'mail_list_registered',  
  91. 'name' => 'custom[mailchimp][mail_list_registered]',  
  92. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  93. 'title' => __( 'Registered users mailing list (not members)', 'membership2' ),  
  94. 'field_options' => MS_Addon_Mailchimp::get_mail_lists(),  
  95. 'value' => $settings->get_custom_setting( 'mailchimp', 'mail_list_registered' ),  
  96. 'ajax_data' => array( 
  97. 'group' => 'mailchimp',  
  98. 'field' => 'mail_list_registered',  
  99. 'action' => $action,  
  100. ),  
  101. ),  
  102.  
  103. 'mail_list_members' => array( 
  104. 'id' => 'mail_list_members',  
  105. 'name' => 'custom[mailchimp][mail_list_members]',  
  106. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  107. 'title' => __( 'Members mailing list', 'membership2' ),  
  108. 'field_options' => MS_Addon_Mailchimp::get_mail_lists(),  
  109. 'value' => $settings->get_custom_setting( 'mailchimp', 'mail_list_members' ),  
  110. 'ajax_data' => array( 
  111. 'group' => 'mailchimp',  
  112. 'field' => 'mail_list_members',  
  113. 'action' => $action,  
  114. ),  
  115. ),  
  116.  
  117. 'mail_list_deactivated' => array( 
  118. 'id' => 'mail_list_deactivated',  
  119. 'name' => 'custom[mailchimp][mail_list_deactivated]',  
  120. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  121. 'title' => __( 'Deactivated memberships mailing list', 'membership2' ),  
  122. 'field_options' => MS_Addon_Mailchimp::get_mail_lists(),  
  123. 'value' => $settings->get_custom_setting( 'mailchimp', 'mail_list_deactivated' ),  
  124. 'ajax_data' => array( 
  125. 'group' => 'mailchimp',  
  126. 'field' => 'mail_list_deactivated',  
  127. 'action' => $action,  
  128. ),  
  129. ),  
  130. ); 
  131.  
  132. return $fields;