tab-settings.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * Settings tab.
  4. *
  5. * @package studiou-wc-mail-queue
  6. * @copyright 2026 QUADARAX
  7. * @author Dalibor Votruba <dvotruba@quadarax.com>
  8. * @license GPL-2.0-or-later
  9. */
  10. defined( 'ABSPATH' ) || exit;
  11. $wcmq_settings = Studiou_WCMQ_Settings::all();
  12. $wcmq_contexts = Studiou_WCMQ_Admin::available_contexts();
  13. $wcmq_handled = Studiou_WCMQ_Settings::handled_contexts();
  14. $wcmq_is_on = Studiou_WCMQ_State::is_queueing();
  15. $wcmq_action_url = admin_url( 'admin-post.php' );
  16. ?>
  17. <form method="post" action="<?php echo esc_url( $wcmq_action_url ); ?>" class="studiou-wcmq-toggle-form">
  18. <?php wp_nonce_field( Studiou_WCMQ_Admin::NONCE ); ?>
  19. <input type="hidden" name="action" value="studiou_wcmq_toggle_state" />
  20. <input type="hidden" name="wcmq_state" value="<?php echo $wcmq_is_on ? 'disabled' : 'enabled'; ?>" />
  21. <p>
  22. <button type="submit" class="button button-primary">
  23. <?php
  24. echo $wcmq_is_on
  25. ? esc_html__( 'Disable mail queue', 'studiou-wc-mail-queue' )
  26. : esc_html__( 'Enable mail queue', 'studiou-wc-mail-queue' );
  27. ?>
  28. </button>
  29. <span class="description">
  30. <?php esc_html_e( 'Disabling stops queueing new mail; anything already queued still sends at the configured rate.', 'studiou-wc-mail-queue' ); ?>
  31. </span>
  32. </p>
  33. </form>
  34. <hr />
  35. <form method="post" action="<?php echo esc_url( $wcmq_action_url ); ?>">
  36. <?php wp_nonce_field( Studiou_WCMQ_Admin::NONCE ); ?>
  37. <input type="hidden" name="action" value="studiou_wcmq_save_settings" />
  38. <h2><?php esc_html_e( 'Rate limit', 'studiou-wc-mail-queue' ); ?></h2>
  39. <table class="form-table" role="presentation">
  40. <tr>
  41. <th scope="row">
  42. <label for="rate_per_minute"><?php esc_html_e( 'Mails per minute', 'studiou-wc-mail-queue' ); ?></label>
  43. </th>
  44. <td>
  45. <input type="number" min="1" max="60" step="1" id="rate_per_minute" name="rate_per_minute"
  46. value="<?php echo esc_attr( $wcmq_settings['rate_per_minute'] ); ?>" class="small-text" />
  47. <p class="description">
  48. <?php esc_html_e( 'Set this below your host\'s real outbound limit — ask their support for the exact number. A value above the real limit reproduces the original problem.', 'studiou-wc-mail-queue' ); ?>
  49. </p>
  50. </td>
  51. </tr>
  52. </table>
  53. <h2><?php esc_html_e( 'Emails handled by the queue', 'studiou-wc-mail-queue' ); ?></h2>
  54. <p class="description">
  55. <?php esc_html_e( 'Anything not ticked here sends immediately, exactly as it does today. Never queue password resets.', 'studiou-wc-mail-queue' ); ?>
  56. </p>
  57. <fieldset class="studiou-wcmq-contexts">
  58. <?php foreach ( $wcmq_contexts as $wcmq_id => $wcmq_label ) : ?>
  59. <label>
  60. <input type="checkbox" name="handled_contexts[]" value="<?php echo esc_attr( $wcmq_id ); ?>"
  61. <?php checked( in_array( $wcmq_id, $wcmq_handled, true ) ); ?> />
  62. <?php echo esc_html( $wcmq_label ); ?>
  63. <code><?php echo esc_html( $wcmq_id ); ?></code>
  64. </label>
  65. <?php endforeach; ?>
  66. </fieldset>
  67. <h2><?php esc_html_e( 'Retention', 'studiou-wc-mail-queue' ); ?></h2>
  68. <p class="description">
  69. <?php esc_html_e( 'The queue stores rendered emails and copies of their attachments. Retention is a privacy control, not just housekeeping. 0 = keep forever.', 'studiou-wc-mail-queue' ); ?>
  70. </p>
  71. <table class="form-table" role="presentation">
  72. <tr>
  73. <th scope="row"><label for="retention_sent_days"><?php esc_html_e( 'Keep sent mail (days)', 'studiou-wc-mail-queue' ); ?></label></th>
  74. <td><input type="number" min="0" step="1" id="retention_sent_days" name="retention_sent_days" value="<?php echo esc_attr( $wcmq_settings['retention_sent_days'] ); ?>" class="small-text" /></td>
  75. </tr>
  76. <tr>
  77. <th scope="row"><label for="retention_failed_days"><?php esc_html_e( 'Keep failed mail (days)', 'studiou-wc-mail-queue' ); ?></label></th>
  78. <td><input type="number" min="0" step="1" id="retention_failed_days" name="retention_failed_days" value="<?php echo esc_attr( $wcmq_settings['retention_failed_days'] ); ?>" class="small-text" /></td>
  79. </tr>
  80. <tr>
  81. <th scope="row"><label for="retention_log_days"><?php esc_html_e( 'Keep log entries (days)', 'studiou-wc-mail-queue' ); ?></label></th>
  82. <td><input type="number" min="0" step="1" id="retention_log_days" name="retention_log_days" value="<?php echo esc_attr( $wcmq_settings['retention_log_days'] ); ?>" class="small-text" /></td>
  83. </tr>
  84. </table>
  85. <h2><?php esc_html_e( 'Reliability', 'studiou-wc-mail-queue' ); ?></h2>
  86. <table class="form-table" role="presentation">
  87. <tr>
  88. <th scope="row"><label for="max_attempts"><?php esc_html_e( 'Max send attempts', 'studiou-wc-mail-queue' ); ?></label></th>
  89. <td>
  90. <input type="number" min="1" max="10" step="1" id="max_attempts" name="max_attempts" value="<?php echo esc_attr( $wcmq_settings['max_attempts'] ); ?>" class="small-text" />
  91. <p class="description"><?php esc_html_e( 'Completed attempts where the mail server rejected the message.', 'studiou-wc-mail-queue' ); ?></p>
  92. </td>
  93. </tr>
  94. <tr>
  95. <th scope="row"><label for="max_reclaims"><?php esc_html_e( 'Max crash recoveries', 'studiou-wc-mail-queue' ); ?></label></th>
  96. <td>
  97. <input type="number" min="1" max="20" step="1" id="max_reclaims" name="max_reclaims" value="<?php echo esc_attr( $wcmq_settings['max_reclaims'] ); ?>" class="small-text" />
  98. <p class="description"><?php esc_html_e( 'Times a mail may be rescued after the sending process died. Counted separately from send attempts, so a PHP timeout never burns a healthy mail\'s retry budget.', 'studiou-wc-mail-queue' ); ?></p>
  99. </td>
  100. </tr>
  101. <tr>
  102. <th scope="row"><label for="claim_timeout"><?php esc_html_e( 'Claim timeout (seconds)', 'studiou-wc-mail-queue' ); ?></label></th>
  103. <td>
  104. <input type="number" min="60" max="86400" step="1" id="claim_timeout" name="claim_timeout" value="<?php echo esc_attr( $wcmq_settings['claim_timeout'] ); ?>" class="small-text" />
  105. <p class="description"><?php esc_html_e( 'How long before a mail stuck "sending" is assumed dead and retried. Keep it well above PHP\'s max_execution_time — too short and a slow send is retried while still in progress, delivering twice.', 'studiou-wc-mail-queue' ); ?></p>
  106. </td>
  107. </tr>
  108. </table>
  109. <h2><?php esc_html_e( 'Debug', 'studiou-wc-mail-queue' ); ?></h2>
  110. <table class="form-table" role="presentation">
  111. <tr>
  112. <th scope="row"><?php esc_html_e( 'Verbose logging', 'studiou-wc-mail-queue' ); ?></th>
  113. <td>
  114. <label>
  115. <input type="checkbox" name="debug" value="1" <?php checked( ! empty( $wcmq_settings['debug'] ) ); ?> />
  116. <?php esc_html_e( 'Record debug-level entries in the log and the PHP error log.', 'studiou-wc-mail-queue' ); ?>
  117. </label>
  118. </td>
  119. </tr>
  120. </table>
  121. <?php submit_button( __( 'Save settings', 'studiou-wc-mail-queue' ) ); ?>
  122. </form>