WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/26/2021 01:39:47 AM (5 months ago)
Author:
antpb
Message:

Media: Add button in media upload page for copying the media url.

Adds a button to the media upload page to make copying the url possible on the same page when a media item upload is successful.

Props anotia, ryokuhi, Mista-Flo, lukecarbis, antpb, claytoncollie, shaunandrews, joedolson.
Fixes #51754.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/async-upload.php

    r50505 r51023  
    4949    switch ( $_REQUEST['fetch'] ) {
    5050        case 3:
     51            echo '<div class="attachment-details">';
    5152            $thumb_url = wp_get_attachment_image_src( $id, 'thumbnail', true );
    5253            if ( $thumb_url ) {
    5354                echo '<img class="pinkynail" src="' . esc_url( $thumb_url[0] ) . '" alt="" />';
    5455            }
    55             if ( current_user_can( 'edit_post', $id ) ) {
    56                 echo '<a class="edit-attachment" href="' . esc_url( get_edit_post_link( $id ) ) . '" target="_blank">' . _x( 'Edit', 'media item' ) . '</a>';
    57             } else {
    58                 echo '<span class="edit-attachment">' . _x( 'Success', 'media item' ) . '</span>';
    59             }
     56            // Title shouldn't ever be empty, but use filename just in case.
     57            $file    = get_attached_file( $post->ID );
     58            $fileurl = wp_get_attachment_url( $post->ID );
     59            $title   = $post->post_title ? $post->post_title : wp_basename( $file );
    6060
    61             // Title shouldn't ever be empty, but use filename just in case.
    62             $file  = get_attached_file( $post->ID );
    63             $title = $post->post_title ? $post->post_title : wp_basename( $file );
    64             echo '<div class="filename new"><span class="title">' . esc_html( wp_html_excerpt( $title, 60, '&hellip;' ) ) . '</span></div>';
     61            echo '<div class="filename new"><span class="media-list-title"><strong>' . esc_html( wp_html_excerpt( $title, 60, '&hellip;' ) ) . '</strong></span> <span class="media-list-subtitle">' . basename( $file ) . '</span></div>';
     62            echo '</div>';
     63            ?>
     64            <div class="attachment-tools">
     65                <span class="media-item-copy-container copy-to-clipboard-container edit-attachment">
     66                    <button type="button" class="button button-small copy-attachment-url" data-clipboard-text="<?php echo $fileurl; ?>"><?php _e( 'Copy URL to clipboard' ); ?></button>
     67                    <span class="success hidden" aria-hidden="true"><?php _e( 'Copied!' ); ?></span>
     68                </span>
     69                <?php
     70                if ( current_user_can( 'edit_post', $id ) ) {
     71                    echo '<a class="edit-attachment" href="' . esc_url( get_edit_post_link( $id ) ) . '" target="_blank">' . _x( 'Edit', 'media item' ) . '</a>';
     72                } else {
     73                    echo '<span class="edit-attachment">' . _x( 'Success', 'media item' ) . '</span>';
     74                }
     75                ?>
     76            </div>
     77            <?php
    6578            break;
    6679        case 2:
Note: See TracChangeset for help on using the changeset viewer.