Skip to content

Commit

Permalink
Possible fix for pronamic/wp-pay-core#170.
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed Jan 22, 2024
1 parent 19f65f8 commit 991423b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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 ) {
Expand Down

0 comments on commit 991423b

Please sign in to comment.