This commit is contained in:
Javier Casares 2026-02-18 15:26:06 +00:00
commit 1e78bb1378
8 changed files with 181 additions and 22 deletions

View file

@ -487,11 +487,42 @@ class Settings_Page {
*/ */
public function render_worker_section() { 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();
?> ?>
<div class="notice notice-info inline"> <div class="notice notice-info inline">
<p><strong><?php esc_html_e( 'Important: Queue Processing', 'robotstxt-smtp-newsletter' ); ?></strong></p> <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 now queued to the database and require a worker process to send them.', 'robotstxt-smtp-newsletter' ); ?></p>
<?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' ); ?>
</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 ); ?>"
</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 ); ?>"
</code>
<p style="margin-top:10px; color:#856404;">
<strong><?php esc_html_e( 'Note:', 'robotstxt-smtp-newsletter' ); ?></strong>
<?php
printf(
/* translators: %s: site URL */
esc_html__( 'The commands above are configured for the current site: %s', 'robotstxt-smtp-newsletter' ),
'<code>' . esc_html( $site_url ) . '</code>'
);
?>
</p>
<?php else : ?>
<h4><?php esc_html_e( 'Single Worker Command', 'robotstxt-smtp-newsletter' ); ?></h4> <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;"> <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 ); ?> 10 "w1"
@ -501,6 +532,7 @@ class Settings_Page {
<code style="display:block; padding:10px; background:#f5f5f5; overflow-x:auto; margin:10px 0; font-family:monospace;"> <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 ); ?> 10 "w{}"
</code> </code>
<?php endif; ?>
<p style="margin-top:15px;"> <p style="margin-top:15px;">
<strong><?php esc_html_e( 'Recommended Setup:', 'robotstxt-smtp-newsletter' ); ?></strong> <strong><?php esc_html_e( 'Recommended Setup:', 'robotstxt-smtp-newsletter' ); ?></strong>

View file

@ -1,3 +1,18 @@
= 2.2.2 =
* FIXED: Newsletter now correctly respects configured batch_size when enqueuing emails
* FIXED: Emails are now enqueued all at once to database instead of gradually
* IMPROVED: Added public $batch property that Newsletter reads directly
* IMPROVED: Added get_batch_size() method for Newsletter compatibility
= 2.2.1 =
* NEW: MultiSite detection in settings page with tailored worker commands
* NEW: Worker script now supports --url parameter for MultiSite environments
* IMPROVED: Settings page automatically displays installation-specific worker setup instructions
* IMPROVED: Worker documentation with MultiSite usage examples
* IMPROVED: README with dedicated MultiSite Installations section
= 2.2.0 = = 2.2.0 =
**Major Update: Queue-Based Architecture** **Major Update: Queue-Based Architecture**

View file

