Duplicate Cron Jobs Using wp_next_scheduled / wp_schedule_event

Ok, well I believe that I have things working correctly. I’d be curious if anyone has any more insights, but I believe what was happening:

  • I was calling my class incorrectly
  • I was referencing a class function in wp_next_scheduled and wp_schedule_event when I should have been referencing a callback/hook.

My revised code (which has been tested and I can confirm works).


define( 'MY_CRON_FILE', __FILE__ );

class MY_Cron_Manager {

    /**
    * Hook in methods.
    */
    public static function init() {

        register_activation_hook( MY_CRON_FILE, array(__CLASS__, 'my_schedule_cron_jobs' ));
        add_action( 'my_cron_job_event_func', array( __CLASS__, 'my_cron_job_func' )); //

    }

    /**
     * Schedule cron Jobs
     */
    public static function my_schedule_cron_jobs() {

        if (! wp_next_scheduled ( 'my_cron_job_event_func' )) {
            wp_schedule_event(time(), 'twicedaily', 'my_cron_job_event_func');
        };

    }

    /**
     * My Function
     */
    public static function my_cron_job_func() {

        // Do Stuff

    }

}

MY_Cron_Manager::init();

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)