wp = $wp;
$this->cronHelper = $cronHelper;
$this->settings = $settings;
}
public function init($shouldDisplay) {
if (!$shouldDisplay) {
return null;
}
$isDismissed = $this->wp->getTransient(self::OPTION_NAME);
$currentMethod = $this->settings->get(CronTrigger::SETTING_CURRENT_METHOD);
$isWPCronMethodActive = $currentMethod === CronTrigger::METHOD_ACTION_SCHEDULER;
$isCronFunctional = $this->isCronFunctional();
if (!$isDismissed && $isWPCronMethodActive && $this->isWPCronDisabled() && !$isCronFunctional) {
return $this->display();
}
}
public function isWPCronDisabled() {
return defined('DISABLE_WP_CRON') && DISABLE_WP_CRON;
}
public function isCronFunctional(): bool {
// If a cron run was started/completed less than an hour ago, we consider it functional.
$lastRunThreshold = time() - HOUR_IN_SECONDS;
return ($this->cronHelper->getDaemon()['run_started_at'] ?? 0) > $lastRunThreshold
|| ($this->cronHelper->getDaemon()['run_completed_at'] ?? 0) > $lastRunThreshold;
}
public function display() {
$errorString = __('WordPress built-in cron is disabled with the DISABLE_WP_CRON constant on your website, this prevents MailPoet sending from working. Please enable WordPress built-in cron or choose a different cron method in MailPoet Settings.', 'mailpoet');
$buttonString = __('[link]Go to Settings[/link]', 'mailpoet');
$error = $errorString . '
' . Helpers::replaceLinkTags($buttonString, 'admin.php?page=mailpoet-settings#advanced', [
'class' => 'button-primary',
]);
$extraClasses = 'mailpoet-dismissible-notice is-dismissible';
return Notice::displayError($error, $extraClasses, self::OPTION_NAME, true, false);
}
public function disable() {
$this->wp->setTransient(self::OPTION_NAME, true, self::DISMISS_NOTICE_TIMEOUT_SECONDS);
}
}