| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- /**
- * Settings tab.
- *
- * @package studiou-wc-mail-queue
- * @copyright 2026 QUADARAX
- * @author Dalibor Votruba <dvotruba@quadarax.com>
- * @license GPL-2.0-or-later
- */
- defined( 'ABSPATH' ) || exit;
- $wcmq_settings = Studiou_WCMQ_Settings::all();
- $wcmq_contexts = Studiou_WCMQ_Admin::available_contexts();
- $wcmq_handled = Studiou_WCMQ_Settings::handled_contexts();
- $wcmq_is_on = Studiou_WCMQ_State::is_queueing();
- $wcmq_action_url = admin_url( 'admin-post.php' );
- ?>
- <form method="post" action="<?php echo esc_url( $wcmq_action_url ); ?>" class="studiou-wcmq-toggle-form">
- <?php wp_nonce_field( Studiou_WCMQ_Admin::NONCE ); ?>
- <input type="hidden" name="action" value="studiou_wcmq_toggle_state" />
- <input type="hidden" name="wcmq_state" value="<?php echo $wcmq_is_on ? 'disabled' : 'enabled'; ?>" />
- <p>
- <button type="submit" class="button button-primary">
- <?php
- echo $wcmq_is_on
- ? esc_html__( 'Disable mail queue', 'studiou-wc-mail-queue' )
- : esc_html__( 'Enable mail queue', 'studiou-wc-mail-queue' );
- ?>
- </button>
- <span class="description">
- <?php esc_html_e( 'Disabling stops queueing new mail; anything already queued still sends at the configured rate.', 'studiou-wc-mail-queue' ); ?>
- </span>
- </p>
- </form>
- <hr />
- <form method="post" action="<?php echo esc_url( $wcmq_action_url ); ?>">
- <?php wp_nonce_field( Studiou_WCMQ_Admin::NONCE ); ?>
- <input type="hidden" name="action" value="studiou_wcmq_save_settings" />
- <h2><?php esc_html_e( 'Rate limit', 'studiou-wc-mail-queue' ); ?></h2>
- <table class="form-table" role="presentation">
- <tr>
- <th scope="row">
- <label for="rate_per_minute"><?php esc_html_e( 'Mails per minute', 'studiou-wc-mail-queue' ); ?></label>
- </th>
- <td>
- <input type="number" min="1" max="60" step="1" id="rate_per_minute" name="rate_per_minute"
- value="<?php echo esc_attr( $wcmq_settings['rate_per_minute'] ); ?>" class="small-text" />
- <p class="description">
- <?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' ); ?>
- </p>
- </td>
- </tr>
- </table>
- <h2><?php esc_html_e( 'Emails handled by the queue', 'studiou-wc-mail-queue' ); ?></h2>
- <p class="description">
- <?php esc_html_e( 'Anything not ticked here sends immediately, exactly as it does today. Never queue password resets.', 'studiou-wc-mail-queue' ); ?>
- </p>
- <fieldset class="studiou-wcmq-contexts">
- <?php foreach ( $wcmq_contexts as $wcmq_id => $wcmq_label ) : ?>
- <label>
- <input type="checkbox" name="handled_contexts[]" value="<?php echo esc_attr( $wcmq_id ); ?>"
- <?php checked( in_array( $wcmq_id, $wcmq_handled, true ) ); ?> />
- <?php echo esc_html( $wcmq_label ); ?>
- <code><?php echo esc_html( $wcmq_id ); ?></code>
- </label>
- <?php endforeach; ?>
- </fieldset>
- <h2><?php esc_html_e( 'Retention', 'studiou-wc-mail-queue' ); ?></h2>
- <p class="description">
- <?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' ); ?>
- </p>
- <table class="form-table" role="presentation">
- <tr>
- <th scope="row"><label for="retention_sent_days"><?php esc_html_e( 'Keep sent mail (days)', 'studiou-wc-mail-queue' ); ?></label></th>
- <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>
- </tr>
- <tr>
- <th scope="row"><label for="retention_failed_days"><?php esc_html_e( 'Keep failed mail (days)', 'studiou-wc-mail-queue' ); ?></label></th>
- <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>
- </tr>
- <tr>
- <th scope="row"><label for="retention_log_days"><?php esc_html_e( 'Keep log entries (days)', 'studiou-wc-mail-queue' ); ?></label></th>
- <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>
- </tr>
- </table>
- <h2><?php esc_html_e( 'Reliability', 'studiou-wc-mail-queue' ); ?></h2>
- <table class="form-table" role="presentation">
- <tr>
- <th scope="row"><label for="max_attempts"><?php esc_html_e( 'Max send attempts', 'studiou-wc-mail-queue' ); ?></label></th>
- <td>
- <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" />
- <p class="description"><?php esc_html_e( 'Completed attempts where the mail server rejected the message.', 'studiou-wc-mail-queue' ); ?></p>
- </td>
- </tr>
- <tr>
- <th scope="row"><label for="max_reclaims"><?php esc_html_e( 'Max crash recoveries', 'studiou-wc-mail-queue' ); ?></label></th>
- <td>
- <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" />
- <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>
- </td>
- </tr>
- <tr>
- <th scope="row"><label for="claim_timeout"><?php esc_html_e( 'Claim timeout (seconds)', 'studiou-wc-mail-queue' ); ?></label></th>
- <td>
- <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" />
- <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>
- </td>
- </tr>
- </table>
- <h2><?php esc_html_e( 'Debug', 'studiou-wc-mail-queue' ); ?></h2>
- <table class="form-table" role="presentation">
- <tr>
- <th scope="row"><?php esc_html_e( 'Verbose logging', 'studiou-wc-mail-queue' ); ?></th>
- <td>
- <label>
- <input type="checkbox" name="debug" value="1" <?php checked( ! empty( $wcmq_settings['debug'] ) ); ?> />
- <?php esc_html_e( 'Record debug-level entries in the log and the PHP error log.', 'studiou-wc-mail-queue' ); ?>
- </label>
- </td>
- </tr>
- </table>
- <?php submit_button( __( 'Save settings', 'studiou-wc-mail-queue' ) ); ?>
- </form>
|