| @@ -25,12 +25,42 @@ | ||
| 25 | 25 | * @return void |
| 26 | 26 | */ |
| 27 | 27 | public static function start() |
| 28 | 28 | { |
| 29 | - if (!self::isStarted()) | |
| 29 | + /** | |
| 30 | + * Prevent the handler from starting a new session in case the process was launched | |
| 31 | + * from wp-cron.php, which manually sends some headers at the beginning of the file. | |
| 32 | + * | |
| 33 | + * @since 10.1.65 | |
| 34 | + */ | |
| 35 | + if (defined('DOING_CRON') && DOING_CRON) | |
| 30 | 36 | { |
| 31 | - session_start(); | |
| 37 | + return; | |
| 32 | 38 | } |
| 39 | + | |
| 40 | + /** | |
| 41 | + * Do not go ahead in case the session has been already started, otherwise duplicate | |
| 42 | + * calls to this method risks to register the same hook more than once. | |
| 43 | + * | |
| 44 | + * @since 10.1.70 | |
| 45 | + */ | |
| 46 | + if (self::isStarted()) | |
| 47 | + { | |
| 48 | + return; | |
| 49 | + } | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * In case the headers have been already sent, trigger warning and abort. | |
| 53 | + * | |
| 54 | + * @since 10.1.70 | |
| 55 | + */ | |
| 56 | + if (headers_sent()) | |
| 57 | + { | |
| 58 | + trigger_error('Session cannot be started after headers have already been sent', E_USER_WARNING); | |
| 59 | + return; | |
| 60 | + } | |
| 61 | + | |
| 62 | + session_start(); | |
| 33 | 63 | |
| 34 | 64 | /** |
| 35 | 65 | * Filters whether to preempt an HTTP request's return value. |
| 36 | 66 | * It is needed to support concurrent cURL requests (see Site Health). |