This commit is contained in:
Javier Casares 2026-09-23 06:09:05 +00:00
commit 27ce69c2d2
9 changed files with 188 additions and 61 deletions

View file

@ -322,7 +322,13 @@ class Robotstxt_Manager_Core_Client {
$typed = array();
foreach ( $cached as $slug => $row ) {
if ( is_string( $slug ) && is_array( $row ) ) {
$typed[ $slug ] = $row;
$typed_row = array();
foreach ( $row as $k => $v ) {
if ( is_string( $k ) ) {
$typed_row[ $k ] = $v;
}
}
$typed[ $slug ] = $typed_row;
}
}
@ -399,6 +405,12 @@ class Robotstxt_Manager_Core_Client {
* Exchanges the account API key for a short-lived download token
* (Core 1.9.0+ `POST /me/download-token`).
*
* Tokens are cached in a short-TTL site transient (5 minutes, a fraction
* of the 15-minute token lifetime) because the updater rebuilds package
* URLs on every read of the update_plugins transient. Failed exchanges
* are negatively cached for one minute so a slow or down store is not
* queried on every read either.
*
* @param string $slug Plugin slug the token may download.
*
* @return string Token string, or '' when unavailable (older Core, no
@ -410,6 +422,13 @@ class Robotstxt_Manager_Core_Client {
return '';
}
$cache_key = 'robotstxt_manager_dl_token_' . sanitize_key( $slug );
$cached = get_site_transient( $cache_key );
if ( is_string( $cached ) ) {
return $cached; // Token, or '' from a negatively cached failure.
}
// Send this site's domain so per-domain license binding is enforced
// at token issuance (Core 1.11.0+); older Core ignores the field.
$host = strtolower( (string) wp_parse_url( home_url(), PHP_URL_HOST ) );
@ -434,14 +453,25 @@ class Robotstxt_Manager_Core_Client {
);
if ( is_wp_error( $response ) || 200 !== (int) wp_remote_retrieve_response_code( $response ) ) {
set_site_transient( $cache_key, '', MINUTE_IN_SECONDS );
return '';
}
$data = json_decode( wp_remote_retrieve_body( $response ), true );
$token = is_array( $data ) ? ( $data['token'] ?? '' ) : '';
$token = is_string( $token ) ? $token : '';
return is_string( $token ) ? $token : '';
if ( '' === $token ) {
set_site_transient( $cache_key, '', MINUTE_IN_SECONDS );
return '';
}
set_site_transient( $cache_key, $token, 5 * MINUTE_IN_SECONDS );
return $token;
}
/**