options.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <?php
  2. defined('ABSPATH') || exit;
  3. @include_once NEWSLETTER_INCLUDES_DIR . '/controls.php';
  4. $controls = new NewsletterControls();
  5. $module = NewsletterSubscription::instance();
  6. $current_language = $module->get_current_language();
  7. $is_all_languages = $module->is_all_languages();
  8. $controls->add_language_warning();
  9. $options = $module->get_options('', $current_language);
  10. if ($controls->is_action()) {
  11. if ($controls->is_action('save')) {
  12. $defaults = $module->get_default_options();
  13. // Without the last curly bracket since there can be a form number apended
  14. if (empty($controls->data['subscription_text'])) {
  15. $controls->data['subscription_text'] = $defaults['subscription_text'];
  16. }
  17. if (empty($controls->data['confirmation_text'])) {
  18. $controls->data['confirmation_text'] = $defaults['confirmation_text'];
  19. }
  20. if (empty($controls->data['confirmation_subject'])) {
  21. $controls->data['confirmation_subject'] = $defaults['confirmation_subject'];
  22. }
  23. if (empty($controls->data['confirmation_message'])) {
  24. $controls->data['confirmation_message'] = $defaults['confirmation_message'];
  25. }
  26. if (empty($controls->data['confirmed_text'])) {
  27. $controls->data['confirmed_text'] = $defaults['confirmed_text'];
  28. }
  29. if (empty($controls->data['confirmed_subject'])) {
  30. $controls->data['confirmed_subject'] = $defaults['confirmed_subject'];
  31. }
  32. if (empty($controls->data['confirmed_message'])) {
  33. $controls->data['confirmed_message'] = $defaults['confirmed_message'];
  34. }
  35. $controls->data['confirmed_message'] = NewsletterModule::clean_url_tags($controls->data['confirmed_message']);
  36. $controls->data['confirmed_text'] = NewsletterModule::clean_url_tags($controls->data['confirmed_text']);
  37. $controls->data['confirmation_text'] = NewsletterModule::clean_url_tags($controls->data['confirmation_text']);
  38. $controls->data['confirmation_message'] = NewsletterModule::clean_url_tags($controls->data['confirmation_message']);
  39. $controls->data['confirmed_url'] = trim($controls->data['confirmed_url']);
  40. $controls->data['confirmation_url'] = trim($controls->data['confirmation_url']);
  41. $module->save_options($controls->data, '', null, $current_language);
  42. $controls->add_message_saved();
  43. }
  44. if ($controls->is_action('reset')) {
  45. $controls->data = $module->reset_options();
  46. }
  47. if ($controls->is_action('test-confirmation')) {
  48. $users = NewsletterUsers::instance()->get_test_users();
  49. if (count($users) == 0) {
  50. $controls->errors = 'There are no test subscribers. Read more about test subscribers <a href="https://www.thenewsletterplugin.com/plugins/newsletter/subscribers-module#test" target="_blank">here</a>.';
  51. } else {
  52. $addresses = array();
  53. foreach ($users as &$user) {
  54. $addresses[] = $user->email;
  55. $res = $module->send_message('confirmation', $user);
  56. if (!$res) {
  57. $controls->errors = 'The email address ' . $user->email . ' failed.';
  58. break;
  59. }
  60. }
  61. $controls->messages .= 'Test emails sent to ' . count($users) . ' test subscribers: ' .
  62. implode(', ', $addresses) . '. Read more about test subscribers <a href="https://www.thenewsletterplugin.com/plugins/newsletter/subscribers-module#test" target="_blank">here</a>.';
  63. $controls->messages .= '<br>If the message is not received, try to change the message text it could trigger some antispam filters.';
  64. }
  65. }
  66. if ($controls->is_action('test-confirmed')) {
  67. $users = NewsletterUsers::instance()->get_test_users();
  68. if (count($users) == 0) {
  69. $controls->errors = 'There are no test subscribers. Read more about test subscribers <a href="https://www.thenewsletterplugin.com/plugins/newsletter/subscribers-module#test" target="_blank">here</a>.';
  70. } else {
  71. $addresses = array();
  72. foreach ($users as $user) {
  73. $addresses[] = $user->email;
  74. $res = $module->send_message('confirmed', $user);
  75. if (!$res) {
  76. $controls->errors = 'The email address ' . $user->email . ' failed.';
  77. break;
  78. }
  79. }
  80. $controls->messages .= 'Test emails sent to ' . count($users) . ' test subscribers: ' .
  81. implode(', ', $addresses) . '. Read more about test subscribers <a href="https://www.thenewsletterplugin.com/plugins/newsletter/subscribers-module#test" target="_blank">here</a>.';
  82. $controls->messages .= '<br>If the message is not received, try to change the message text it could trigger some antispam filters.';
  83. }
  84. }
  85. } else {
  86. $controls->data = $module->get_options('', $current_language);
  87. }
  88. ?>
  89. <div class="wrap" id="tnp-wrap">
  90. <?php include NEWSLETTER_DIR . '/tnp-header.php'; ?>
  91. <div id="tnp-heading">
  92. <h2><?php _e('Subscription Configuration', 'newsletter') ?></h2>
  93. <?php $controls->page_help('https://www.thenewsletterplugin.com/documentation/subscription') ?>
  94. </div>
  95. <div id="tnp-body">
  96. <form method="post" action="">
  97. <?php $controls->init(); ?>
  98. <div id="tabs">
  99. <ul>
  100. <li><a href="#tabs-general"><?php _e('General', 'newsletter') ?></a></li>
  101. <li><a href="#tabs-2"><?php _e('Subscription', 'newsletter') ?></a></li>
  102. <li><a href="#tabs-4"><?php _e('Welcome', 'newsletter') ?></a></li>
  103. <li><a href="#tabs-3"><?php _e('Activation', 'newsletter') ?></a></li>
  104. </ul>
  105. <div id="tabs-general">
  106. <?php if ($is_all_languages) { ?>
  107. <table class="form-table">
  108. <tr>
  109. <th><?php _e('Opt In', 'newsletter') ?></th>
  110. <td>
  111. <?php $controls->select('noconfirmation', array(0 => __('Double Opt In', 'newsletter'), 1 => __('Single Opt In', 'newsletter'))); ?>
  112. <?php $controls->help('https://www.thenewsletterplugin.com/documentation/subscription#opt-in') ?>
  113. </td>
  114. </tr>
  115. <tr>
  116. <th><?php _e('Override Opt In', 'newsletter') ?></th>
  117. <td>
  118. <?php $controls->yesno('optin_override'); ?>
  119. </td>
  120. </tr>
  121. <tr>
  122. <th><?php _e('Repeated subscriptions', 'newsletter') ?></th>
  123. <td>
  124. <?php //$controls->select('multiple', array('0'=>__('No', 'newsletter'), '1'=>__('Yes', 'newsletter'), '2'=>__('On new lists added', 'newsletter'))); ?>
  125. <?php $controls->select('multiple', array('0'=>__('No', 'newsletter'), '1'=>__('Yes', 'newsletter'))); ?>
  126. <?php $controls->help('https://www.thenewsletterplugin.com/documentation/subscription#repeated')?>
  127. </td>
  128. </tr>
  129. <tr>
  130. <th><?php _e('Notifications', 'newsletter') ?></th>
  131. <td>
  132. <?php $controls->yesno('notify'); ?>
  133. <?php $controls->text_email('notify_email'); ?>
  134. </td>
  135. </tr>
  136. </table>
  137. <?php } else { ?>
  138. <p>Switch to "All languages" to manage these options.</p>
  139. <?php } ?>
  140. </div>
  141. <div id="tabs-2">
  142. <table class="form-table">
  143. <tr>
  144. <th><?php _e('Subscription page', 'newsletter') ?><br><?php echo $controls->help('https://www.thenewsletterplugin.com/documentation/newsletter-tags') ?></th>
  145. <td>
  146. <?php $controls->wp_editor('subscription_text'); ?>
  147. </td>
  148. </tr>
  149. </table>
  150. <h3>Special cases</h3>
  151. <table class="form-table">
  152. <tr>
  153. <th><?php _e('Error page', 'newsletter') ?></th>
  154. <td>
  155. <?php $controls->wp_editor('error_text'); ?>
  156. </td>
  157. </tr>
  158. </table>
  159. </div>
  160. <div id="tabs-3">
  161. <p><?php _e('Only for double opt-in mode.', 'newsletter') ?></p>
  162. <?php $controls->panel_help('https://www.thenewsletterplugin.com/documentation/subscription#activation') ?>
  163. <table class="form-table">
  164. <tr>
  165. <th><?php _e('Activation message', 'newsletter') ?></th>
  166. <td>
  167. <?php $controls->wp_editor('confirmation_text'); ?>
  168. </td>
  169. </tr>
  170. <tr>
  171. <th><?php _e('Alternative activation page', 'newsletter'); ?></th>
  172. <td>
  173. <?php $controls->text('confirmation_url', 70, 'https://...'); ?>
  174. </td>
  175. </tr>
  176. <!-- CONFIRMATION EMAIL -->
  177. <tr>
  178. <th><?php _e('Activation email', 'newsletter') ?></th>
  179. <td>
  180. <?php $controls->email('confirmation', 'wordpress'); ?>
  181. <br>
  182. <?php $controls->button('test-confirmation', 'Send a test'); ?>
  183. </td>
  184. </tr>
  185. </table>
  186. </div>
  187. <div id="tabs-4">
  188. <p>
  189. <?php $controls->panel_help('https://www.thenewsletterplugin.com/documentation/subscription#welcome') ?>
  190. </p>
  191. <table class="form-table">
  192. <tr>
  193. <th><?php _e('Welcome message', 'newsletter') ?></th>
  194. <td>
  195. <?php $controls->wp_editor('confirmed_text'); ?>
  196. </td>
  197. </tr>
  198. <tr>
  199. <th><?php _e('Alternative welcome page URL', 'newsletter') ?></th>
  200. <td>
  201. <?php $controls->text('confirmed_url', 70, 'https://...'); ?>
  202. </td>
  203. </tr>
  204. <tr>
  205. <th><?php _e('Conversion tracking code', 'newsletter') ?>
  206. <?php $controls->help('https://www.thenewsletterplugin.com/documentation/subscription#conversion') ?></th>
  207. <td>
  208. <?php $controls->textarea('confirmed_tracking'); ?>
  209. </td>
  210. </tr>
  211. <!-- WELCOME/CONFIRMED EMAIL -->
  212. <tr>
  213. <th>
  214. <?php _e('Welcome email', 'newsletter') ?>
  215. </th>
  216. <td>
  217. <?php $controls->email('confirmed', 'wordpress', $is_all_languages); ?>
  218. <br>
  219. <?php $controls->button('test-confirmed', 'Send a test'); ?>
  220. </td>
  221. </tr>
  222. </table>
  223. </div>
  224. </div>
  225. <p>
  226. <?php $controls->button_save() ?>
  227. <?php $controls->button_reset() ?>
  228. </p>
  229. </form>
  230. </div>
  231. <?php include NEWSLETTER_DIR . '/tnp-footer.php'; ?>
  232. </div>