Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/247 a $result is used instead of $request #277

Merged
merged 2 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions includes/classes/SiteAutomation/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,26 @@ public function request_access_token( $client_id, $client_secret ) {
/** This filter is documented in includes/classes/SiteAutomation/Request.php */
$args = apply_filters( 'sophi_request_args', $args, $auth_url );

$request = wp_remote_post( $auth_url, $args );
$result = wp_remote_post( $auth_url, $args );

/** This filter is documented in includes/classes/SiteAutomation/Request.php */
$request = apply_filters( 'sophi_request_result', $request, $args, $auth_url );
$result = apply_filters( 'sophi_request_result', $result, $args, $auth_url );

if ( is_wp_error( $request ) ) {
return $request;
if ( is_wp_error( $result ) ) {
return $result;
}

if ( 401 === wp_remote_retrieve_response_code( $request ) ) {
if ( 401 === wp_remote_retrieve_response_code( $result ) ) {
return new \WP_Error( 401, __( 'Invalid credentials! Please confirm your client ID and secret then try again.', 'sophi-wp' ) );
}

if ( 200 !== wp_remote_retrieve_response_code( $request ) ) {
return new \WP_Error( $request['response']['code'], $request['response']['message'] );
if ( 200 !== wp_remote_retrieve_response_code( $result ) ) {
return new \WP_Error( $result['response']['code'], $result['response']['message'] );
}

$response = wp_remote_retrieve_body( $request );
$response = json_decode( $response, true );
$response = wp_remote_retrieve_body( $result );

return $response;
return json_decode( $response, true );
}

/**
Expand Down
22 changes: 11 additions & 11 deletions includes/classes/SiteAutomation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,16 @@ private function request( $timeout ) {
*
* @param {array} $args HTTP request arguments.
* @param {string} $url The request URL.
*
*
* @return {array} HTTP request arguments.
*/
$args = apply_filters( 'sophi_request_args', $args, $this->api_url );

if ( function_exists( 'vip_safe_wp_remote_get' ) ) {
$request = vip_safe_wp_remote_get( $this->api_url, '', 3, $timeout, 20, $args );
$result = vip_safe_wp_remote_get( $this->api_url, '', 3, $timeout, 20, $args );
} else {
$args['timeout'] = $timeout;
$request = wp_remote_get( $this->api_url, $args ); // phpcs:ignore
$result = wp_remote_get( $this->api_url, $args ); // phpcs:ignore
}

/**
Expand All @@ -243,23 +243,23 @@ private function request( $timeout ) {
* @since 1.0.14
* @hook sophi_request_result
*
* @param {array|WP_Error} $request Result of HTTP request.
* @param {array|WP_Error} $result Result of HTTP request.
* @param {array} $args HTTP request arguments.
* @param {string} $url The request URL.
*
*
* @return {array|WP_Error} Result of HTTP request.
*/
$request = apply_filters( 'sophi_request_result', $request, $args, $this->api_url );
$result = apply_filters( 'sophi_request_result', $result, $args, $this->api_url );

if ( is_wp_error( $request ) ) {
return $request;
if ( is_wp_error( $result ) ) {
return $result;
}

if ( wp_remote_retrieve_response_code( $request ) !== 200 ) {
return new \WP_Error( wp_remote_retrieve_response_code( $request ), $request['response']['message'] );
if ( wp_remote_retrieve_response_code( $result ) !== 200 ) {
return new \WP_Error( wp_remote_retrieve_response_code( $result ), $result['response']['message'] );
}

return json_decode( wp_remote_retrieve_body( $request ), true );
return json_decode( wp_remote_retrieve_body( $result ), true );
}

/**
Expand Down