wp cron wordpress问题

时间:2019-02-15 15:40:18

标签: wordpress cron

在我的wordpress网站上,我想每30天向尚未完成个人资料的用户发送提醒。 我从制作一个简单的示例来测试cron开始,但是它不起作用。你能帮我解决吗? getUserModel()函数不起作用。


        // send reminder
    // Scheduled Action Hook
    function SendEmailRemiderToESN( ) {
        wp_mail( "sammoudi.maher@gmail.com","TestCron","Hello" );
    }
    add_action( 'SendEmailRemiderToESN', 'SendEmailRemiderToESN' );

    // Custom Cron Recurrences
    function custom_cron_job_recurrence( $schedules ) {
        $schedules['every30days'] = array(
            'display' => __( 'every30days', 'textdomain' ),
            'interval' => 2592000,
        );
        return $schedules;
    }
    add_filter( 'cron_schedules', 'custom_cron_job_recurrence' );

    // Schedule Cron Job Event
    function custom_cron_job() {
        if ( ! wp_next_scheduled( 'SendEmailRemiderToESN' ) ) {
            wp_schedule_event( current_time( 'timestamp' ), 'every30days', 'SendEmailRemiderToESN' );
        }
    }
    add_action( 'wp', 'custom_cron_job' );

1 个答案:

答案 0 :(得分:0)

测试此;) 它在我的Mac上的localhost中工作

function custom_cron_job_recurrence_own( $schedules ) {

    $schedules['every30days'] = array(
        'interval'  => 2592000,
        'display'   => __( 'every30days', 'textdomain' )
    );

    return $schedules;
}
add_filter( 'cron_schedules', 'custom_cron_job_recurrence_own' );


if ( ! wp_next_scheduled( 'SendEmailRemiderToESN' ) ) {
    wp_schedule_event( time(), 'every30days', 'SendEmailRemiderToESN' );
}
add_action('SendEmailRemiderToESN', 'custom_cron_job_recurrence');

function custom_cron_job_recurrence() {

    wp_mail(................);

};