mailpoet
Last commit date
assets
11 months ago
generated
11 months ago
lang
11 months ago
lib
11 months ago
lib-3rd-party
1 year ago
vendor
11 months ago
vendor-prefixed
1 year ago
views
11 months ago
.gitleaksignore
1 year ago
index.php
3 years ago
license.txt
4 years ago
mailpoet-cron.php
2 years ago
mailpoet.php
11 months ago
mailpoet_initializer.php
1 year ago
readme.txt
11 months ago
mailpoet-cron.php
67 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | /** |
| 4 | * This file may be used by MailPoet to run a cron daemon that sends emails and perform other periodic tasks. It is |
| 5 | * disabled by default, and it only works on the command line (it is not accessible via the web browser in any way). |
| 6 | * It is used by a small subset of users that are not able to use the recommended method to send MailPoet emails. |
| 7 | * This is the case for sites that have their WP-Cron jobs broken by 3rd party plugins during cron processing, which |
| 8 | * prevents MailPoet from functioning. To work around this problem, this script loads only MailPoet and WordPress, |
| 9 | * without any other plugins. That is why it needs to require wp-load.php directly. |
| 10 | */ |
| 11 | |
| 12 | ini_set("display_errors", "1"); |
| 13 | error_reporting(E_ALL); |
| 14 | |
| 15 | if (!isset($argv[1]) || !$argv[1]) { |
| 16 | echo 'You need to pass a WordPress root as an argument.'; |
| 17 | exit(1); |
| 18 | } |
| 19 | |
| 20 | $wpLoadFile = $argv[1] . '/wp-load.php'; |
| 21 | if (!file_exists($wpLoadFile)) { |
| 22 | echo 'WordPress root argument is not valid.'; |
| 23 | exit(1); |
| 24 | } |
| 25 | |
| 26 | if (!defined('ABSPATH')) { |
| 27 | /** Set up WordPress environment */ |
| 28 | require_once($wpLoadFile); |
| 29 | } |
| 30 | |
| 31 | if (!is_plugin_active('mailpoet/mailpoet.php')) { |
| 32 | echo 'MailPoet plugin is not active'; |
| 33 | exit(1); |
| 34 | } |
| 35 | |
| 36 | if (wp_is_maintenance_mode()) { |
| 37 | echo 'WordPress site in maintenance mode.'; |
| 38 | exit(1); |
| 39 | } |
| 40 | |
| 41 | // Check for minimum supported PHP version |
| 42 | if (version_compare(phpversion(), '7.4.0', '<')) { |
| 43 | echo 'MailPoet requires PHP version 7.4 or newer (version 8.1 recommended).'; |
| 44 | exit(1); |
| 45 | } |
| 46 | |
| 47 | if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
| 48 | set_time_limit(0); |
| 49 | } |
| 50 | |
| 51 | $container = \MailPoet\DI\ContainerWrapper::getInstance(WP_DEBUG); |
| 52 | |
| 53 | // Check if Linux Cron method is set in plugin settings |
| 54 | $settings = $container->get(\MailPoet\Settings\SettingsController::class); |
| 55 | if ($settings->get('cron_trigger.method') !== \MailPoet\Cron\CronTrigger::METHOD_LINUX_CRON) { |
| 56 | echo 'You attempt to run MailPoets "Server side cron (Linux cron)."' . PHP_EOL . |
| 57 | 'But in your settings, you have defined a different method for the Newsletter task scheduler.' . PHP_EOL . |
| 58 | 'If you want to use the "Server side cron", please go to MailPoet > Settings > Advanced and choose the correct Newsletter task scheduler.' . PHP_EOL; |
| 59 | exit(1); |
| 60 | } |
| 61 | |
| 62 | // Run Cron Daemon |
| 63 | $cronHelper = $container->get(\MailPoet\Cron\CronHelper::class); |
| 64 | $data = $cronHelper->createDaemon(null); |
| 65 | $trigger = $container->get(\MailPoet\Cron\Daemon::class); |
| 66 | $trigger->run($data); |
| 67 |