WordPress tutorial: Scheduled events


WordPress has a system that allows you to plan operations to be performed at regular intervals. You have to start by recording an action.

add_action (& # 039; montheme_import_content & # 039 ;, function () {
    touch (__ DIR__. & # 039; / demo - & # 039;. time ());
});

Then we will be able to plan using the method wp_schedule_event ($ depart, $ frequence, $ action) (we will check that the action is not already planned before using this function).

if (! wp_next_scheduled (& # 039; montheme_import_content & # 039;)) {
    wp_schedule_event (time (), & # 039; daily & # 039 ;, & # 039; montheme_import_content & # 039;);
}

You can also store new frequencies using the filter cron_schedules....

Read more