wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren
wp_cron › WordPress Function
Seit2.1.0
Veraltetn/v
› wp_cron ( Keine Parameter )
| Definiert in: |
|
| Codex: | |
| Changelog: |
|
Registers _wp_cron() to run on the {@see 'shutdown'} action.
The spawn_cron() function attempts to make a non-blocking loopback request towp-cron.php (when alternative
cron is not being used). However, the wp_remote_post() function does not always respect the timeout and
blocking parameters. A timeout of 0.01 may end up taking 1 second. When this runs at the {@see 'wp_loaded'}
action, it increases the Time To First Byte (TTFB) since the HTML cannot be sent while waiting for the cron request
to initiate. Moving the spawning of cron to the {@see 'shutdown'} hook allows for the server to flush the HTML document to
the browser while waiting for the request.Quellcode
function wp_cron(): void {
if ( defined( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON ) {
if ( did_action( 'wp_loaded' ) ) {
_wp_cron();
} else {
add_action( 'wp_loaded', '_wp_cron', 20 );
}
} elseif ( doing_action( 'shutdown' ) ) {
_wp_cron();
} else {
add_action( 'shutdown', '_wp_cron' );
}
}