Bumped by Community user
3 added 70 characters in body; edited title
source | link

How To Create A Class That Registers and Schedules Duplicate Cron Jobs Without DuplicationUsing wp_next_scheduled / wp_schedule_event

I'm working on a plugin to register and schedule various cron jobs. I am:

  • using WP Crontrol (just to see all of my cron jobs and override them if need be)
  • have a server cron job set up and have define('DISABLE_WP_CRON', true); in place

When I went into 'Cron Events' within Crontrol I saw that some functions were added literally hundreds of times. Specifically, in 'Cron Events' the function is what's getting registered/listed, not the hook. A simplified version of my code:

class My_Cron_Manager {

    /**
     * Constructor
     */
    public function __construct() {

        add_filter( 'wp', array( $this, 'my_schedule_cron_jobs' ) );
        add_action( 'my_cron_event_func', array( $this, 'my_cron_job_func' ));

    }

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

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

    }

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

        // Do Stuff

    }

}

new My_Cron_Manager();

I have a suspicion that I had an error in my code that was re-registering the function, but I'm not entirely sure. Am I utilizing wp_next_scheduled and wp_schedule_event correctly?

Can someone please let me know if my above code would be causing duplicated hook/function registration?

Thanks in advance!

How To Create A Class That Registers and Schedules Cron Jobs Without Duplication

I'm working on a plugin to register and schedule various cron jobs. I am:

  • using WP Crontrol (just to see all of my cron jobs and override them if need be)
  • have a server cron job set up and have define('DISABLE_WP_CRON', true); in place

When I went into 'Cron Events' within Crontrol I saw that some functions were added literally hundreds of times. Specifically, in 'Cron Events' the function is what's getting registered/listed, not the hook. A simplified version of my code:

class My_Cron_Manager {

    /**
     * Constructor
     */
    public function __construct() {

        add_filter( 'wp', array( $this, 'my_schedule_cron_jobs' ) );
        add_action( 'my_cron_event_func', array( $this, 'my_cron_job_func' ));

    }

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

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

    }

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

        // Do Stuff

    }

}

new My_Cron_Manager();

I have a suspicion that I had an error in my code that was re-registering the function, but I'm not entirely sure.

Can someone please let me know if my above code would be causing duplicated hook/function registration?

Thanks in advance!

Duplicate Cron Jobs Using wp_next_scheduled / wp_schedule_event

I'm working on a plugin to register and schedule various cron jobs. I am:

  • using WP Crontrol (just to see all of my cron jobs and override them if need be)
  • have a server cron job set up and have define('DISABLE_WP_CRON', true); in place

When I went into 'Cron Events' within Crontrol I saw that some functions were added literally hundreds of times. Specifically, in 'Cron Events' the function is what's getting registered/listed, not the hook. A simplified version of my code:

class My_Cron_Manager {

    /**
     * Constructor
     */
    public function __construct() {

        add_filter( 'wp', array( $this, 'my_schedule_cron_jobs' ) );
        add_action( 'my_cron_event_func', array( $this, 'my_cron_job_func' ));

    }

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

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

    }

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

        // Do Stuff

    }

}

new My_Cron_Manager();

I have a suspicion that I had an error in my code that was re-registering the function, but I'm not entirely sure. Am I utilizing wp_next_scheduled and wp_schedule_event correctly?

Can someone please let me know if my above code would be causing duplicated hook/function registration?

Thanks in advance!

2 added 23 characters in body
source | link

I'm working on a plugin to register and schedule various cron jobs. I am:

  • using WP Crontrol (just to see all of my cron jobs and override them if need be)
  • have a server cron job set up and have define('DISABLE_WP_CRON', true); in place

When I went into 'Cron Events' within Crontrol I saw that some functions were added literally hundreds of times. Specifically, in 'Cron Events' the function is what's getting registered/listed, not the hook. A simplified version of my code:

class My_Cron_Manager {

    /**
     * Constructor
     */
    public function __construct() {

        add_filter( 'wp', array( $this, 'my_schedule_cron_jobs' ) );
        add_action( 'my_cron_event_func', array( $this, 'my_cron_job_func' ));

    }

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

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

    }

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

        // Do Stuff

    }

}

new My_Cron_Manager();

I have a suspicion that I had an error in my code that was re-registering the function, but I'm not entirely sure.

Can someone please let me know if my above code would be causing duplicated hook/function registration?

Thanks in advance!

I'm working on a plugin to register and schedule various cron jobs. I am:

  • using WP Crontrol (just to see all of my cron jobs and override them if need be)
  • have a server cron job set up and have define('DISABLE_WP_CRON', true); in place

When I went into 'Cron Events' I saw that some functions were added literally hundreds of times. Specifically, in 'Cron Events' the function is what's getting registered, not the hook. A simplified version of my code:

class My_Cron_Manager {

    /**
     * Constructor
     */
    public function __construct() {

        add_filter( 'wp', array( $this, 'my_schedule_cron_jobs' ) );
        add_action( 'my_cron_event_func', array( $this, 'my_cron_job_func' ));

    }

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

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

    }

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

        // Do Stuff

    }

}

new My_Cron_Manager();

I have a suspicion that I had an error in my code that was re-registering the function, but I'm not entirely sure.

Can someone please let me know if my above code would be causing duplicated hook/function registration?

Thanks in advance!

I'm working on a plugin to register and schedule various cron jobs. I am:

  • using WP Crontrol (just to see all of my cron jobs and override them if need be)
  • have a server cron job set up and have define('DISABLE_WP_CRON', true); in place

When I went into 'Cron Events' within Crontrol I saw that some functions were added literally hundreds of times. Specifically, in 'Cron Events' the function is what's getting registered/listed, not the hook. A simplified version of my code:

class My_Cron_Manager {

    /**
     * Constructor
     */
    public function __construct() {

        add_filter( 'wp', array( $this, 'my_schedule_cron_jobs' ) );
        add_action( 'my_cron_event_func', array( $this, 'my_cron_job_func' ));

    }

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

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

    }

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

        // Do Stuff

    }

}

new My_Cron_Manager();

I have a suspicion that I had an error in my code that was re-registering the function, but I'm not entirely sure.

Can someone please let me know if my above code would be causing duplicated hook/function registration?

Thanks in advance!

1
source | link

How To Create A Class That Registers and Schedules Cron Jobs Without Duplication

I'm working on a plugin to register and schedule various cron jobs. I am:

  • using WP Crontrol (just to see all of my cron jobs and override them if need be)
  • have a server cron job set up and have define('DISABLE_WP_CRON', true); in place

When I went into 'Cron Events' I saw that some functions were added literally hundreds of times. Specifically, in 'Cron Events' the function is what's getting registered, not the hook. A simplified version of my code:

class My_Cron_Manager {

    /**
     * Constructor
     */
    public function __construct() {

        add_filter( 'wp', array( $this, 'my_schedule_cron_jobs' ) );
        add_action( 'my_cron_event_func', array( $this, 'my_cron_job_func' ));

    }

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

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

    }

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

        // Do Stuff

    }

}

new My_Cron_Manager();

I have a suspicion that I had an error in my code that was re-registering the function, but I'm not entirely sure.

Can someone please let me know if my above code would be causing duplicated hook/function registration?

Thanks in advance!