Cron job in WordPress not working

前端 未结 2 612
清歌不尽
清歌不尽 2021-01-28 18:59

I have made a WordPress cron job that should send out a mail each hour:

function mail_cron_job() {
     $time = date( \'h:ia\', time() );
       wp_mail( \'****@         


        
相关标签:
2条回答
  • 2021-01-28 19:29

    Cron Job Schedule in wordpress

    //Add Interval [ Day ] 
    function cron_add_daily($schedules) 
    {
    // Adds once every minute to the existing schedules.
    $schedules['daily'] = array('display' =>( 'Once Daily' ) );
    return $schedules;
    }
    add_filter( 'cron_schedules', 'cron_add_daily' );
    // create a scheduled event (if it does not exist already)
    function cron_activation() {
     if( !wp_next_scheduled( 'plugin_mailcronjob' ) ) {  
       wp_schedule_event(time(), 'daily', 'plugin_mailcronjob' );  
      }
     }
     // and make sure it's called whenever WordPress loads
      add_action('init', 'crons_activation');
    
     function repeat_function_daily()
     {
       /*
            put code here what you want check daily
       */
    
      }
     // hook that function onto our scheduled event:
     add_action ('plugin_mailcronjob', 'repeat_function_daily'); 
    
    0 讨论(0)
  • 2021-01-28 19:39

    you need to use an action hook to tie the event and function together.

    add_action( 'mail_cron_job', 'mail_cron_job' );
    

    You can add that right after the function.

    0 讨论(0)
提交回复
热议问题