wp_schedule_event / cron_schedules - custom recurrence time not working in Plugi (3 posts)

  1. PapyRef
    Posted 4 years ago #


    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).


    Here is the code:

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

  2. dc5ala
    Posted 4 years ago #


    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.

  3. dc5ala
    Posted 4 years ago #

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


Topic Closed

This topic has been closed to new replies.

About this Topic