Plugin does not work when sending mail from wp-cli script
-
Hello!
I noticed that this plugin does not working when sending a email from a WP-CLI script. This is the case for any custom wp-cli command that has the wp_mail function in it.
I get the following error:
Error: Call to a member function wp_mail() on null
online 53
insmtp-mailing-queue/smtp-mailing-queue.php
.I think this has something to do with global variables working slightly different in WP CLI.
I was able to fix it with these modifications:
in
smtp-mailing-queue.php
:if (!function_exists('wp_mail') && !isset($_GET['smqProcessQueue'])) { function wp_mail($to, $subject, $message, $headers = '', $attachments = array()) { $originalPluggeable = OriginalPluggeable::get_instance(); $smtpMailingQueue = SMTPMailingQueue::get_instance(__FILE__, $originalPluggeable); return $smtpMailingQueue->wp_mail($to, $subject, $message, $headers, $attachments); } }
In the
OriginalPluggeable
andSMTPMailingQueue
classes I added this field andget_instance
method:private static $instance = null;
public static function get_instance($pluginFile = null, OriginalPluggeable $originalPluggeable) { if ( null == self::$instance ) { self::$instance = new self($pluginFile, $originalPluggeable); } return self::$instance; }
public static function get_instance() { if ( null == self::$instance ) { self::$instance = new self(); } return self::$instance; }
I hope you can fix this problem using the above solution or another solution.
- The topic ‘Plugin does not work when sending mail from wp-cli script’ is closed to new replies.