@@ -838,6 +838,9 @@ function image_link_input_fields($post, $url_type='') {
838838function image_attachment_fields_to_edit ($ form_fields , $ post ) {
839839 if ( substr ($ post ->post_mime_type , 0 , 5 ) == 'image ' ) {
840840 $ form_fields ['post_title ' ]['required ' ] = true ;
841+ $ file = wp_get_attachment_url ($ post ->ID );
842+
843+ $ form_fields ['image_url ' ]['value ' ] = $ file ;
841844
842845 $ form_fields ['post_excerpt ' ]['label ' ] = __ ('Caption ' );
843846 $ form_fields ['post_excerpt ' ]['helps ' ][] = __ ('Also used as alternate text for the image ' );
@@ -871,6 +874,11 @@ function media_single_attachment_fields_to_edit( $form_fields, $post ) {
871874 return $ form_fields ;
872875}
873876
877+ function media_post_single_attachment_fields_to_edit ( $ form_fields , $ post ) {
878+ unset($ form_fields ['image_url ' ]);
879+ return $ form_fields ;
880+ }
881+
874882/**
875883 * {@internal Missing Short Description}}
876884 *
@@ -943,6 +951,8 @@ function get_attachment_fields_to_edit($post, $errors = null) {
943951 if ( is_array ($ post ) )
944952 $ post = (object ) $ post ;
945953
954+ $ image_url = wp_get_attachment_url ($ post ->ID );
955+
946956 $ edit_post = sanitize_post ($ post , 'edit ' );
947957
948958 $ form_fields = array (
@@ -969,6 +979,13 @@ function get_attachment_fields_to_edit($post, $errors = null) {
969979 'label ' => __ ('Order ' ),
970980 'value ' => $ edit_post ->menu_order
971981 ),
982+ 'image_url ' => array (
983+ 'label ' => __ ('File URL ' ),
984+ 'input ' => 'html ' ,
985+ 'html ' => "<input type='text' class='urlfield' readonly='readonly' name='attachments[ $ post ->ID ][url]' value=' " . attribute_escape ($ image_url ) . "' /><br /> " ,
986+ 'value ' => $ edit_post ->post_url ,
987+ 'helps ' => __ ('Location of the uploaded file. ' ),
988+ )
972989 );
973990
974991 foreach ( get_attachment_taxonomies ($ post ) as $ taxonomy ) {
@@ -1371,6 +1388,7 @@ function media_upload_type_form($type = 'file', $errors = null, $id = null) {
13711388<?php
13721389if ( $ id ) {
13731390 if ( !is_wp_error ($ id ) ) {
1391+ add_filter ('attachment_fields_to_edit ' , 'media_post_single_attachment_fields_to_edit ' , 10 , 2 );
13741392 echo get_media_items ( $ id , $ errors );
13751393 } else {
13761394 echo '<div id="media-upload-error"> ' .wp_specialchars ($ id ->get_error_message ()).'</div> ' ;
@@ -1537,6 +1555,7 @@ function media_upload_gallery_form($errors) {
15371555</tr></thead>
15381556</table>
15391557<div id="media-items">
1558+ <?php add_filter ('attachment_fields_to_edit ' , 'media_post_single_attachment_fields_to_edit ' , 10 , 2 ); ?>
15401559<?php echo get_media_items ($ post_id , $ errors ); ?>
15411560</div>
15421561
@@ -1770,6 +1789,7 @@ function media_upload_library_form($errors) {
17701789</script>
17711790
17721791<div id="media-items">
1792+ <?php add_filter ('attachment_fields_to_edit ' , 'media_post_single_attachment_fields_to_edit ' , 10 , 2 ); ?>
17731793<?php echo get_media_items (null , $ errors ); ?>
17741794</div>
17751795<p class="ml-submit">
0 commit comments