events - Wp_schedule_event functions.php

admin2025-06-07  50

I am using this code in my functions.php which works fine. However, I was wondering if this is the best practice to do so to schedule an event, or if there is a better solution.

if (!wp_next_scheduled('my_task_hook')) {
    wp_schedule_event( time(), 'daily', 'my_task_hook' );
}

add_action( 'my_task_hook', 'my_task_function' ); 

function my_task_function() {
    wp_mail('[email protected]', 'Test Email', 'Hello, this is a test automatically scheduled email from WordPress.');
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749241270a317543.html

最新回复(0)