Skip to content

Commit

Permalink
Merge pull request #42 from Siteimprove/INS-2874
Browse files Browse the repository at this point in the history
INS-2874: Refactoring code to fix a problem with some clients API credentials
  • Loading branch information
jespernpedersen authored Mar 27, 2024
2 parents 8e44ccc + 6bad19c commit 4a5c8f8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
52 changes: 20 additions & 32 deletions siteimprove/admin/partials/class-siteimprove-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,47 +572,35 @@ public static function check_credentials( $username, $key ) {
return $return;
}

$request = self::make_api_request( $username, $key, '/sites' );
$request = self::make_api_request( $username, $key, '/sites?page_size=1000' );

if ( isset( $request['response'] ) && 200 === $request['response']['code'] ) {
$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;
$results = json_decode( $request['body'] );
$account_sites = $results->items;

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

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

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

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

if ( false === $site_found ) {
$return['error'] = __( 'Current domain/website not found for the provided credentials.', 'siteimprove' );
if ( true === $site_found ) {
$return = array(
'status' => 'true',
);
} else {
$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
2 changes: 1 addition & 1 deletion siteimprove/siteimprove.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Plugin Name: Siteimprove Plugin
* Plugin URI: https://www.siteimprove.com/integrations/cms-plugin/wordpress/
* Description: Integration with Siteimprove.
* Version: 2.0.5
* Version: 2.0.6
* Author: Siteimprove
* Author URI: http://www.siteimprove.com/
* Requires at least: 4.7.2
Expand Down

0 comments on commit 4a5c8f8

Please sign in to comment.