get_error_message() ) ); } $code = wp_remote_retrieve_response_code( $spawn ); $message = wp_remote_retrieve_response_message( $spawn ); if ( 200 === $code ) { WP_CLI::success( 'WP-Cron spawning is working as expected.' ); } else { WP_CLI::error( sprintf( 'WP-Cron spawn returned HTTP status code: %1$s %2$s', $code, $message ) ); } } /** * Spawns a request to `wp-cron.php` and return the response. * * This function is designed to mimic the functionality in `spawn_cron()` * with the addition of returning the result of the `wp_remote_post()` * request. * * @return WP_Error|array The response or WP_Error on failure. */ protected static function get_cron_spawn() { $sslverify = \WP_CLI\Utils\wp_version_compare( 4.0, '<' ); $doing_wp_cron = sprintf( '%.22F', microtime( true ) ); $cron_request_array = array( 'url' => site_url( 'wp-cron.php?doing_wp_cron=' . $doing_wp_cron ), 'key' => $doing_wp_cron, 'args' => array( 'timeout' => 3, 'blocking' => true, // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Calling native WordPress hook. 'sslverify' => apply_filters( 'https_local_ssl_verify', $sslverify ), ), ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Calling native WordPress hook. $cron_request = apply_filters( 'cron_request', $cron_request_array ); # Enforce a blocking request in case something that's hooked onto the 'cron_request' filter sets it to false $cron_request['args']['blocking'] = true; $result = wp_remote_post( $cron_request['url'], $cron_request['args'] ); return $result; } }