[wp-trac] [WordPress Trac] #24160: ALTERNATE_WP_CRON runs wp_cron() too early
WordPress Trac
noreply at wordpress.org
Sun Jan 31 21:33:57 UTC 2021
#24160: ALTERNATE_WP_CRON runs wp_cron() too early
-----------------------------+----------------------------
Reporter: r-a-y | Owner: peterwilsoncc
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: 5.7
Component: Cron API | Version: 3.4
Severity: normal | Resolution:
Keywords: has-patch early | Focuses:
-----------------------------+----------------------------
Comment (by johnbillion):
For anyone like me who is trying to wrap their head around what exactly
the problem is:
* When `wp-cron.php` is accessed with a direct POST request, either as a
result of `spawn_cron()` or as a result of a real server cron job
requesting it, `wp-load.php` is included and then any pending cron events
are iterated and run. This means actions such as `init` and `wp_loaded`
have finished executing by the point where the cron events are run.
* With `ALTERNATE_WP_CRON` in use, the `wp_cron` function that's hooked
into `init` does an `include_once( 'wp-cron.php' )` which then iterates
and runs pending cron events after flushing a redirect header to the
client.
This means with `ALTERNATE_WP_CRON` in use, cron events run within the
`init` hook on priority 10. Without it in use, they run after the
`wp_loaded` action has fired.
To bring these two situations closer, the `wp_cron` function should be
hooked into `wp_loaded` with a late priority, as per Peter's comment and
PR above.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/24160#comment:22>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list