我有这个功能,每3分钟触发一次,检查一个插件是否处于非活动状态,如果它处于非活动状态,则向我发送一封电子邮件:
if ( ! function_exists('is_plugin_inactive')) {
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
}
if (is_plugin_inactive( 'pluginfolder/plugin.php' )) {
function isa_add_cron_recurrence_interval( $schedules ) {
$schedules['every_three_minutes'] = array(
'interval' => 180,
'display' => __( 'Every 3 Minutes', 'textdomain' )
);
return $schedules;
}
add_filter( 'cron_schedules', 'isa_add_cron_recurrence_interval' );
wp_schedule_event( time(), 'every_three_minutes',
'your_three_minute_action_hook' );
add_action('your_three_minute_action_hook',
'isa_test_cron_job_send_mail');
function isa_test_cron_job_send_mail() {
//plugin is not activated
$to = 'me@gmail.com';
$subject = 'Plugin Inactive';
$body = 'PANIC!';
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail( $to, $subject, $body, $headers );
}
}
每次运行时都会通过电子邮件向我发送电子邮件。 如何限制每次发送时发送一次的电子邮件?