This commit is contained in:
Javier Casares 2026-09-23 06:11:14 +00:00
commit bb3beaa353
12 changed files with 465 additions and 147 deletions

View file

@ -379,7 +379,9 @@ class Robotstxt_Manager_Installer {
}
/**
* Updates an installed plugin to the latest catalog version.
* Updates an installed plugin to the latest catalog version or, when a
* security patch is declared for the exact installed version (Core
* 1.16.0+), to that patch instead of the feature mainline.
*
* @return void
*/
@ -394,7 +396,17 @@ class Robotstxt_Manager_Installer {
$this->redirect_error( __( 'Plugin is not installed.', 'robotstxt-manager' ) );
}
$result = $this->download_and_install( $slug, true );
$patch = '';
$entry = $this->find_catalog_entry( $slug );
if ( is_array( $entry ) ) {
$all = get_plugins();
$version = isset( $all[ $file ]['Version'] ) && is_string( $all[ $file ]['Version'] ) ? $all[ $file ]['Version'] : '';
$patch = Robotstxt_Manager_Updater::security_patch_for( $entry, $version );
}
$result = $this->download_and_install( $slug, true, $patch );
if ( is_wp_error( $result ) ) {
$this->redirect_error( $result->get_error_message() );
@ -502,10 +514,12 @@ class Robotstxt_Manager_Installer {
*
* @param string $slug Plugin slug.
* @param bool $overwrite Whether to overwrite an existing install (update).
* @param string $security_version Patch version to download instead of the
* stable mainline (Core 1.16.0+), '' for stable.
*
* @return true|WP_Error True on success.
*/
private function download_and_install( string $slug, bool $overwrite = false ) {
private function download_and_install( string $slug, bool $overwrite = false, string $security_version = '' ) {
$client = Robotstxt_Manager_Core_Client::from_options();
if ( ! $client->is_configured() ) {
@ -529,15 +543,26 @@ class Robotstxt_Manager_Installer {
// fetched directly (no auth). Everything else goes through Core's
// authenticated download endpoint (account API key as Bearer), with
// this site's domain for per-domain license binding (Core 1.11.0+).
$use_download_endpoint = ! ( $is_free && '' !== $dl_url );
// Security patches always stream through the endpoint with a version
// parameter — the public URL only carries the mainline stable ZIP.
$use_download_endpoint = '' !== $security_version || ! ( $is_free && '' !== $dl_url );
$zip_url = $use_download_endpoint
? add_query_arg(
'domain',
rawurlencode( $this->site_domain() ),
if ( $use_download_endpoint ) {
$dl_args = array(
'domain' => rawurlencode( $this->site_domain() ),
);
if ( '' !== $security_version ) {
$dl_args['version'] = rawurlencode( $security_version );
}
$zip_url = add_query_arg(
$dl_args,
$client->get_store_url() . '/wp-json/robotstxt-core/v1/plugins/' . rawurlencode( $slug ) . '/download'
)
: $dl_url;
);
} else {
$zip_url = $dl_url;
}
$tmp_file = wp_tempnam( $slug . '.zip' );