Media: Only show “Copy” and “Download” actions when an attachment URL is available.

Includes unit tests to verify the logic for displaying row actions in the Media Library in certain scenarios, e.g. with and without the “Trash” or “Unattached” filter.

Follow-up to [55949].

Props costdev, kebbet, mukesh27, oglekler.
Fixes #57893.
Built from https://develop.svn.wordpress.org/trunk@56072


git-svn-id: http://core.svn.wordpress.org/trunk@55584 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2023-06-27 16:29:28 +00:00
parent 955720d678
commit 26a0bf0049
2 changed files with 20 additions and 16 deletions

View File

@ -816,23 +816,27 @@ class WP_Media_List_Table extends WP_List_Table {
);
}
$actions['copy'] = sprintf(
'<span class="copy-to-clipboard-container"><button type="button" class="button-link copy-attachment-url media-library" data-clipboard-text="%s" aria-label="%s">%s</button><span class="success hidden" aria-hidden="true">%s</span></span>',
esc_url( $attachment_url ),
/* translators: %s: Attachment title. */
esc_attr( sprintf( __( 'Copy &#8220;%s&#8221; URL to clipboard' ), $att_title ) ),
__( 'Copy URL' ),
__( 'Copied!' )
);
if ( $attachment_url ) {
$actions['copy'] = sprintf(
'<span class="copy-to-clipboard-container"><button type="button" class="button-link copy-attachment-url media-library" data-clipboard-text="%s" aria-label="%s">%s</button><span class="success hidden" aria-hidden="true">%s</span></span>',
esc_url( $attachment_url ),
/* translators: %s: Attachment title. */
esc_attr( sprintf( __( 'Copy &#8220;%s&#8221; URL to clipboard' ), $att_title ) ),
__( 'Copy URL' ),
__( 'Copied!' )
);
}
}
$actions['download'] = sprintf(
'<a href="%s" aria-label="%s" download>%s</a>',
esc_url( $attachment_url ),
/* translators: %s: Attachment title. */
esc_attr( sprintf( __( 'Download &#8220;%s&#8221;' ), $att_title ) ),
__( 'Download file' )
);
if ( $attachment_url ) {
$actions['download'] = sprintf(
'<a href="%s" aria-label="%s" download>%s</a>',
esc_url( $attachment_url ),
/* translators: %s: Attachment title. */
esc_attr( sprintf( __( 'Download &#8220;%s&#8221;' ), $att_title ) ),
__( 'Download file' )
);
}
if ( $this->detached && current_user_can( 'edit_post', $post->ID ) ) {
$actions['attach'] = sprintf(

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.3-alpha-56071';
$wp_version = '6.3-alpha-56072';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.