From 991423ba8e3c79cf2ff90a7df0b58dd341ebc6dd Mon Sep 17 00:00:00 2001 From: Remco Tolsma <869674+remcotolsma@users.noreply.github.com> Date: Mon, 22 Jan 2024 15:35:32 +0100 Subject: [PATCH] Possible fix for https://github.com/pronamic/wp-pay-core/issues/170. --- src/Client.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Client.php b/src/Client.php index bb888a9..f4bf1e6 100644 --- a/src/Client.php +++ b/src/Client.php @@ -99,6 +99,22 @@ public function get_user_agent() { ); } + /** + * Helper function to check if the HTTP timeout could be increased. + * + * @link https://github.com/pronamic/wp-pay-core/issues/170 + * @return bool + */ + private function should_increase_http_timeout() { + return ( + \wp_doing_cron() + || + \defined( 'WP_CLI' ) && WP_CLI + || + \defined( 'PRONAMIC_AS_CONTEXT' ) + ); + } + /** * Send request with the specified action and parameters * @@ -117,6 +133,7 @@ public function send_request( $url, $method = 'GET', $data = null ) { 'headers' => [ 'Authorization' => 'Bearer ' . $this->api_key, ], + 'timeout' => $this->should_increase_http_timeout() ? 30 : 5, ]; if ( null !== $data ) {