wp_schedule_single_event not working in 3.3.1 (4 posts)

  1. Omar Jackman
    Posted 4 years ago #

    I am testing the wp_schedule_single_event function and it is currently not working on my upgraded version of wordpress.

    It looks like the event is being scheduled but the code in my hook is never executed. Any help with this matter would be greatly appreciated

    Here is example code I put in my themes function.php:

    	update_option('test_action_option', 'Scheduled: ' . $_GET['begintest']);
    	wp_clear_scheduled_hook( 'event_test_action'); // clear anything else in the system
    	wp_schedule_single_event( time() + 10, 'event_test_action');
    add_action('event_test_action', 'event_test_action');
    function event_test_action(){
    	update_option('test_action_option', 'Ran');

    [ Please do not bump or poke, it's not permitted here. ]

  2. spurge
    Posted 3 years ago #

    Even if this was long ago I'll post an answer.

    After some digging in the wordpress cron files I found the following:

    * wp_schedule_single_event is using microseconds instead of seconds as the documentation says.
    * Arguments must be passed as arrays. My php/apache error log was warning about some executed array functions on non-arrays. It's do_action_ref_array that is used by the scheduler code that requires arrays as arguments. This is also not documented.

  3. bcworkz
    Posted 3 years ago #

    @spurge, that's some interesting observations. Do you have references you can provide?

    While wp_cron() (where the $timestamp parameter gets compared) uses microtimer() function, it is returning a real number, the mantissa portion is the seconds since UNIX epoch, the fractional portion is a fraction of a second, accurate to a microsecond. This sounds like the unit is seconds, not microseconds. Otherwise, the value would need to be a long integer. I'm not even sure the microseconds since epoch even fit in an integer, unless it's a quad integer?

    As far as arguments, in the docs under parameters, it specifies $args must be an array. I see no conflicting info anywhere else. I'm looking at Function Reference/wp schedule single event. Are you looking somewhere else?

  4. spurge
    Posted 3 years ago #

    @bcworkz, look at the code :) wp-includes/cron.php and wp-cron.php. But it looks that you already have :)

    Sorry about the array argument. You're right, it is documented, but I didn't think so when I wrote the post.

Topic Closed

This topic has been closed to new replies.

About this Topic