This commit is contained in:
Javier Casares 2026-08-15 12:40:32 +00:00
commit 061329c704
11 changed files with 114 additions and 25 deletions

View file

@ -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 );
}
/**