• 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
    on line 53 in smtp-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 and SMTPMailingQueue classes I added this field and get_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.

    • This topic was modified 2 years, 2 months ago by Christiaan van Luik. Reason: Remove nonfunctional markdown
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Birmania

    (@birmania)

    Hi @cvl01,

    Thanks for this nice and clear bug report with code suggestion.
    Your code seems very logic but I found that we just have to explicitely globalize ‘$smtpMailingQueue’ in order for WP-CLI to find it.

    See : https://github.com/wp-cli/wp-cli/issues/4019

    I just published v1.4.6 with the associated fix.
    Waiting for your feedback, ensuring that your problem is solved.

    Yours faithfully,
    Birmania

    Thread Starter Christiaan van Luik

    (@cvl01)

    That is a nice and easy fix you did, I can confirm it works properly.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Plugin does not work when sending mail from wp-cli script’ is closed to new replies.