Make WordPress Core

Changeset 49207


Ignore:
Timestamp:
10/19/2020 08:27:34 PM (4 years ago)
Author:
antpb
Message:

Media: Add 'Uploaded to' for individual media items in the media editor.
Adds a link in the media editor showing which post a media item was uploaded to.
Props karmatosed, garrett-eclipse, Mista-Flo, SergeyBiryukov, joemcgill, hellofromTonya.
Fixes #46866.

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/css/edit.css

    r49179 r49207  
    459459#post-body #visibility:before,
    460460.curtime #timestamp:before,
     461#post-body .misc-pub-uploadedby:before,
     462#post-body .misc-pub-uploadedto:before,
    461463#post-body .misc-pub-revisions:before,
    462464#post-body .misc-pub-response-to:before,
     
    468470#post-body #visibility:before,
    469471.curtime #timestamp:before,
     472#post-body .misc-pub-uploadedby:before,
     473#post-body .misc-pub-uploadedto:before,
    470474#post-body .misc-pub-revisions:before,
    471475#post-body .misc-pub-response-to:before,
     
    492496.curtime #timestamp:before {
    493497    content: "\f145";
     498    position: relative;
     499    top: -1px;
     500}
     501
     502#post-body .misc-pub-uploadedby:before {
     503    content: "\f110";
     504    position: relative;
     505    top: -1px;
     506}
     507
     508#post-body .misc-pub-uploadedto:before {
     509    content: "\f318";
    494510    position: relative;
    495511    top: -1px;
  • trunk/src/wp-admin/includes/media.php

    r49198 r49207  
    32893289    $att_url = wp_get_attachment_url( $attachment_id );
    32903290
    3291     ?>
     3291    $author = get_userdata( $post->post_author );
     3292
     3293    $uploaded_by_name = __( '(no author)' );
     3294    $uploaded_by_link = '';
     3295    if ( $author->exists() ) {
     3296        $uploaded_by_name = $author->display_name ? $author->display_name : $author->nickname;
     3297        $uploaded_by_link = get_edit_user_link( $author->ID );
     3298    } ?>
     3299    <div class="misc-pub-section misc-pub-uploadedby">
     3300        <?php if ( $uploaded_by_link ) : ?>
     3301            <?php _e( 'Uploaded by:' ); ?> <a href="<?php echo $uploaded_by_link ?>"><strong><?php echo $uploaded_by_name ?></strong></a>
     3302        <?php else: ?>
     3303            <?php _e( 'Uploaded by:' ); ?> <strong><?php echo $uploaded_by_name ?></strong>
     3304        <?php endif; ?>
     3305    </div>
     3306
     3307    <?php if ( $post->post_parent ) :
     3308        $post_parent = get_post( $post->post_parent );
     3309        if ( $post_parent ) :
     3310            $uploaded_to_title = $post_parent->post_title ? $post_parent->post_title : __( '(no title)' );
     3311            $uploaded_to_link = get_edit_post_link( $post->post_parent, 'raw' ); ?>
     3312            <div class="misc-pub-section misc-pub-uploadedto">
     3313                <?php if ( $uploaded_to_link ) : ?>
     3314                    <?php _e( 'Uploaded to:' ); ?> <a href="<?php echo $uploaded_to_link ?>"><strong><?php echo $uploaded_to_title; ?></strong></a>
     3315                <?php else: ?>
     3316                    <?php _e( 'Uploaded to:' ); ?> <strong><?php echo $uploaded_to_title; ?></strong>
     3317                <?php endif; ?>
     3318            </div>
     3319        <?php endif; ?>
     3320    <?php endif; ?>
     3321
    32923322    <div class="misc-pub-section misc-pub-attachment">
    32933323        <label for="attachment_url"><?php _e( 'File URL:' ); ?></label>
  • trunk/src/wp-includes/media-template.php

    r49195 r49207  
    406406            <div class="details">
    407407                <h2 class="screen-reader-text"><?php _e( 'Details' ); ?></h2>
     408                <div class="uploaded"><strong><?php _e( 'Uploaded on:' ); ?></strong> {{ data.dateFormatted }}</div>
     409                <div class="uploaded-by">
     410                    <strong><?php _e( 'Uploaded by:' ); ?></strong>
     411                        <# if ( data.authorLink ) { #>
     412                            <a href="{{ data.authorLink }}">{{ data.authorName }}</a>
     413                        <# } else { #>
     414                            {{ data.authorName }}
     415                        <# } #>
     416                </div>
     417                <# if ( data.uploadedToTitle ) { #>
     418                    <div class="uploaded-to">
     419                        <strong><?php _e( 'Uploaded to:' ); ?></strong>
     420                        <# if ( data.uploadedToLink ) { #>
     421                            <a href="{{ data.uploadedToLink }}">{{ data.uploadedToTitle }}</a>
     422                        <# } else { #>
     423                            {{ data.uploadedToTitle }}
     424                        <# } #>
     425                    </div>
     426                <# } #>
    408427                <div class="filename"><strong><?php _e( 'File name:' ); ?></strong> {{ data.filename }}</div>
    409                 <div class="filename"><strong><?php _e( 'File type:' ); ?></strong> {{ data.mime }}</div>
    410                 <div class="uploaded"><strong><?php _e( 'Uploaded on:' ); ?></strong> {{ data.dateFormatted }}</div>
    411 
     428                <div class="file-type"><strong><?php _e( 'File type:' ); ?></strong> {{ data.mime }}</div>
    412429                <div class="file-size"><strong><?php _e( 'File size:' ); ?></strong> {{ data.filesizeHumanReadable }}</div>
    413430                <# if ( 'image' === data.type && ! data.uploading ) { #>
     
    486503                    <textarea id="attachment-details-two-column-description" {{ maybeReadOnly }}>{{ data.description }}</textarea>
    487504                </span>
    488                 <span class="setting">
    489                     <span class="name"><?php _e( 'Uploaded By' ); ?></span>
    490                     <span class="value">{{ data.authorName }}</span>
    491                 </span>
    492                 <# if ( data.uploadedToTitle ) { #>
    493                     <span class="setting">
    494                         <span class="name"><?php _e( 'Uploaded To' ); ?></span>
    495                         <# if ( data.uploadedToLink ) { #>
    496                             <span class="value"><a href="{{ data.uploadedToLink }}">{{ data.uploadedToTitle }}</a></span>
    497                         <# } else { #>
    498                             <span class="value">{{ data.uploadedToTitle }}</span>
    499                         <# } #>
    500                     </span>
    501                 <# } #>
    502505                <span class="setting" data-setting="url">
    503506                    <label for="attachment-details-two-column-copy-link" class="name"><?php _e( 'File URL:' ); ?></label>
  • trunk/src/wp-includes/media.php

    r49193 r49207  
    38103810    $author = new WP_User( $attachment->post_author );
    38113811    if ( $author->exists() ) {
    3812         $response['authorName'] = html_entity_decode( $author->display_name, ENT_QUOTES, get_bloginfo( 'charset' ) );
     3812        $response['authorName'] = html_entity_decode( $author->display_name ? $author->display_name : $author->nickname, ENT_QUOTES, get_bloginfo( 'charset' ) );
     3813        $response['authorLink'] = get_edit_user_link( $author->ID );
    38133814    } else {
    38143815        $response['authorName'] = __( '(no author)' );
     
    38173818    if ( $attachment->post_parent ) {
    38183819        $post_parent = get_post( $attachment->post_parent );
    3819     } else {
    3820         $post_parent = false;
    3821     }
    3822 
    3823     if ( $post_parent ) {
    3824         $parent_type = get_post_type_object( $post_parent->post_type );
    3825 
    3826         if ( $parent_type && $parent_type->show_ui && current_user_can( 'edit_post', $attachment->post_parent ) ) {
    3827             $response['uploadedToLink'] = get_edit_post_link( $attachment->post_parent, 'raw' );
    3828         }
    3829 
    3830         if ( $parent_type && current_user_can( 'read_post', $attachment->post_parent ) ) {
     3820        if ( $post_parent ) {
    38313821            $response['uploadedToTitle'] = $post_parent->post_title ? $post_parent->post_title : __( '(no title)' );
     3822            $response['uploadedToLink']  = get_edit_post_link( $attachment->post_parent, 'raw' );
    38323823        }
    38333824    }
Note: See TracChangeset for help on using the changeset viewer.