| @@ -25,14 +25,44 @@ | ||
| 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 | } |
| 33 | 39 | |
| 34 | 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(); | |
| 63 | + | |
| 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). |
| 37 | 67 | * |
| 38 | 68 | * Returning a non-false value from the filter will short-circuit the HTTP request and return |
| @@ -124,9 +154,9 @@ | ||
| 124 | 154 | public static function isStarted() |
| 125 | 155 | { |
| 126 | 156 | /** |
| 127 | 157 | * Make sure the session status is currently active. This because, |
| 128 | - * in case someonehad manually closed the session, this method would | |
| 158 | + * in case someone had manually closed the session, this method would | |
| 129 | 159 | * have improperly returned true. |
| 130 | 160 | * |
| 131 | 161 | * @since 10.1.43 |
| 132 | 162 | */ |