Commit 8f7d9d3c authored by Erick Hitter's avatar Erick Hitter
Browse files

Ensure `DOING_CRON` is set for all REST requests

If code is loaded conditionally when `DOING_CRON` is set, not setting it for all of the plugin's REST endpoints can lead to unexpected behaviour.

For example, duplicate events can be created infinitely, in combination with the skip-empty-event functionality.

Fixes #97
parent bcf0e85c
......@@ -31,13 +31,19 @@ class Events extends Singleton {
* This also runs before Core has parsed the request and set the \REST_REQUEST constant
*/
public function prepare_environment() {
if ( ! is_rest_endpoint_request( 'run' ) ) {
// Limit to plugin's endpoints
if ( ! is_rest_endpoint_request( 'list' ) && ! is_rest_endpoint_request( 'run' ) ) {
return;
}
ignore_user_abort( true );
set_time_limit( JOB_TIMEOUT_IN_MINUTES * MINUTE_IN_SECONDS );
// Flag is used in many contexts, so should be set for all of our requests, regardless of the action
define( 'DOING_CRON', true );
// When running events, allow for long-running ones, and non-blocking trigger requests
if ( is_rest_endpoint_request( 'run' ) ) {
ignore_user_abort( true );
set_time_limit( JOB_TIMEOUT_IN_MINUTES * MINUTE_IN_SECONDS );
}
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment