In my (admin) plugin I want to display a message using admin_notices action on successful sending of mail. Currently it is not displaying. I know this has something to do with the order of events, but I cannot figure out how to structure it so that the message displays.

Currently I’m adding the admin_notices action from within an init action callback. I’m not sure if this is allowed and therefore this may be the issue. However, if I add it to the __construct method, how can I get it to know that the mail has been sent?

Currently my Send_mail class looks something like:

class Send_mail {
    public function __construct() {
        add_action('init', array($this, 'send_mail'), 30 );
    }
    public function send_mail() {
        // wp_mail() functionality
        // returns true on successful send
        if ($mail_sent == true) {
            add_action('admin_notices', array($this, 'show_admin_notice') );
        }
    }
    public function show_admin_notice() {
        // output admin notice html
    }
}

Read more here: Hook into admin_notices after sending mail


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , ,

Wordpress related questions and answers: