This commit is contained in:
Javier Casares 2026-02-18 15:24:59 +00:00
commit 0ece5f3a6d
16 changed files with 2342 additions and 785 deletions

View file

@ -31,9 +31,8 @@ class Plugin extends \NewsletterMailerAddon {
* @var array<string, mixed>
*/
private static $defaults = array(
'enabled' => false,
'batch_size' => 10,
'max_per_connection' => 50,
'enabled' => false,
'batch_size' => 10,
);
/**
@ -115,13 +114,27 @@ class Plugin extends \NewsletterMailerAddon {
public function init() {
parent::init();
// Load required classes.
require_once ROBOTSTXT_SMTP_NEWSLETTER_PATH . 'includes/class-queue.php';
require_once ROBOTSTXT_SMTP_NEWSLETTER_PATH . 'includes/class-statistics.php';
require_once ROBOTSTXT_SMTP_NEWSLETTER_PATH . 'includes/class-email-message.php';
// Initialize database tables.
Queue::get_instance();
Statistics::get_instance();
// Load text domain.
add_action( 'init', array( $this, 'load_textdomain' ) );
// Register settings (but not menu - parent handles that).
// Register admin pages.
if ( is_admin() ) {
require_once ROBOTSTXT_SMTP_NEWSLETTER_PATH . 'admin/class-settings-page.php';
require_once ROBOTSTXT_SMTP_NEWSLETTER_PATH . 'admin/class-emails-list-page.php';
require_once ROBOTSTXT_SMTP_NEWSLETTER_PATH . 'admin/class-statistics-page.php';
add_action( 'admin_init', array( 'Robotstxt_SMTP_Newsletter\Admin\Settings_Page', 'register_settings_static' ) );
add_action( 'admin_menu', array( 'Robotstxt_SMTP_Newsletter\Admin\Emails_List_Page', 'register' ) );
add_action( 'admin_menu', array( 'Robotstxt_SMTP_Newsletter\Admin\Statistics_Page', 'register' ) );
}
}
@ -147,6 +160,11 @@ class Plugin extends \NewsletterMailerAddon {
* @return \NewsletterMailer
*/
public function get_mailer() {
// Load required classes.
require_once ROBOTSTXT_SMTP_NEWSLETTER_PATH . 'includes/class-queue.php';
require_once ROBOTSTXT_SMTP_NEWSLETTER_PATH . 'includes/class-statistics.php';
require_once ROBOTSTXT_SMTP_NEWSLETTER_PATH . 'includes/class-email-message.php';
// Get our settings and map to Newsletter's expected format.
$settings = $this->get_settings();
$smtp_settings = $this->get_smtp_settings();
@ -156,9 +174,8 @@ class Plugin extends \NewsletterMailerAddon {
// Newsletter expects 'turbo' for batch_size and 'speed' for emails/hour.
$mailer_options = array(
'turbo' => $settings['batch_size'] ?? 10,
'speed' => $speed,
'max_per_connection' => $settings['max_per_connection'] ?? 50,
'turbo' => $settings['batch_size'] ?? 10,
'speed' => $speed,
);
// Detect if Amazon SES is active.
@ -243,4 +260,29 @@ class Plugin extends \NewsletterMailerAddon {
return $settings;
}
/**
* Plugin activation hook.
*
* Creates database tables and migrates settings.
*
* @return void
*/
public static function activation_hook() {
// Load required classes.
require_once ROBOTSTXT_SMTP_NEWSLETTER_PATH . 'includes/class-queue.php';
require_once ROBOTSTXT_SMTP_NEWSLETTER_PATH . 'includes/class-statistics.php';
require_once ROBOTSTXT_SMTP_NEWSLETTER_PATH . 'includes/class-email-message.php';
// Tables are created automatically via __construct().
Queue::get_instance();
Statistics::get_instance();
// Migrate settings: remove deprecated max_per_connection.
$options = get_option( 'robotstxt_smtp_newsletter_options', array() );
if ( isset( $options['max_per_connection'] ) ) {
unset( $options['max_per_connection'] );
update_option( 'robotstxt_smtp_newsletter_options', $options );
}
}
}