Skip to content

Commit

Permalink
Merge pull request #41 from Siteimprove/INS-2874
Browse files Browse the repository at this point in the history
INS-2874: fixing a problem with some clients API credentials
  • Loading branch information
Flavio-Almeida authored Dec 22, 2023
2 parents 7de4954 + d4f23c4 commit 8e44ccc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ The code on this repository has to match the WordPress Coding Standards in order
Every pull request will be checked against WPCS through GitHub Actions.

## Version History
### 2.0.6
* Bugfix - Fixed an issue when some users tried saving their API credentials

### 2.0.5
* Updated - Siteimprove logo

Expand Down
50 changes: 31 additions & 19 deletions siteimprove/admin/partials/class-siteimprove-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,32 +575,44 @@ public static function check_credentials( $username, $key ) {
$request = self::make_api_request( $username, $key, '/sites' );

if ( isset( $request['response'] ) && 200 === $request['response']['code'] ) {
$results = json_decode( $request['body'] );
$account_sites = $results->items;
$results = json_decode( $request['body'] );
$total_pages_result = $results->total_pages;
$site_found = false;
$public_url = get_option( 'siteimprove_public_url' );

for ( $i = 0; $i < $total_pages_result; $i++ ) {
if ( 1 < $total_pages_result && 1 < ( $i + 1 ) ) {
$request = self::make_api_request( $username, $key, '/sites?page=' . $i + 1 );
}
if ( isset( $request['response'] ) && 200 === $request['response']['code'] ) {
$results = json_decode( $request['body'] );
$account_sites = $results->items;

$public_url = get_option( 'siteimprove_public_url' );
if ( ! empty( $public_url ) ) {
$site_url = $public_url;
} else {
$site_url = get_site_url();
}

if ( ! empty( $public_url ) ) {
$site_url = $public_url;
} else {
$site_url = get_site_url();
}
$domain = wp_parse_url( $site_url, PHP_URL_HOST );

$domain = wp_parse_url( $site_url, PHP_URL_HOST );
$site_found = false;
foreach ( $account_sites as $site_key => $site_data ) {
if ( false !== strpos( $site_data->url, $domain ) ) {
$site_found = true;

foreach ( $account_sites as $site_key => $site_data ) {
if ( false !== strpos( $site_data->url, $domain ) ) {
$site_found = true;
return array(
'status' => 'true',
);
}
}
} else {
$return['error'] = __( 'Unable to check website domain. Please try again later', 'siteimprove' );
return $return;
}
}

if ( true === $site_found ) {
$return = array(
'status' => 'true',
);
} else {
$return['error'] = __( 'Current domain/website not found for the provided credentials', 'siteimprove' );
if ( false === $site_found ) {
$return['error'] = __( 'Current domain/website not found for the provided credentials.', 'siteimprove' );
}
} else {
$return['error'] = __( 'Unable to check website domain. Please try again later', 'siteimprove' );
Expand Down
3 changes: 3 additions & 0 deletions siteimprove/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ Please review whether you have JavaScript turned off in your browser. We use Jav


== Changelog ==
= 2.0.6 =
* Bugfix - Fixed an issue when some users tried saving their API credentials

= 2.0.5 =
* Updated - Siteimprove logo

Expand Down

0 comments on commit 8e44ccc

Please sign in to comment.