diff --git a/admin/class-settings-page.php b/admin/class-settings-page.php index 3a242ed..66f35dc 100644 --- a/admin/class-settings-page.php +++ b/admin/class-settings-page.php @@ -487,20 +487,52 @@ class Settings_Page { */ public function render_worker_section() { $worker_path = ROBOTSTXT_SMTP_NEWSLETTER_PATH . 'worker.php'; + $is_multisite = is_multisite(); + $site_url = get_site_url(); ?>

-

- - php 10 "w1" - + +
+

+ + +

+
-

- - seq 1 10 | xargs -P10 -I{} php 10 "w{}" - +

+ + php 10 "w1" --url="" + + +

+ + seq 1 10 | xargs -P10 -I{} php 10 "w{}" --url="" + + +

+ + ' . esc_html( $site_url ) . '' + ); + ?> +

+ +

+ + php 10 "w1" + + +

+ + seq 1 10 | xargs -P10 -I{} php 10 "w{}" + +

diff --git a/changelog.txt b/changelog.txt index fe024fc..b49f2d2 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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 = **Major Update: Queue-Based Architecture** diff --git a/includes/class-amazonses-mailer.php b/includes/class-amazonses-mailer.php index de529c4..1ec68af 100644 --- a/includes/class-amazonses-mailer.php +++ b/includes/class-amazonses-mailer.php @@ -27,6 +27,13 @@ class AmazonSES_Mailer extends \NewsletterMailer { */ protected $batch_size = 50; + /** + * Public batch property that Newsletter reads directly. + * + * @var int + */ + public $batch = 50; + /** * Constructor. * @@ -38,6 +45,7 @@ class AmazonSES_Mailer extends \NewsletterMailer { // Configure batch_size from turbo (standard Newsletter pattern). if ( ! empty( $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; } + /** + * 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. * diff --git a/includes/class-smtp-mailer.php b/includes/class-smtp-mailer.php index cb25940..9bd55a1 100644 --- a/includes/class-smtp-mailer.php +++ b/includes/class-smtp-mailer.php @@ -25,6 +25,13 @@ class SMTP_Mailer extends \NewsletterMailer { */ protected $batch_size = 10; + /** + * Public batch property that Newsletter reads directly. + * + * @var int + */ + public $batch = 10; + /** * Constructor. * @@ -36,6 +43,7 @@ class SMTP_Mailer extends \NewsletterMailer { // Configure batch_size from turbo (standard Newsletter pattern). if ( ! empty( $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; } + /** + * 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. * diff --git a/readme.txt b/readme.txt index f65c053..8af6fc1 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: newsletter, smtp, email, bulk, queue, worker, amazonses, statistics Requires at least: 4.7 Tested up to: 6.9 Requires PHP: 7.2 -Stable tag: 2.2.0 +Stable tag: 2.2.2 License: GPLv2 or later 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):** 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"` -For parallel processing (10 workers): - +Parallel processing (10 workers): `* * * * * 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 = @@ -136,6 +141,35 @@ Yes. The plugin integrates with ROBOTSTXT SMTP rate limiting system to ensure yo == 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 = * Initial release * SMTPKeepAlive support for SMTP @@ -146,5 +180,14 @@ Yes. The plugin integrates with ROBOTSTXT SMTP rate limiting system to ensure yo == 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 = Initial release of SMTP (by ROBOTSTXT) Newsletter. diff --git a/robotstxt-smtp-newsletter.php b/robotstxt-smtp-newsletter.php index e69ba2b..4b47c2e 100644 --- a/robotstxt-smtp-newsletter.php +++ b/robotstxt-smtp-newsletter.php @@ -3,7 +3,7 @@ * Plugin Name: Newsletter - SMTP (by ROBOTSTXT) * 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. - * Version: 2.2.0 + * Version: 2.2.2 * Requires at least: 4.7 * Requires PHP: 7.2 * Security: robotstxt@robotstxt.es @@ -25,7 +25,7 @@ if ( ! defined( 'ABSPATH' ) ) { } // 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_PATH', plugin_dir_path( __FILE__ ) ); define( 'ROBOTSTXT_SMTP_NEWSLETTER_URL', plugin_dir_url( __FILE__ ) ); diff --git a/update.json b/update.json index 192e864..ad0107c 100644 --- a/update.json +++ b/update.json @@ -1,19 +1,19 @@ { "name": "Newsletter - SMTP (by ROBOTSTXT)", "slug": "robotstxt-smtp-newsletter", - "version": "2.2.0", + "version": "2.2.2", "author": "ROBOTSTXT", "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", "tested": "6.9", "requires_php": "7.2", "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.", - "changelog": "

2.2.0 - 2026-02-16

2.1.0 - 2026-02-09

2.0.1 - 2026-01-29

2.0.0 - 2026-01-29

1.0.0 - 2026-01-29

", + "changelog": "

2.2.2 - 2026-02-16

2.2.1 - 2026-02-16

2.2.0 - 2026-02-16

2.1.0 - 2026-02-09

2.0.1 - 2026-01-29

2.0.0 - 2026-01-29

1.0.0 - 2026-01-29

", "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.", - "changelog": "

2.2.0 - 2026-02-16

" + "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": "

2.2.2 - 2026-02-16

2.2.1 - 2026-02-16

2.2.0 - 2026-02-16

" }, "banners": { "low": "", diff --git a/worker.php b/worker.php index de14776..81eaf1f 100644 --- a/worker.php +++ b/worker.php @@ -8,9 +8,11 @@ * This script runs as a standalone CLI process, independent of WordPress cron. * It loads WordPress with DOING_CRON defined to prevent triggering actual cron. * - * Usage: php worker.php + * Usage: php worker.php [--url=] * 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 MultiSite: seq 1 10 | xargs -P10 -I{} php worker.php 10 "w{}" --url="https://example.com" * * @package ROBOTSTXT_SMTP_Newsletter * @since 2.2.0 @@ -24,14 +26,41 @@ if ( php_sapi_name() !== 'cli' ) { // Parse command-line arguments. if ( $argc < 3 ) { - fwrite( STDERR, "Usage: php worker.php \n" ); + fwrite( STDERR, "Usage: php worker.php [--url=]\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 ); } $batch_size = max( 1, (int) $argv[1] ); $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. define( 'DOING_CRON', true );