• Hello,

    I’m trying to create a simple single scheduled event and have created an action using add_action to be scheduled. However, when I schedule an event it does not have an action. I am using WP-Cron Dashboard plugin to check the status of the event and it does schedule properly and executes however there is no action in the event. The WP-Cron Dashboard indicates that the action does not exist. However, I can use the do_action() command right before I schedule the event and it works perfectly fine; executing the function in the action.

    Here is a snipit of how I am trying to add_action() and then use wp_schedule_single_event().

    if (isset($_POST['Submit1']))
    					{
    add_action('test_code','do_this_in_an_hour');
    wp_schedule_single_event($timed3, 'test_code');
    }

    $timed3 is a unixtime variable that is declared outside of the if statement. Using WP-Cron Dashboard I can see that the event is scheduled at the correct time of $timed3 and disappears from the queue list at the given time. However, the action shows up as non-existent in the Dashboard. I can insert do_action(‘test_code’); in a line between add_action() and wp_schedule_single_event() and this executes perfectly fine running the desired function. Any advice on why this isn’t working would be greatly appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Faytesp

    (@faytesp)

    Also for those wondering about the function, it includes a file with a simple class in it to acquire the time. Once the class saves the time in a variable, I serialize the object of the class so I can call the object later and check what time the event was called. I have also ran this function separately and it works as well being able to get the current time, store it in a serializable object and later call the object and unserialize it to display the time.

    Thread Starter Faytesp

    (@faytesp)

    still unable to fix the action hook, would creating it in a seperate file before I schedule affect the outcome? though this would create alot of unnecessary files.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘add_action undetected by wp_schedule_single_event’ is closed to new replies.