[resolved] Illegal Offset Type when using wp_schedule_event (3 posts)

  1. therealwesfoster
    Posted 4 years ago #

    When I try creating a schedule, I get an “Illegal Offset” error in /wp-includes/cron.php on line 79. Since I didn’t edit the core cron.php file, I’m not sure what’s wrong. Here’s my code that calls the function:

    class ClassName {
    // This function runs instantly when the class is called
    function __construct(){
       $start_date = strtotime('27 September 2011');
       wp_schedule_event($start_date, 'hourly', array(&$this, 'do_cron'));
    // The cron data
    function do_cron(){
       die('The cron data is here!');
    }// end class
    // Run the class
    $class = new ClassName();

    And just in case you don't want to look, line 79 of cron.php is:

    $crons[$event->timestamp][$event->hook][$key] = array( 'schedule' => $event->schedule, 'args' => $event->args, 'interval' => $event->interval );

    Any ideas? I'm stumped!

  2. therealwesfoster
    Posted 4 years ago #

    Could it be that I'm putting an array in place of the (string) $hook?

    In most functions, you can add array(&$this, 'function_name') in place of the hook to call a function from the same class. However, the schedule functions specifically call for a "string" instead of a string|array.

    I bet this is the problem. I'll try it now and come back with an answer if it's working.

  3. therealwesfoster
    Posted 4 years ago #

    That is EXACTLY the problem! Hopefully this post will help someone else!

    This needs to be fixed in the next version of WP though, for sure.

Topic Closed

This topic has been closed to new replies.

About this Topic