Make WordPress Core


Ignore:
Timestamp:
06/27/2023 04:26:15 PM (15 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-media-list-table.php

    r56023 r56072  
    817817            }
    818818
    819             $actions['copy'] = sprintf(
    820                 '<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>',
     819            if ( $attachment_url ) {
     820                $actions['copy'] = sprintf(
     821                    '<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>',
     822                    esc_url( $attachment_url ),
     823                    /* translators: %s: Attachment title. */
     824                    esc_attr( sprintf( __( 'Copy &#8220;%s&#8221; URL to clipboard' ), $att_title ) ),
     825                    __( 'Copy URL' ),
     826                    __( 'Copied!' )
     827                );
     828            }
     829        }
     830
     831        if ( $attachment_url ) {
     832            $actions['download'] = sprintf(
     833                '<a href="%s" aria-label="%s" download>%s</a>',
    821834                esc_url( $attachment_url ),
    822835                /* translators: %s: Attachment title. */
    823                 esc_attr( sprintf( __( 'Copy &#8220;%s&#8221; URL to clipboard' ), $att_title ) ),
    824                 __( 'Copy URL' ),
    825                 __( 'Copied!' )
     836                esc_attr( sprintf( __( 'Download &#8220;%s&#8221;' ), $att_title ) ),
     837                __( 'Download file' )
    826838            );
    827839        }
    828 
    829         $actions['download'] = sprintf(
    830             '<a href="%s" aria-label="%s" download>%s</a>',
    831             esc_url( $attachment_url ),
    832             /* translators: %s: Attachment title. */
    833             esc_attr( sprintf( __( 'Download &#8220;%s&#8221;' ), $att_title ) ),
    834             __( 'Download file' )
    835         );
    836840
    837841        if ( $this->detached && current_user_can( 'edit_post', $post->ID ) ) {
Note: See TracChangeset for help on using the changeset viewer.