From 0b9c7b7cdf860a046c4ee7ffd676c420b6ac7a0b Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Mon, 22 Feb 2021 00:51:09 +0000 Subject: [PATCH] Site Health: Update loopback test to `POST` to wp-cron. Replace loopback health check URL with a `POST` request to `wp-cron.php` in the WordPress install directory. This more closely represents how WordPress uses loopback requests. A `POST` request is used to cause `wp-cron.php` to exit prior to running any cron jobs. This allows the test to indicate success quicker and accounts for sites that set the `DISABLE_WP_CRON` constant to avoid running cron jobs on loopback requests. Props clorith, peterwilsoncc, TimothyBlynJacobs. Fixes #52547. Built from https://develop.svn.wordpress.org/trunk@50399 git-svn-id: http://core.svn.wordpress.org/trunk@50010 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/class-wp-site-health.php | 15 +++++++++++++-- wp-includes/version.php | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/wp-admin/includes/class-wp-site-health.php b/wp-admin/includes/class-wp-site-health.php index bae01e7af9..48bd21b6a6 100644 --- a/wp-admin/includes/class-wp-site-health.php +++ b/wp-admin/includes/class-wp-site-health.php @@ -2647,6 +2647,7 @@ class WP_Site_Health { * @return object The test results. */ function can_perform_loopback() { + $body = array( 'site-health' => 'loopback-test' ); $cookies = wp_unslash( $_COOKIE ); $timeout = 10; $headers = array( @@ -2660,9 +2661,19 @@ class WP_Site_Health { $headers['Authorization'] = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) ); } - $url = home_url(); + $url = site_url( 'wp-cron.php' ); - $r = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout', 'sslverify' ) ); + /* + * A post request is used for the wp-cron.php loopback test to cause the file + * to finish early without triggering cron jobs. This has two benefits: + * - cron jobs are not triggered a second time on the site health page, + * - the loopback request finishes sooner providing a quicker result. + * + * Using a POST request causes the loopback to differ slightly to the standard + * GET request WordPress uses for wp-cron.php loopback requests but is close + * enough. See https://core.trac.wordpress.org/ticket/52547 + */ + $r = wp_remote_post( $url, compact( 'body', 'cookies', 'headers', 'timeout', 'sslverify' ) ); if ( is_wp_error( $r ) ) { return (object) array( diff --git a/wp-includes/version.php b/wp-includes/version.php index 3a705494cb..b57cd77cec 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.7-beta3-50398'; +$wp_version = '5.7-beta3-50399'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.