-
Notifications
You must be signed in to change notification settings - Fork 3.1k
First draft at hook to control wp-cron.php endpoint. #10438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
e9c6e22
bd3da34
5196fa5
93a44da
c589697
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -18,19 +18,11 @@ | |||||
|
|
||||||
| ignore_user_abort( true ); | ||||||
|
|
||||||
| if ( ! headers_sent() ) { | ||||||
| header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' ); | ||||||
| header( 'Cache-Control: no-cache, must-revalidate, max-age=0' ); | ||||||
| } | ||||||
|
|
||||||
| // Don't run cron until the request finishes, if possible. | ||||||
| if ( function_exists( 'fastcgi_finish_request' ) ) { | ||||||
| fastcgi_finish_request(); | ||||||
| } elseif ( function_exists( 'litespeed_finish_request' ) ) { | ||||||
| litespeed_finish_request(); | ||||||
| } | ||||||
|
|
||||||
| if ( ! empty( $_POST ) || defined( 'DOING_AJAX' ) || defined( 'DOING_CRON' ) ) { | ||||||
| if ( ! headers_sent() ) { | ||||||
| header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' ); | ||||||
| header( 'Cache-Control: no-store, no-cache, must-revalidate, max-age=0' ); | ||||||
| } | ||||||
| die(); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would seem like a good place to send |
||||||
| } | ||||||
|
|
||||||
|
|
@@ -46,6 +38,27 @@ | |||||
| require_once __DIR__ . '/wp-load.php'; | ||||||
| } | ||||||
|
|
||||||
| /** This filter is documented in wp-includes/default-constants.php */ | ||||||
| if ( ! apply_filters( 'wp_cron_endpoint_enabled', true ) ) { | ||||||
| if ( ! headers_sent() ) { | ||||||
| header( 'X-WP-Cron: Bypass' ); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of a custom header, what about:
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm happy to do this if batcache caches 403 responses (pending adding output to the page, as discussed on the ticket). |
||||||
| } | ||||||
| die(); | ||||||
| } | ||||||
|
|
||||||
| if ( ! headers_sent() ) { | ||||||
| header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' ); | ||||||
| header( 'Cache-Control: no-store, no-cache, must-revalidate, max-age=0' ); | ||||||
| header( 'X-WP-Cron: Spawned' ); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of sending this here, what if below where it does: if ( empty( $crons ) ) {
die();
}It could be changed to: if ( empty( $crons ) ) {
status_header( 304 );
die();
} else {
status_header( 200 );
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm unsure. It's still a successful request if the cron array is empty, it just happens that there are no jobs to spawn. It would also require the DB request be made before the fast finish. |
||||||
| } | ||||||
|
|
||||||
| // Don't run cron until the request finishes, if possible. | ||||||
| if ( function_exists( 'fastcgi_finish_request' ) ) { | ||||||
| fastcgi_finish_request(); | ||||||
| } elseif ( function_exists( 'litespeed_finish_request' ) ) { | ||||||
| litespeed_finish_request(); | ||||||
| } | ||||||
|
|
||||||
| // Attempt to raise the PHP memory limit for cron event processing. | ||||||
| wp_raise_memory_limit( 'cron' ); | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't these headers be left right here? They're now sent in two different places below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a slight change: if requests are bypassed the no-caching headers aren't sent as it's safe to cache the endpoint as it doesn't need to hit the database.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right. Good point