wp_schedule_event is not working

Asked

Viewed 68 times

1

I have the following function created in my functions.php. I’m changing the theme to schedule, and I can see that it’s scheduled by the function of next_schedule.

add_action( 'after_switch_theme', 'prefix_setup_schedule' ); 

function prefix_setup_schedule() {
    if ( ! wp_next_scheduled( 'sendemail' ) ) {
        $timeschedule = strtotime(date("Y-m-d 18:00:00"));
        wp_schedule_event( $timeschedule, 'daily', 'sendemail');
    }
}

function sendemail()
{
    update_option('envioemail','feito');
}

However, this code is not running, does anyone have any idea?

1 answer

1

I managed to solve the following way, first the wp_schedule_event was like this:

wp_schedule_event( $timeschedule, 'daily', 'my_daily_event');

Then I created an action like this:

add_action( 'my_daily_event',  'sendemail' ); 

and the function became normal, so my problem was solved.

Response based on comment from the questioner.

  • Caio, if you want to publish a reply in your own name, let me know and I will remove this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.