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 ) {