2016-04-20 16 views
0

我禁用WP cron和建立一個cron作業我的服務器上,在每個小時的頂背離http://www.domain.com/wp-cron.php?doing_wp_cronwp_schedule_event不是wp-config.php文件中執行我的功能

運行,我有以下的代碼我functions.php文件,但是當作物作業在每小時的頂部運行時,我永遠不會收到電子郵件。

我檢查了數據庫和確認工作是在wp_options桌子底下「的cron」

我想不出什麼我做錯了導致郵件不火。

// Scheduled Action Hook 
    function menu_update_reminder() { 
     mail('[email protected]', 'Cron ran successfully', 'Cron ran successfully'); 
} 

// Schedule Cron Job Event 
function menu_update_cron() { 
    if (! wp_next_scheduled('menu_update_reminder')) { 
     wp_schedule_event(current_time('timestamp'), 'hourly', 'menu_update_reminder'); 
    } 
} 
add_action('wp', 'menu_update_cron'); 
+0

可能是一個想法,記錄以及發送電子郵件,至少你知道它是否郵件的問題或問題的cron .. – David

+0

你嘗試使用wp_mail ? – neoprez

回答

0

我最終沒有在代碼中最有用的部分。 add_action在cron作業運行後實際運行該函數中的代碼。

menu_update_reminder功能更名爲menu_update_reminder_run

// Scheduled Action Hook 
function menu_update_reminder_run() { 
    mail('[email protected]', 'Cron ran successfully', 'Cron ran successfully'); 
} 
add_action('menu_update_reminder' , 'menu_update_reminder_run'); 

// Schedule Cron Job Event 
function menu_update_cron() { 
if (! wp_next_scheduled('menu_update_reminder')) { 
    wp_schedule_event(current_time('timestamp'), 'hourly', 'menu_update_reminder'); 
    } 
} 
add_action('wp', 'menu_update_cron');