WordPress.org

Support

Support » Plugins and Hacks » Hacks » wp_schedule_event / cron_schedules – custom recurrence time not working in Plugi

wp_schedule_event / cron_schedules – custom recurrence time not working in Plugi

  • Hello,

    I am trying to add custom intervals for the WP cron in a plugin.
    It run with “hourly”, “daily” default recurrence time.
    It dont’ run when I add my own custom recurrence time for the function wp_schedule_event.

    I want to execute a function every X hours (defined by users).

    Thanks.

    Here is the code:

    [Code moderated as per the Forum Rules. Please use the pastebin]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello.

    Looks like i have the same problem. I am writing a plugin and playing with wp_schedule_event at the moment.

    I added a custom recurrence via the ‘cron_schedules’ filter in the constructor of my plugin class. Next thing i did was putting wp_schedule_event in an activation hook with my custom recurrence, but it does not get added. When i use something like ‘daily’ it gets added but not with my own recurrence.

    Lookin at wp-includes/cron.php i see this:

    $schedules = wp_get_schedules();
    
    if ( !isset( $schedules[$recurrence] ) )
    	return false;

    That seems that the custom recurrence is not available at the point i call wp_schedule_event and therefore does not get added.

    Probably have to call wp_schedule_event on another hook and not on plugin activation, though that seems to be a nice place for it.

    Found the issue with my code. The outer array returned from my ‘cron_schedules’ filter had a missing ‘named index’.

    See:
    http://codex.wordpress.org/Plugin_API/Filter_Reference/cron_schedules

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_schedule_event / cron_schedules – custom recurrence time not working in Plugi’ is closed to new replies.
Skip to toolbar