admin管理员组文章数量:1025202
I have used two plugins for cron
1) Advance Cron Manager 2) WP Control
I have added cron in both plugins, but it removes from queue after some time when there is no activity on website (frontenf/Backend).
It's odd but cron interval time is 1 minute, but last till I am logged in dashboard for testing same thing.
Cron Type: Recurring after 1 minute. Here is screenshot of schedule event.
This is code from my plugin file
add_action('new_email_event', 'identify_new_email_received');
function identify_new_email_received() {
ini_set('display_errors', '1');
$settings = odz_get_whatsappsmtp_settings();
include(dirname(__FILE__).'/src/PhpImap/__autoload.php');
$hostname = '{imap.gmail:993/imap/ssl}INBOX';
$username = $settings['configured_email'];
$password = $settings['email_password'];
$mailbox = new PhpImap\Mailbox('{imap.gmail:993/imap/ssl}INBOX', $username, $password);
//$mailbox = new PhpImap\Mailbox('{imap.gmail:993/imap/ssl}INBOX', $settings['configured_email'], $settings['email_password'], __DIR__);
$since_date = date('Y-m-d',strtotime("-1 days"));
$mailsIds = $mailbox->searchMailbox('SINCE "'.$since_date.'"');
if(!$mailsIds) {
my_custom_log('No emails');
}
$email_data = array();
if(!get_site_option('wp_last_email_time')){
my_custom_log('No last email');
//whatsapp the last email
$latest_mail = count($mailsIds) -1;
$mail = $mailbox->getMail($mailsIds[$latest_mail]);
$email_data['date'] = $mail->date;
$email_data['text'] = $mail->textPlain;
$email_data['id'] = $mail->id;
$email_data['subject'] = $mail->subject;
$email_data['fromAddress'] = $mail->fromAddress;
$email_data['fromName'] = $mail->fromName;
$sender = get_sender_number($mail->textHtml);
$msg = get_sender_message($mail->textHtml);
if(!empty($msg)){
$email_data['text'] = $msg;
}
if(!empty($sender)){
$mailbox->deleteMail($mail->id);
sendWhatsappMessage($email_data,$sender);
update_site_option('wp_last_email_time',strtotime($mail->date));
}
}
else{
my_custom_log('Looping through mail ids');
foreach($mailsIds as $mail_id){
$mail = $mailbox->getMail($mail_id);
$last_email = get_site_option('wp_last_email_time');
my_custom_log('last email time');
my_custom_log($last_email);
my_custom_log('************************');
if(strtotime($mail->date) > $last_email){
$email_data = array();
$email_data['date'] = $mail->date;
$email_data['text'] = $mail->textPlain;
$email_data['id'] = $mail->id;
$email_data['subject'] = $mail->subject;
$email_data['fromAddress'] = $mail->fromAddress;
$email_data['fromName'] = $mail->fromName;
$sender = get_sender_number($mail->textHtml);
$msg = get_sender_message($mail->textHtml);
if(!empty($msg)){
$email_data['text'] = $msg;
}
if(!empty($sender)){
sendWhatsappMessage($email_data,$sender);
update_site_option('wp_last_email_time',strtotime($mail->date));
$mailbox->deleteMail($mail->id);
}
}
else{
//echo 'this email not sent. '.$mail->subject.' '.$mail->date.' '.strtotime($mail->date).'</br>';
}
}
}
}
I have used two plugins for cron
1) Advance Cron Manager 2) WP Control
I have added cron in both plugins, but it removes from queue after some time when there is no activity on website (frontenf/Backend).
It's odd but cron interval time is 1 minute, but last till I am logged in dashboard for testing same thing.
Cron Type: Recurring after 1 minute. Here is screenshot of schedule event.
This is code from my plugin file
add_action('new_email_event', 'identify_new_email_received');
function identify_new_email_received() {
ini_set('display_errors', '1');
$settings = odz_get_whatsappsmtp_settings();
include(dirname(__FILE__).'/src/PhpImap/__autoload.php');
$hostname = '{imap.gmail:993/imap/ssl}INBOX';
$username = $settings['configured_email'];
$password = $settings['email_password'];
$mailbox = new PhpImap\Mailbox('{imap.gmail:993/imap/ssl}INBOX', $username, $password);
//$mailbox = new PhpImap\Mailbox('{imap.gmail:993/imap/ssl}INBOX', $settings['configured_email'], $settings['email_password'], __DIR__);
$since_date = date('Y-m-d',strtotime("-1 days"));
$mailsIds = $mailbox->searchMailbox('SINCE "'.$since_date.'"');
if(!$mailsIds) {
my_custom_log('No emails');
}
$email_data = array();
if(!get_site_option('wp_last_email_time')){
my_custom_log('No last email');
//whatsapp the last email
$latest_mail = count($mailsIds) -1;
$mail = $mailbox->getMail($mailsIds[$latest_mail]);
$email_data['date'] = $mail->date;
$email_data['text'] = $mail->textPlain;
$email_data['id'] = $mail->id;
$email_data['subject'] = $mail->subject;
$email_data['fromAddress'] = $mail->fromAddress;
$email_data['fromName'] = $mail->fromName;
$sender = get_sender_number($mail->textHtml);
$msg = get_sender_message($mail->textHtml);
if(!empty($msg)){
$email_data['text'] = $msg;
}
if(!empty($sender)){
$mailbox->deleteMail($mail->id);
sendWhatsappMessage($email_data,$sender);
update_site_option('wp_last_email_time',strtotime($mail->date));
}
}
else{
my_custom_log('Looping through mail ids');
foreach($mailsIds as $mail_id){
$mail = $mailbox->getMail($mail_id);
$last_email = get_site_option('wp_last_email_time');
my_custom_log('last email time');
my_custom_log($last_email);
my_custom_log('************************');
if(strtotime($mail->date) > $last_email){
$email_data = array();
$email_data['date'] = $mail->date;
$email_data['text'] = $mail->textPlain;
$email_data['id'] = $mail->id;
$email_data['subject'] = $mail->subject;
$email_data['fromAddress'] = $mail->fromAddress;
$email_data['fromName'] = $mail->fromName;
$sender = get_sender_number($mail->textHtml);
$msg = get_sender_message($mail->textHtml);
if(!empty($msg)){
$email_data['text'] = $msg;
}
if(!empty($sender)){
sendWhatsappMessage($email_data,$sender);
update_site_option('wp_last_email_time',strtotime($mail->date));
$mailbox->deleteMail($mail->id);
}
}
else{
//echo 'this email not sent. '.$mail->subject.' '.$mail->date.' '.strtotime($mail->date).'</br>';
}
}
}
}
本文标签: pluginsScheduled cron event removed from list automatically after sometime
版权声明:本文标题:plugins - Scheduled cron event removed from list automatically after sometime 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745611921a2159050.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论