mercredi 30 mars 2016

wordpress schedule event not firing in set time

In wordpress I am creating a plugin where I am sending email to users. For that I am using wordpress cron job. So basically what it will do is just send emails to users in every hour. So my code looks like this

    public function __construct() {
        add_action('init', array( $this, 'send_emails_to_users') );  
      add_action('cliv_recurring_cron_job', array( $this, 'send_email') );
    }

    public function send_emails_to_users() {
        if(!wp_next_scheduled('cliv_recurring_cron_job')) {
          wp_schedule_event (time(), 'hourly', 'cliv_recurring_cron_job');
        }
    }

public function send_email() {
    //send email code goes here
}

Here everything looks good but it does not sends the email.

If I make my code like this

public function __construct() {
    add_action('head', array( $this, 'send_email') );  
}

Then it sends the email. But the problem is here it sends the email on every time the page loads or when user visits the site. That's why I want to use wp_schedule_event to make email in every hour. So can someone tell me how to resolve this issue. Any suggestion or help will be really appreciable.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire