From ec624193eba66533046670cdc0e76a5463e7b089 Mon Sep 17 00:00:00 2001 From: Anthony Burchell Date: Mon, 19 Oct 2020 20:27:34 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@49207 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/css/edit.css | 16 +++++++++++++ src/wp-admin/includes/media.php | 32 +++++++++++++++++++++++++- src/wp-includes/media-template.php | 37 ++++++++++++++++-------------- src/wp-includes/media.php | 17 ++++---------- 4 files changed, 71 insertions(+), 31 deletions(-) diff --git a/src/wp-admin/css/edit.css b/src/wp-admin/css/edit.css index 9f63a9bb2e..ef7a39940e 100644 --- a/src/wp-admin/css/edit.css +++ b/src/wp-admin/css/edit.css @@ -458,6 +458,8 @@ form#tags-filter { #post-body .misc-pub-post-status:before, #post-body #visibility:before, .curtime #timestamp:before, +#post-body .misc-pub-uploadedby:before, +#post-body .misc-pub-uploadedto:before, #post-body .misc-pub-revisions:before, #post-body .misc-pub-response-to:before, #post-body .misc-pub-comment-status:before { @@ -467,6 +469,8 @@ form#tags-filter { #post-body .misc-pub-post-status:before, #post-body #visibility:before, .curtime #timestamp:before, +#post-body .misc-pub-uploadedby:before, +#post-body .misc-pub-uploadedto:before, #post-body .misc-pub-revisions:before, #post-body .misc-pub-response-to:before, #post-body .misc-pub-comment-status:before { @@ -495,6 +499,18 @@ form#tags-filter { top: -1px; } +#post-body .misc-pub-uploadedby:before { + content: "\f110"; + position: relative; + top: -1px; +} + +#post-body .misc-pub-uploadedto:before { + content: "\f318"; + position: relative; + top: -1px; +} + #post-body .misc-pub-revisions:before { content: "\f321"; } diff --git a/src/wp-admin/includes/media.php b/src/wp-admin/includes/media.php index 1efea2f0ee..0859180d2c 100644 --- a/src/wp-admin/includes/media.php +++ b/src/wp-admin/includes/media.php @@ -3288,7 +3288,37 @@ function attachment_submitbox_metadata() { $att_url = wp_get_attachment_url( $attachment_id ); - ?> + $author = get_userdata( $post->post_author ); + + $uploaded_by_name = __( '(no author)' ); + $uploaded_by_link = ''; + if ( $author->exists() ) { + $uploaded_by_name = $author->display_name ? $author->display_name : $author->nickname; + $uploaded_by_link = get_edit_user_link( $author->ID ); + } ?> +
+ + + + + +
+ + post_parent ) : + $post_parent = get_post( $post->post_parent ); + if ( $post_parent ) : + $uploaded_to_title = $post_parent->post_title ? $post_parent->post_title : __( '(no title)' ); + $uploaded_to_link = get_edit_post_link( $post->post_parent, 'raw' ); ?> +
+ + + + + +
+ + +
diff --git a/src/wp-includes/media-template.php b/src/wp-includes/media-template.php index c14b7f4793..af418dd2e7 100644 --- a/src/wp-includes/media-template.php +++ b/src/wp-includes/media-template.php @@ -405,10 +405,27 @@ function wp_print_media_templates() {

-
{{ data.filename }}
-
{{ data.mime }}
{{ data.dateFormatted }}
- +
+ + <# if ( data.authorLink ) { #> + {{ data.authorName }} + <# } else { #> + {{ data.authorName }} + <# } #> +
+ <# if ( data.uploadedToTitle ) { #> +
+ + <# if ( data.uploadedToLink ) { #> + {{ data.uploadedToTitle }} + <# } else { #> + {{ data.uploadedToTitle }} + <# } #> +
+ <# } #> +
{{ data.filename }}
+
{{ data.mime }}
{{ data.filesizeHumanReadable }}
<# if ( 'image' === data.type && ! data.uploading ) { #> <# if ( data.width && data.height ) { #> @@ -485,20 +502,6 @@ function wp_print_media_templates() { - - - {{ data.authorName }} - - <# if ( data.uploadedToTitle ) { #> - - - <# if ( data.uploadedToLink ) { #> - {{ data.uploadedToTitle }} - <# } else { #> - {{ data.uploadedToTitle }} - <# } #> - - <# } #> diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 383ad9930f..a73544b588 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -3809,26 +3809,17 @@ function wp_prepare_attachment_for_js( $attachment ) { $author = new WP_User( $attachment->post_author ); if ( $author->exists() ) { - $response['authorName'] = html_entity_decode( $author->display_name, ENT_QUOTES, get_bloginfo( 'charset' ) ); + $response['authorName'] = html_entity_decode( $author->display_name ? $author->display_name : $author->nickname, ENT_QUOTES, get_bloginfo( 'charset' ) ); + $response['authorLink'] = get_edit_user_link( $author->ID ); } else { $response['authorName'] = __( '(no author)' ); } if ( $attachment->post_parent ) { $post_parent = get_post( $attachment->post_parent ); - } else { - $post_parent = false; - } - - if ( $post_parent ) { - $parent_type = get_post_type_object( $post_parent->post_type ); - - if ( $parent_type && $parent_type->show_ui && current_user_can( 'edit_post', $attachment->post_parent ) ) { - $response['uploadedToLink'] = get_edit_post_link( $attachment->post_parent, 'raw' ); - } - - if ( $parent_type && current_user_can( 'read_post', $attachment->post_parent ) ) { + if ( $post_parent ) { $response['uploadedToTitle'] = $post_parent->post_title ? $post_parent->post_title : __( '(no title)' ); + $response['uploadedToLink'] = get_edit_post_link( $attachment->post_parent, 'raw' ); } }