v0.5.1
This commit is contained in:
parent
90ac22a845
commit
061329c704
11 changed files with 114 additions and 25 deletions
|
|
@ -146,8 +146,18 @@ class Robotstxt_Manager_Core_Client {
|
|||
);
|
||||
}
|
||||
|
||||
$body = wp_remote_retrieve_body( $response );
|
||||
$count = is_array( json_decode( $body, true ) ) ? count( json_decode( $body, true ) ) : 0;
|
||||
$code = (int) wp_remote_retrieve_response_code( $response );
|
||||
|
||||
if ( 200 !== $code ) {
|
||||
return array(
|
||||
'ok' => false,
|
||||
/* translators: %d: HTTP status code. */
|
||||
'message' => sprintf( __( 'The store responded with HTTP %d. Check the Store URL and API key.', 'robotstxt-manager' ), $code ),
|
||||
);
|
||||
}
|
||||
|
||||
$decoded = json_decode( wp_remote_retrieve_body( $response ), true );
|
||||
$count = is_array( $decoded ) ? count( $decoded ) : 0;
|
||||
|
||||
return array(
|
||||
'ok' => true,
|
||||
|
|
@ -191,6 +201,12 @@ class Robotstxt_Manager_Core_Client {
|
|||
return array();
|
||||
}
|
||||
|
||||
// A non-200 response (auth failure, outage) must not be cached as an
|
||||
// "empty catalog" for the full TTL — return nothing and retry next time.
|
||||
if ( 200 !== (int) wp_remote_retrieve_response_code( $response ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$body = wp_remote_retrieve_body( $response );
|
||||
$data = json_decode( $body, true );
|
||||
|
||||
|
|
|
|||
|
|
@ -92,6 +92,13 @@ class Robotstxt_Manager_Updater {
|
|||
}
|
||||
|
||||
if ( version_compare( $version, $new_version, '<' ) ) {
|
||||
// Premium updates need the account key in the package URL;
|
||||
// without a usable key the native updater would only hit a
|
||||
// 403, so skip injecting the entry.
|
||||
if ( 'premium' === $entry['type'] && ! $this->has_api_key() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( property_exists( $transient, 'response' ) && is_array( $transient->response ) ) {
|
||||
$transient->response[ $plugin_file ] = $this->build_update_object( $slug, (string) $plugin_file, $entry );
|
||||
}
|
||||
|
|
@ -260,6 +267,18 @@ class Robotstxt_Manager_Updater {
|
|||
return (object) $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a decryptable account API key is configured.
|
||||
*
|
||||
* @return bool True when a usable key exists.
|
||||
*/
|
||||
private function has_api_key(): bool {
|
||||
$api_key_raw = get_option( 'robotstxt_manager_api_key', '' );
|
||||
$api_key = is_string( $api_key_raw ) ? Robotstxt_Manager_Encryption::decrypt( $api_key_raw ) : '';
|
||||
|
||||
return '' !== $api_key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the download package URL for the native upgrader.
|
||||
*
|
||||
|
|
@ -298,9 +317,10 @@ class Robotstxt_Manager_Updater {
|
|||
* @return string Domain (e.g. 'example.com').
|
||||
*/
|
||||
private function site_domain(): string {
|
||||
$host = (string) wp_parse_url( home_url(), PHP_URL_HOST );
|
||||
$host = strtolower( (string) wp_parse_url( home_url(), PHP_URL_HOST ) );
|
||||
|
||||
return strtolower( ltrim( $host, 'www.' ) );
|
||||
// Strip the literal "www." prefix (ltrim would eat any leading w/.).
|
||||
return (string) preg_replace( '/^www\./', '', $host );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue