Cron job in WordPress not working

前端 未结 2 646
清歌不尽
清歌不尽 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'); 
    

提交回复
热议问题