This commit is contained in:
Javier Casares 2026-02-18 16:09:17 +00:00
commit 768bbfbdd2
6 changed files with 150 additions and 34 deletions

View file

@ -339,12 +339,64 @@ class Settings_Page {
*/
public function render_batch_size_field() {
$options = get_option( self::OPTION_NAME, array() );
$batch_size = $options['batch_size'] ?? 10;
$batch_size = absint( $options['batch_size'] ?? 10 );
?>
<input type="number" name="<?php echo esc_attr( self::OPTION_NAME ); ?>[batch_size]" value="<?php echo esc_attr( $batch_size ); ?>" min="1" max="10000" class="small-text">
<p class="description">
<?php esc_html_e( 'Number of emails to send in each batch. Higher values improve performance with SMTPKeepAlive.', 'robotstxt-smtp-newsletter' ); ?><br>
<?php esc_html_e( 'See calculated recommendations below based on your rate limits and cron interval.', 'robotstxt-smtp-newsletter' ); ?>
<?php esc_html_e( 'Number of emails each worker picks up and sends per cycle. Workers read this value from the database automatically — no need to specify it in the command line.', 'robotstxt-smtp-newsletter' ); ?>
</p>
<table style="margin-top:10px; border-collapse:collapse; font-size:13px;">
<thead>
<tr>
<th style="text-align:left; padding:4px 12px 4px 0; color:#666; font-weight:normal; border-bottom:1px solid #ddd;">
<?php esc_html_e( 'Workers', 'robotstxt-smtp-newsletter' ); ?>
</th>
<th style="text-align:left; padding:4px 12px 4px 0; color:#666; font-weight:normal; border-bottom:1px solid #ddd;">
<?php esc_html_e( 'Batch Size', 'robotstxt-smtp-newsletter' ); ?>
</th>
<th style="text-align:left; padding:4px 0; color:#666; font-weight:normal; border-bottom:1px solid #ddd;">
<?php esc_html_e( 'Simultaneous emails', 'robotstxt-smtp-newsletter' ); ?>
</th>
</tr>
</thead>
<tbody>
<?php
$examples = array( 1, 5, 10, 20, 50 );
foreach ( $examples as $example ) :
$simultaneous = 10 * $example;
$is_current = ( $example === $batch_size );
$row_style = $is_current ? 'background:#e8f4fd; font-weight:bold;' : '';
?>
<tr style="<?php echo esc_attr( $row_style ); ?>">
<td style="padding:3px 12px 3px 0;">10</td>
<td style="padding:3px 12px 3px 0;">
<?php echo absint( $example ); ?>
<?php if ( $is_current ) : ?>
&larr; <?php esc_html_e( 'current', 'robotstxt-smtp-newsletter' ); ?>
<?php endif; ?>
</td>
<td style="padding:3px 0;">
<strong><?php echo number_format_i18n( $simultaneous ); ?></strong>
</td>
</tr>
<?php endforeach; ?>
<?php if ( ! in_array( $batch_size, $examples, true ) && $batch_size > 0 ) : ?>
<tr style="background:#e8f4fd; font-weight:bold;">
<td style="padding:3px 12px 3px 0;">10</td>
<td style="padding:3px 12px 3px 0;">
<?php echo absint( $batch_size ); ?>
&larr; <?php esc_html_e( 'current', 'robotstxt-smtp-newsletter' ); ?>
</td>
<td style="padding:3px 0;">
<strong><?php echo number_format_i18n( 10 * $batch_size ); ?></strong>
</td>
</tr>
<?php endif; ?>
</tbody>
</table>
<p class="description" style="margin-top:8px;">
<?php esc_html_e( 'Table assumes the recommended setup of 10 parallel workers. Adjust your worker command to run more or fewer workers.', 'robotstxt-smtp-newsletter' ); ?><br>
<?php esc_html_e( 'See calculated recommendations below based on your rate limits.', 'robotstxt-smtp-newsletter' ); ?>
</p>
<?php
}
@ -486,30 +538,53 @@ class Settings_Page {
* @return void
*/
public function render_worker_section() {
$worker_path = ROBOTSTXT_SMTP_NEWSLETTER_PATH . 'worker.php';
$worker_path = ROBOTSTXT_SMTP_NEWSLETTER_PATH . 'worker.php';
$is_multisite = is_multisite();
$site_url = get_site_url();
$site_url = get_site_url();
$options = get_option( 'robotstxt_smtp_newsletter_options', array() );
$batch_size = max( 1, absint( $options['batch_size'] ?? 10 ) );
?>
<div class="notice notice-info inline">
<p><strong><?php esc_html_e( 'Important: Queue Processing', 'robotstxt-smtp-newsletter' ); ?></strong></p>
<p><?php esc_html_e( 'Newsletter emails are now queued to the database and require a worker process to send them.', 'robotstxt-smtp-newsletter' ); ?></p>
<p>
<?php esc_html_e( 'Newsletter emails are queued to the database and processed by external worker processes.', 'robotstxt-smtp-newsletter' ); ?>
<?php esc_html_e( 'Workers read the Batch Size from the database automatically — no need to pass it as a command-line argument.', 'robotstxt-smtp-newsletter' ); ?>
</p>
<table style="margin:10px 0 15px 0; border-collapse:collapse; font-size:13px;">
<tr>
<td style="padding:3px 15px 3px 0; color:#666;"><?php esc_html_e( 'Parallel workers:', 'robotstxt-smtp-newsletter' ); ?></td>
<td style="padding:3px 0;"><strong>10</strong></td>
</tr>
<tr>
<td style="padding:3px 15px 3px 0; color:#666;"><?php esc_html_e( 'Batch size (current setting):', 'robotstxt-smtp-newsletter' ); ?></td>
<td style="padding:3px 0;"><strong><?php echo absint( $batch_size ); ?></strong></td>
</tr>
<tr style="border-top:1px solid #ddd;">
<td style="padding:6px 15px 3px 0; color:#666;"><?php esc_html_e( 'Simultaneous emails:', 'robotstxt-smtp-newsletter' ); ?></td>
<td style="padding:6px 0;"><strong style="font-size:15px;"><?php echo number_format_i18n( 10 * $batch_size ); ?></strong>
<small style="color:#666; margin-left:5px;">(10 &times; <?php echo absint( $batch_size ); ?>)</small>
</td>
</tr>
</table>
<?php if ( $is_multisite ) : ?>
<div style="background:#fff3cd; border-left:4px solid #ffc107; padding:10px; margin:15px 0;">
<p style="margin:0;">
<strong><?php esc_html_e( 'MultiSite Detected:', 'robotstxt-smtp-newsletter' ); ?></strong>
<?php esc_html_e( 'This WordPress installation is running in MultiSite mode. Worker commands must include the --url parameter to specify which site to process.', 'robotstxt-smtp-newsletter' ); ?>
<?php esc_html_e( 'Worker commands must include the --url parameter to specify which site to process.', 'robotstxt-smtp-newsletter' ); ?>
</p>
</div>
<h4><?php esc_html_e( 'Single Worker Command (MultiSite)', 'robotstxt-smtp-newsletter' ); ?></h4>
<code style="display:block; padding:10px; background:#f5f5f5; overflow-x:auto; margin:10px 0; font-family:monospace;">
php <?php echo esc_html( $worker_path ); ?> 10 "w1" --url="<?php echo esc_html( $site_url ); ?>"
php <?php echo esc_html( $worker_path ); ?> "w1" --url="<?php echo esc_html( $site_url ); ?>"
</code>
<h4><?php esc_html_e( 'Parallel Processing (10 workers) - MultiSite', 'robotstxt-smtp-newsletter' ); ?></h4>
<code style="display:block; padding:10px; background:#f5f5f5; overflow-x:auto; margin:10px 0; font-family:monospace;">
seq 1 10 | xargs -P10 -I{} php <?php echo esc_html( $worker_path ); ?> 10 "w{}" --url="<?php echo esc_html( $site_url ); ?>"
seq 1 10 | xargs -P10 -I{} php <?php echo esc_html( $worker_path ); ?> "w{}" --url="<?php echo esc_html( $site_url ); ?>"
</code>
<p style="margin-top:10px; color:#856404;">
@ -525,12 +600,12 @@ class Settings_Page {
<?php else : ?>
<h4><?php esc_html_e( 'Single Worker Command', 'robotstxt-smtp-newsletter' ); ?></h4>
<code style="display:block; padding:10px; background:#f5f5f5; overflow-x:auto; margin:10px 0; font-family:monospace;">
php <?php echo esc_html( $worker_path ); ?> 10 "w1"
php <?php echo esc_html( $worker_path ); ?> "w1"
</code>
<h4><?php esc_html_e( 'Parallel Processing (10 workers)', 'robotstxt-smtp-newsletter' ); ?></h4>
<code style="display:block; padding:10px; background:#f5f5f5; overflow-x:auto; margin:10px 0; font-family:monospace;">
seq 1 10 | xargs -P10 -I{} php <?php echo esc_html( $worker_path ); ?> 10 "w{}"
seq 1 10 | xargs -P10 -I{} php <?php echo esc_html( $worker_path ); ?> "w{}"
</code>
<?php endif; ?>