您可以这样做,在伪代码和注释中进行解释。
在函数中创建如下函数。php文件:
/**
* This function collects the tasks that are due in a week and sends a reminder
**/
function check_user_tasks_week_before() {
// query which Completion Dates are in a week
// loop through the results (if any)
// and send every user in the result (or every task that is almost due) the email:
// Send a mail:
wp_mail( \'[email protected]\',
\'Your task should be completed in a week\',
\'Hey, the deadline for your task blablabla is due in a week, get going or else!\');
}
(有关
how to attach an image see this page at the WordPress 法典。)
到schedule the task with wp_cron
, 所以它每天都在运行,在文件函数中创建这样的函数。php:
// If the task does not exist yet, it is created here:
if ( ! wp_next_scheduled( \'my_task_hook\' ) ) {
// you can specify what time() it should run (it is a unix timestamp)
// in your case \'daily\' would be a good choice:
wp_schedule_event( time(), \'daily\', \'my_task_hook\' );
}
add_action( \'my_task_hook\', \'check_user_tasks_week_before\' );