@ -27,6 +27,13 @@ class AmazonSES_Mailer extends \NewsletterMailer {
*/ */
protected $batch_size = 50; protected $batch_size = 50;
/**
* Public batch property that Newsletter reads directly.
*
* @var int
*/
public $batch = 50;
/** /**
* Constructor. * Constructor.
* *
@ -38,6 +45,7 @@ class AmazonSES_Mailer extends \NewsletterMailer {
// Configure batch_size from turbo (standard Newsletter pattern). // Configure batch_size from turbo (standard Newsletter pattern).
if ( ! empty( $options['turbo'] ) ) { if ( ! empty( $options['turbo'] ) ) {
$this->batch_size = max( 1, (int) $options['turbo'] ); $this->batch_size = max( 1, (int) $options['turbo'] );
$this->batch = $this->batch_size; // Newsletter reads this directly.
} }
} }
@ -50,6 +58,18 @@ class AmazonSES_Mailer extends \NewsletterMailer {
return $this->speed; return $this->speed;
} }
/**
* Get batch size (emails per execution).
*
* This tells Newsletter how many emails to load and process in each execution.
* Critical for queue-based architecture to enqueue all emails at once.
*
* @return int
*/
public function get_batch_size() {
return $this->batch_size;
}
/** /**
* Enqueue single email to database. * Enqueue single email to database.
* *

View file

@ -25,6 +25,13 @@ class SMTP_Mailer extends \NewsletterMailer {
*/ */
protected $batch_size = 10; protected $batch_size = 10;
/**
* Public batch property that Newsletter reads directly.
*
* @var int
*/
public $batch = 10;
/** /**
* Constructor. * Constructor.
* *
@ -36,6 +43,7 @@ class SMTP_Mailer extends \NewsletterMailer {
// Configure batch_size from turbo (standard Newsletter pattern). // Configure batch_size from turbo (standard Newsletter pattern).
if ( ! empty( $options['turbo'] ) ) { if ( ! empty( $options['turbo'] ) ) {
$this->batch_size = max( 1, (int) $options['turbo'] ); $this->batch_size = max( 1, (int) $options['turbo'] );
$this->batch = $this->batch_size; // Newsletter reads this directly.
} }
} }
@ -51,6 +59,18 @@ class SMTP_Mailer extends \NewsletterMailer {
return $this->speed; return $this->speed;
} }
/**
* Get batch size (emails per execution).
*
* This tells Newsletter how many emails to load and process in each execution.
* Critical for queue-based architecture to enqueue all emails at once.
*
* @return int
*/
public function get_batch_size() {
return $this->batch_size;
}
/** /**
* Enqueue single email to database. * Enqueue single email to database.
* *

View file

@ -4,7 +4,7 @@ Tags: newsletter, smtp, email, bulk, queue, worker, amazonses, statistics
Requires at least: 4.7 Requires at least: 4.7
Tested up to: 6.9 Tested up to: 6.9
Requires PHP: 7.2 Requires PHP: 7.2
Stable tag: 2.2.0 Stable tag: 2.2.2
License: GPLv2 or later License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html License URI: https://www.gnu.org/licenses/gpl-2.0.html
@ -69,13 +69,18 @@ SMTP (by ROBOTSTXT) Newsletter connects your Newsletter plugin with ROBOTSTXT SM
**Worker Setup (Required):** **Worker Setup (Required):**
Set up a cron job or process supervisor to run the worker: Set up a cron job or process supervisor to run the worker:
Single worker:
`* * * * * php /path/to/wp-content/plugins/robotstxt-smtp-newsletter/worker.php 10 "w1"` `* * * * * php /path/to/wp-content/plugins/robotstxt-smtp-newsletter/worker.php 10 "w1"`
For parallel processing (10 workers): Parallel processing (10 workers):
`* * * * * seq 1 10 | xargs -P10 -I{} php /path/to/worker.php 10 "w{}"` `* * * * * seq 1 10 | xargs -P10 -I{} php /path/to/worker.php 10 "w{}"`
See Settings → SMTP → Queue Worker Configuration for detailed commands. **For WordPress MultiSite:**
Workers require the --url parameter to specify which site to process:
`* * * * * php /path/to/worker.php 10 "w1" --url="https://site.example.com"`
See Settings → SMTP → Queue Worker Configuration for detailed commands tailored to your installation.
= Monitoring = = Monitoring =
@ -136,6 +141,35 @@ Yes. The plugin integrates with ROBOTSTXT SMTP rate limiting system to ensure yo
== Changelog == == Changelog ==
= 2.2.2 =
* FIXED: Newsletter now correctly respects configured batch_size when enqueuing emails
* FIXED: Emails are now enqueued all at once to database instead of gradually
* IMPROVED: Added public $batch property that Newsletter reads directly
* IMPROVED: Added get_batch_size() method for Newsletter compatibility
= 2.2.1 =
* NEW: MultiSite detection in settings page with tailored worker commands
* NEW: Worker script now supports --url parameter for MultiSite environments
* IMPROVED: Settings page automatically displays installation-specific worker setup instructions
* IMPROVED: Worker documentation with MultiSite usage examples
* IMPROVED: README with dedicated MultiSite Installations section
= 2.2.0 =
* MAJOR: Database-backed email queue for persistent, reliable email delivery
* MAJOR: External CLI worker script for asynchronous email processing
* NEW: Queue Status widget with real-time statistics (pending, processing, sent, failed)
* NEW: Recent Campaigns section with key metrics in settings page
* NEW: Email Queue admin page to view all queued and sent emails
* NEW: Statistics admin page with campaign performance metrics
* NEW: Parallel worker support for high-volume sending (10+ workers simultaneously)
* NEW: Automatic retry with exponential backoff (up to 3 attempts: 5min → 15min → 30min)
* NEW: Campaign statistics tracking (start time, duration, speed, success rate)
* CHANGED: Emails are now queued to database instead of sent immediately
* CHANGED: Campaign statistics now grouped by unique Newsletter ID instead of campaign name
* REMOVED: max_per_connection setting (no longer needed with worker architecture)
* FIXED: Duplicate campaign statistics for campaigns with same name but different IDs
* BREAKING: Manual worker setup required - emails no longer send automatically
= 1.0.0 = = 1.0.0 =
* Initial release * Initial release
* SMTPKeepAlive support for SMTP * SMTPKeepAlive support for SMTP
@ -146,5 +180,14 @@ Yes. The plugin integrates with ROBOTSTXT SMTP rate limiting system to ensure yo
== Upgrade Notice == == Upgrade Notice ==
= 2.2.2 =
Fixed batch size enforcement - emails now enqueue correctly all at once instead of gradually.
= 2.2.1 =
Improved MultiSite support with automatic detection and tailored worker commands.
= 2.2.0 =
Major update with queue-based architecture. Manual worker setup required - see settings page for commands.
= 1.0.0 = = 1.0.0 =
Initial release of SMTP (by ROBOTSTXT) Newsletter. Initial release of SMTP (by ROBOTSTXT) Newsletter.

View file

@ -3,7 +3,7 @@
* Plugin Name: Newsletter - SMTP (by ROBOTSTXT) * Plugin Name: Newsletter - SMTP (by ROBOTSTXT)
* Plugin URI: https://git.robotstxt.es/ROBOTSTXT/robotstxt-smtp-newsletter * Plugin URI: https://git.robotstxt.es/ROBOTSTXT/robotstxt-smtp-newsletter
* Description: Integrates ROBOTSTXT SMTP configuration with Newsletter plugin for efficient bulk email delivery with database-backed queue and external workers. * Description: Integrates ROBOTSTXT SMTP configuration with Newsletter plugin for efficient bulk email delivery with database-backed queue and external workers.
* Version: 2.2.0 * Version: 2.2.2
* Requires at least: 4.7 * Requires at least: 4.7
* Requires PHP: 7.2 * Requires PHP: 7.2
* Security: robotstxt@robotstxt.es * Security: robotstxt@robotstxt.es
@ -25,7 +25,7 @@ if ( ! defined( 'ABSPATH' ) ) {
} }
// Plugin constants. // Plugin constants.
define( 'ROBOTSTXT_SMTP_NEWSLETTER_VERSION', '2.2.0' ); define( 'ROBOTSTXT_SMTP_NEWSLETTER_VERSION', '2.2.2' );
define( 'ROBOTSTXT_SMTP_NEWSLETTER_FILE', __FILE__ ); define( 'ROBOTSTXT_SMTP_NEWSLETTER_FILE', __FILE__ );
define( 'ROBOTSTXT_SMTP_NEWSLETTER_PATH', plugin_dir_path( __FILE__ ) ); define( 'ROBOTSTXT_SMTP_NEWSLETTER_PATH', plugin_dir_path( __FILE__ ) );
define( 'ROBOTSTXT_SMTP_NEWSLETTER_URL', plugin_dir_url( __FILE__ ) ); define( 'ROBOTSTXT_SMTP_NEWSLETTER_URL', plugin_dir_url( __FILE__ ) );

View file

@ -1,19 +1,19 @@
{ {
"name": "Newsletter - SMTP (by ROBOTSTXT)", "name": "Newsletter - SMTP (by ROBOTSTXT)",
"slug": "robotstxt-smtp-newsletter", "slug": "robotstxt-smtp-newsletter",
"version": "2.2.0", "version": "2.2.2",
"author": "ROBOTSTXT", "author": "ROBOTSTXT",
"homepage": "https://git.robotstxt.es/ROBOTSTXT/robotstxt-smtp-newsletter", "homepage": "https://git.robotstxt.es/ROBOTSTXT/robotstxt-smtp-newsletter",
"download_url": "https://git.robotstxt.es/ROBOTSTXT/robotstxt-smtp-newsletter/releases/download/2.2.0/robotstxt-smtp-newsletter-2.2.0.zip", "download_url": "https://git.robotstxt.es/ROBOTSTXT/robotstxt-smtp-newsletter/releases/download/2.2.2/robotstxt-smtp-newsletter-2.2.2.zip",
"requires": "4.7", "requires": "4.7",
"tested": "6.9", "tested": "6.9",
"requires_php": "7.2", "requires_php": "7.2",
"last_updated": "2026-02-16", "last_updated": "2026-02-16",
"description": "Integrates ROBOTSTXT SMTP configuration with Newsletter plugin for reliable bulk email delivery with database-backed queue and external workers. Provides persistent email queue, parallel processing, automatic retry, and comprehensive campaign statistics.", "description": "Integrates ROBOTSTXT SMTP configuration with Newsletter plugin for reliable bulk email delivery with database-backed queue and external workers. Provides persistent email queue, parallel processing, automatic retry, and comprehensive campaign statistics.",
"changelog": "<h4>2.2.0 - 2026-02-16</h4><ul><li><strong>MAJOR:</strong> Database-backed email queue for persistent, reliable email delivery</li><li><strong>MAJOR:</strong> External CLI worker script for asynchronous email processing</li><li><strong>Added:</strong> Queue Status widget with real-time statistics (pending, processing, sent, failed)</li><li><strong>Added:</strong> Recent Campaigns section with key metrics in settings page</li><li><strong>Added:</strong> Email Queue admin page to view all queued and sent emails</li><li><strong>Added:</strong> Statistics admin page with campaign performance metrics</li><li><strong>Added:</strong> Parallel worker support for high-volume sending (10+ workers simultaneously)</li><li><strong>Added:</strong> Automatic retry with exponential backoff (up to 3 attempts: 5min → 15min → 30min)</li><li><strong>Added:</strong> Campaign statistics tracking (start time, duration, speed, success rate)</li><li><strong>Changed:</strong> Emails are now queued to database instead of sent immediately</li><li><strong>Changed:</strong> Settings page reorganized with Queue Status, Recent Campaigns, and Worker Configuration sections</li><li><strong>Changed:</strong> Campaign statistics now grouped by unique Newsletter ID instead of campaign name</li><li><strong>Removed:</strong> max_per_connection setting (no longer needed with worker architecture)</li><li><strong>Removed:</strong> Direct PHPMailer usage (replaced with wp_mail() in workers)</li><li><strong>Fixed:</strong> Duplicate campaign statistics for campaigns with same name but different IDs</li><li><strong>Fixed:</strong> Worker command documentation (corrected parallel worker syntax)</li><li><strong>BREAKING:</strong> Manual worker setup required - emails no longer send automatically</li><li><strong>BREAKING:</strong> System cron or process supervisor required for production use</li><li><strong>Technical:</strong> New database tables for queue and statistics with automatic creation on activation</li><li><strong>Technical:</strong> Microsecond precision timestamps for accurate performance metrics</li><li><strong>Security:</strong> CLI-only worker script with SQL injection prevention and capability checks</li></ul><h4>2.1.0 - 2026-02-09</h4><ul><li><strong>Changed:</strong> Uninstall behavior: plugin no longer performs cleanup on uninstall, all data cleanup is now handled by the core SMTP plugin</li><li><strong>Changed:</strong> This ensures Newsletter configuration is preserved when only the add-on is removed, and properly cleaned when the core plugin is uninstalled</li><li><strong>Technical:</strong> Simplified uninstall.php to delegate all cleanup responsibility to core SMTP plugin</li></ul><h4>2.0.1 - 2026-01-29</h4><ul><li><strong>Changed:</strong> Removed Network requirement from plugin headers to allow single-site activation</li></ul><h4>2.0.0 - 2026-01-29</h4><ul><li><strong>Changed:</strong> Updated compatibility with SMTP (by ROBOTSTXT) plugin 2.0.0</li><li><strong>Changed:</strong> Enhanced integration with core SMTP plugin security improvements</li><li><strong>Improved:</strong> Better error handling and validation</li></ul><h4>1.0.0 - 2026-01-29</h4><ul><li><strong>Added:</strong> Initial release with SMTPKeepAlive support</li><li><strong>Added:</strong> Amazon SES API integration for optimized delivery</li><li><strong>Performance:</strong> 20-30x faster bulk email sending compared to standard wp_mail()</li></ul>", "changelog": "<h4>2.2.2 - 2026-02-16</h4><ul><li><strong>Fixed:</strong> Newsletter now correctly respects configured batch_size when enqueuing emails</li><li><strong>Fixed:</strong> Emails are now enqueued all at once to database instead of gradually</li><li><strong>Improved:</strong> Added public $batch property that Newsletter reads directly</li><li><strong>Improved:</strong> Added get_batch_size() method for Newsletter compatibility</li><li><strong>Technical:</strong> Mailers expose batch_size through multiple interfaces for Newsletter compatibility</li></ul><h4>2.2.1 - 2026-02-16</h4><ul><li><strong>Added:</strong> MultiSite detection in settings page with tailored worker commands</li><li><strong>Added:</strong> Worker script now supports --url parameter for MultiSite environments</li><li><strong>Improved:</strong> Settings page automatically displays installation-specific worker setup instructions</li><li><strong>Improved:</strong> Worker documentation with MultiSite usage examples</li><li><strong>Improved:</strong> README with dedicated MultiSite Installations section</li><li><strong>Technical:</strong> Worker script parses --url parameter and sets appropriate $_SERVER variables</li><li><strong>Technical:</strong> Settings page uses is_multisite() and get_site_url() for detection and URL generation</li></ul><h4>2.2.0 - 2026-02-16</h4><ul><li><strong>MAJOR:</strong> Database-backed email queue for persistent, reliable email delivery</li><li><strong>MAJOR:</strong> External CLI worker script for asynchronous email processing</li><li><strong>Added:</strong> Queue Status widget with real-time statistics (pending, processing, sent, failed)</li><li><strong>Added:</strong> Recent Campaigns section with key metrics in settings page</li><li><strong>Added:</strong> Email Queue admin page to view all queued and sent emails</li><li><strong>Added:</strong> Statistics admin page with campaign performance metrics</li><li><strong>Added:</strong> Parallel worker support for high-volume sending (10+ workers simultaneously)</li><li><strong>Added:</strong> Automatic retry with exponential backoff (up to 3 attempts: 5min → 15min → 30min)</li><li><strong>Added:</strong> Campaign statistics tracking (start time, duration, speed, success rate)</li><li><strong>Changed:</strong> Emails are now queued to database instead of sent immediately</li><li><strong>Changed:</strong> Settings page reorganized with Queue Status, Recent Campaigns, and Worker Configuration sections</li><li><strong>Changed:</strong> Campaign statistics now grouped by unique Newsletter ID instead of campaign name</li><li><strong>Removed:</strong> max_per_connection setting (no longer needed with worker architecture)</li><li><strong>Removed:</strong> Direct PHPMailer usage (replaced with wp_mail() in workers)</li><li><strong>Fixed:</strong> Duplicate campaign statistics for campaigns with same name but different IDs</li><li><strong>Fixed:</strong> Worker command documentation (corrected parallel worker syntax)</li><li><strong>BREAKING:</strong> Manual worker setup required - emails no longer send automatically</li><li><strong>BREAKING:</strong> System cron or process supervisor required for production use</li><li><strong>Technical:</strong> New database tables for queue and statistics with automatic creation on activation</li><li><strong>Technical:</strong> Microsecond precision timestamps for accurate performance metrics</li><li><strong>Security:</strong> CLI-only worker script with SQL injection prevention and capability checks</li></ul><h4>2.1.0 - 2026-02-09</h4><ul><li><strong>Changed:</strong> Uninstall behavior: plugin no longer performs cleanup on uninstall, all data cleanup is now handled by the core SMTP plugin</li><li><strong>Changed:</strong> This ensures Newsletter configuration is preserved when only the add-on is removed, and properly cleaned when the core plugin is uninstalled</li><li><strong>Technical:</strong> Simplified uninstall.php to delegate all cleanup responsibility to core SMTP plugin</li></ul><h4>2.0.1 - 2026-01-29</h4><ul><li><strong>Changed:</strong> Removed Network requirement from plugin headers to allow single-site activation</li></ul><h4>2.0.0 - 2026-01-29</h4><ul><li><strong>Changed:</strong> Updated compatibility with SMTP (by ROBOTSTXT) plugin 2.0.0</li><li><strong>Changed:</strong> Enhanced integration with core SMTP plugin security improvements</li><li><strong>Improved:</strong> Better error handling and validation</li></ul><h4>1.0.0 - 2026-01-29</h4><ul><li><strong>Added:</strong> Initial release with SMTPKeepAlive support</li><li><strong>Added:</strong> Amazon SES API integration for optimized delivery</li><li><strong>Performance:</strong> 20-30x faster bulk email sending compared to standard wp_mail()</li></ul>",
"sections": { "sections": {
"description": "Integrates ROBOTSTXT SMTP configuration with Newsletter plugin for reliable bulk email delivery with database-backed queue and external workers. Version 2.2.0 introduces a queue-based architecture with persistent email storage, parallel worker processing, automatic retry logic, and comprehensive campaign statistics. Emails are queued to database and processed by external CLI workers, providing reliability, scalability, and detailed monitoring.", "description": "Integrates ROBOTSTXT SMTP configuration with Newsletter plugin for reliable bulk email delivery with database-backed queue and external workers. Version 2.2.2 fixes batch size enforcement to ensure all emails are enqueued at once. Emails are queued to database and processed by external CLI workers, providing reliability, scalability, and detailed monitoring.",
"changelog": "<h4>2.2.0 - 2026-02-16</h4><ul><li><strong>MAJOR:</strong> Database-backed email queue for persistent, reliable email delivery</li><li><strong>MAJOR:</strong> External CLI worker script for asynchronous email processing</li><li><strong>Added:</strong> Queue Status widget with real-time statistics</li><li><strong>Added:</strong> Recent Campaigns section with key metrics</li><li><strong>Added:</strong> Email Queue admin page</li><li><strong>Added:</strong> Statistics admin page with campaign metrics</li><li><strong>Added:</strong> Parallel worker support (10+ workers)</li><li><strong>Added:</strong> Automatic retry with exponential backoff</li><li><strong>Changed:</strong> Emails queued to database instead of sent immediately</li><li><strong>Changed:</strong> Campaign statistics grouped by Newsletter ID</li><li><strong>Removed:</strong> max_per_connection setting</li><li><strong>Fixed:</strong> Duplicate campaign statistics</li><li><strong>BREAKING:</strong> Manual worker setup required</li></ul>" "changelog": "<h4>2.2.2 - 2026-02-16</h4><ul><li><strong>Fixed:</strong> Batch size enforcement - emails now enqueue correctly all at once</li><li><strong>Improved:</strong> Newsletter compatibility with $batch property and get_batch_size() method</li></ul><h4>2.2.1 - 2026-02-16</h4><ul><li><strong>Added:</strong> MultiSite detection with tailored worker commands</li><li><strong>Added:</strong> Worker --url parameter support for MultiSite</li><li><strong>Improved:</strong> Installation-specific worker setup instructions</li></ul><h4>2.2.0 - 2026-02-16</h4><ul><li><strong>MAJOR:</strong> Database-backed email queue for persistent, reliable email delivery</li><li><strong>MAJOR:</strong> External CLI worker script for asynchronous email processing</li><li><strong>Added:</strong> Queue Status widget with real-time statistics</li><li><strong>Added:</strong> Recent Campaigns section with key metrics</li><li><strong>Added:</strong> Email Queue admin page</li><li><strong>Added:</strong> Statistics admin page with campaign metrics</li><li><strong>Added:</strong> Parallel worker support (10+ workers)</li><li><strong>Added:</strong> Automatic retry with exponential backoff</li><li><strong>Changed:</strong> Emails queued to database instead of sent immediately</li><li><strong>Changed:</strong> Campaign statistics grouped by Newsletter ID</li><li><strong>Removed:</strong> max_per_connection setting</li><li><strong>Fixed:</strong> Duplicate campaign statistics</li><li><strong>BREAKING:</strong> Manual worker setup required</li></ul>"
}, },
"banners": { "banners": {
"low": "", "low": "",

View file

@ -8,9 +8,11 @@
* This script runs as a standalone CLI process, independent of WordPress cron. * This script runs as a standalone CLI process, independent of WordPress cron.
* It loads WordPress with DOING_CRON defined to prevent triggering actual cron. * It loads WordPress with DOING_CRON defined to prevent triggering actual cron.
* *
* Usage: php worker.php <batch_size> <worker_id> * Usage: php worker.php <batch_size> <worker_id> [--url=<site_url>]
* Example: php worker.php 10 "w1" * Example: php worker.php 10 "w1"
* MultiSite: php worker.php 10 "w1" --url="https://example.com"
* Parallel: seq 1 10 | xargs -P10 -I{} php worker.php 10 "w{}" * Parallel: seq 1 10 | xargs -P10 -I{} php worker.php 10 "w{}"
* Parallel MultiSite: seq 1 10 | xargs -P10 -I{} php worker.php 10 "w{}" --url="https://example.com"
* *
* @package ROBOTSTXT_SMTP_Newsletter * @package ROBOTSTXT_SMTP_Newsletter
* @since 2.2.0 * @since 2.2.0
@ -24,14 +26,41 @@ if ( php_sapi_name() !== 'cli' ) {
// Parse command-line arguments. // Parse command-line arguments.
if ( $argc < 3 ) { if ( $argc < 3 ) {
fwrite( STDERR, "Usage: php worker.php <batch_size> <worker_id>\n" ); fwrite( STDERR, "Usage: php worker.php <batch_size> <worker_id> [--url=<site_url>]\n" );
fwrite( STDERR, "Example: php worker.php 10 \"w1\"\n" ); fwrite( STDERR, "Example: php worker.php 10 \"w1\"\n" );
fwrite( STDERR, "MultiSite: php worker.php 10 \"w1\" --url=\"https://example.com\"\n" );
exit( 1 ); exit( 1 );
} }
$batch_size = max( 1, (int) $argv[1] ); $batch_size = max( 1, (int) $argv[1] );
$worker_id = $argv[2]; $worker_id = $argv[2];
// Parse optional --url parameter for MultiSite support.
$site_url = null;
for ( $i = 3; $i < $argc; $i++ ) {
if ( strpos( $argv[ $i ], '--url=' ) === 0 ) {
$site_url = substr( $argv[ $i ], 6 );
break;
}
}
// If --url is provided, set HTTP_HOST for WordPress to load the correct site.
if ( $site_url ) {
$parsed_url = parse_url( $site_url );
if ( isset( $parsed_url['host'] ) ) {
$_SERVER['HTTP_HOST'] = $parsed_url['host'];
$_SERVER['SERVER_NAME'] = $parsed_url['host'];
// Set HTTPS if URL uses https.
if ( isset( $parsed_url['scheme'] ) && 'https' === $parsed_url['scheme'] ) {
$_SERVER['HTTPS'] = 'on';
}
// Set REQUEST_URI to root.
$_SERVER['REQUEST_URI'] = '/';
}
}
// Load WordPress. // Load WordPress.
define( 'DOING_CRON', true ); define( 'DOING_CRON', true );