Skip to content

Conversation

@costdev
Copy link
Member

@costdev costdev commented Aug 19, 2025

This PR ensures that the directory name of a FAIR package is renamed to slug-didhash on installation.

In particular, this deals with the installation of a package without knowing its DID in advance. For example, when uploading the ZIP file of a plugin or theme.

See #228

@costdev costdev requested a review from afragen August 19, 2025 20:46
@costdev costdev force-pushed the move_package_on_install branch from 6c0bbec to c8497ef Compare August 19, 2025 20:54
@afragen
Copy link
Contributor

afragen commented Aug 20, 2025

We already do this on direct install,

function rename_source_selection( string $source, string $remote_source, WP_Upgrader $upgrader ) {
global $wp_filesystem;
$did = wp_cache_get( Admin\ACTION_INSTALL_DID );
if ( ! $did ) {
return $source;
}
$metadata = fetch_package_metadata( $did );
if ( is_wp_error( $metadata ) ) {
return $metadata;
}
// Sanity check.
if ( $upgrader->new_plugin_data['Name'] !== $metadata->name ) {
return $source;
}
if ( str_contains( $source, get_did_hash( $did ) ) && basename( $source ) === $metadata->slug ) {
return $source;
}
$new_source = trailingslashit( $remote_source ) . $metadata->slug . '-' . get_did_hash( $did );
if ( trailingslashit( strtolower( $source ) ) !== trailingslashit( strtolower( $new_source ) ) ) {
$wp_filesystem->move( $source, $new_source, true );
}
return trailingslashit( $new_source );
}

@costdev
Copy link
Member Author

costdev commented Aug 20, 2025

That covers the "Direct Install" tab, whereas this covers the "Upload ZIP" or wp plugin install <URL|path/to/zip> install paths.

@Ipstenu
Copy link
Contributor

Ipstenu commented Oct 27, 2025

@costdev Where are we here? Is this ready for 1.1?

@Ipstenu Ipstenu added question Further information is requested enhancement New feature or request labels Oct 27, 2025
In particular, this deals with the installation of a package without knowing its DID in advance. For example, when uploading the ZIP file of a plugin or theme.

Signed-off-by: costdev <[email protected]>
Signed-off-by: costdev <[email protected]>
@costdev costdev force-pushed the move_package_on_install branch from 2ec0043 to ea638e1 Compare October 27, 2025 19:23
@costdev
Copy link
Member Author

costdev commented Oct 27, 2025

@Ipstenu Just rebased the PR branch on main. It's ready for testing again.

🧪 Test this PR on Playground

@afragen
Copy link
Contributor

afragen commented Oct 28, 2025

I think https://github.com/afragen/fair-plugin/tree/rename-theme-on-download also solves issue with at least some code reuse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants