Skip to content

Commit 7736b19

Browse files
authored
Merge pull request #74 from ConvertKit/conditionally-append-get-params
Conditionally append parameters to `GET` requests
2 parents 6a461d5 + ff3f41a commit 7736b19

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/class-convertkit-api-v4.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -1325,12 +1325,19 @@ public function request( $endpoint, $method = 'get', $params = array(), $retry_i
13251325
// Send request.
13261326
switch ( strtolower( $method ) ) {
13271327
case 'get':
1328+
// Build URL.
1329+
$url = $this->get_api_url( $endpoint );
1330+
13281331
// We deliberate don't use add_query_arg(), as this converts double equal signs (typically
13291332
// provided by `start_cursor` and `end_cursor`) to a single equal sign, therefore breaking
13301333
// pagination. http_build_query() will encode equals signs instead, preserving them
13311334
// and ensuring paginated requests work correctly.
1335+
if ( count( $params ) ) {
1336+
$url .= '?' . http_build_query( $params );
1337+
}
1338+
13321339
$result = wp_remote_get(
1333-
$this->get_api_url( $endpoint ) . '?' . http_build_query( $params ),
1340+
$url,
13341341
array(
13351342
'headers' => $this->get_request_headers(),
13361343
'timeout' => $this->get_timeout(),

0 commit comments

Comments
 (0)