Skip to content

Conversation

@peterwilsoncc
Copy link
Contributor

  • Introduces a filter to allow developers to enable/disable the wp-cron.php endpoint, wp_cron_endpoint_enabled.
  • The default value of the constant DISABLE_WP_CRON is defined and set to false if the endpoint is disabled.
  • Modifies wp-cron.php endpoint:
    • Adds a header indicating whether jobs are spawned or bypassed
    • Modifies when the request fast-finishes running to allow said header to be sent.

Trac ticket: https://core.trac.wordpress.org/ticket/64157


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@peterwilsoncc peterwilsoncc self-assigned this Oct 30, 2025
@peterwilsoncc peterwilsoncc marked this pull request as ready for review October 30, 2025 22:45
@github-actions
Copy link

github-actions bot commented Oct 30, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props peterwilsoncc, westonruter.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

/** 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' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a custom header, what about:

Suggested change
header( 'X-WP-Cron: Bypass' );
status_header( 403 );

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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).

Comment on lines -22 to -23
header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. Good point

header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
}
die();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would seem like a good place to send status_header( 400 ). I'm not sure when this ! empty( $_POST ) || defined( 'DOING_AJAX' ) || defined( 'DOING_CRON' ) condition would happen normally.

if ( ! headers_sent() ) {
header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
header( 'X-WP-Cron: Spawned' );
Copy link
Member

Choose a reason for hiding this comment

The 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 );
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

peterwilsoncc and others added 2 commits November 2, 2025 08:43
The new GitHub PR UI doesn't include batch commit anymore. Dandy.

Co-authored-by: Weston Ruter <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants