37 if ( ! current_user_can( 'upload_files' ) ) { |
37 if ( ! current_user_can( 'upload_files' ) ) { |
38 wp_die( __( 'Sorry, you are not allowed to upload files.' ) ); |
38 wp_die( __( 'Sorry, you are not allowed to upload files.' ) ); |
39 } |
39 } |
40 |
40 |
41 // Just fetch the detail form for that attachment. |
41 // Just fetch the detail form for that attachment. |
42 if ( isset( $_REQUEST['attachment_id'] ) && intval( $_REQUEST['attachment_id'] ) && $_REQUEST['fetch'] ) { |
42 if ( isset( $_REQUEST['attachment_id'] ) && (int) $_REQUEST['attachment_id'] && $_REQUEST['fetch'] ) { |
43 $id = intval( $_REQUEST['attachment_id'] ); |
43 $id = (int) $_REQUEST['attachment_id']; |
44 $post = get_post( $id ); |
44 $post = get_post( $id ); |
45 if ( 'attachment' !== $post->post_type ) { |
45 if ( 'attachment' !== $post->post_type ) { |
46 wp_die( __( 'Invalid post type.' ) ); |
46 wp_die( __( 'Invalid post type.' ) ); |
47 } |
47 } |
48 |
48 |
49 switch ( $_REQUEST['fetch'] ) { |
49 switch ( $_REQUEST['fetch'] ) { |
50 case 3: |
50 case 3: |
51 $thumb_url = wp_get_attachment_image_src( $id, 'thumbnail', true ); |
51 ?> |
52 if ( $thumb_url ) { |
52 <div class="media-item-wrapper"> |
53 echo '<img class="pinkynail" src="' . esc_url( $thumb_url[0] ) . '" alt="" />'; |
53 <div class="attachment-details"> |
54 } |
54 <?php |
55 if ( current_user_can( 'edit_post', $id ) ) { |
55 $thumb_url = wp_get_attachment_image_src( $id, 'thumbnail', true ); |
56 echo '<a class="edit-attachment" href="' . esc_url( get_edit_post_link( $id ) ) . '" target="_blank">' . _x( 'Edit', 'media item' ) . '</a>'; |
56 if ( $thumb_url ) { |
57 } else { |
57 echo '<img class="pinkynail" src="' . esc_url( $thumb_url[0] ) . '" alt="" />'; |
58 echo '<span class="edit-attachment">' . _x( 'Success', 'media item' ) . '</span>'; |
58 } |
59 } |
|
60 |
59 |
61 // Title shouldn't ever be empty, but use filename just in case. |
60 // Title shouldn't ever be empty, but use filename just in case. |
62 $file = get_attached_file( $post->ID ); |
61 $file = get_attached_file( $post->ID ); |
63 $title = $post->post_title ? $post->post_title : wp_basename( $file ); |
62 $file_url = wp_get_attachment_url( $post->ID ); |
64 echo '<div class="filename new"><span class="title">' . esc_html( wp_html_excerpt( $title, 60, '…' ) ) . '</span></div>'; |
63 $title = $post->post_title ? $post->post_title : wp_basename( $file ); |
|
64 ?> |
|
65 <div class="filename new"> |
|
66 <span class="media-list-title"><strong><?php echo esc_html( wp_html_excerpt( $title, 60, '…' ) ); ?></strong></span> |
|
67 <span class="media-list-subtitle"><?php echo wp_basename( $file ); ?></span> |
|
68 </div> |
|
69 </div> |
|
70 <div class="attachment-tools"> |
|
71 <span class="media-item-copy-container copy-to-clipboard-container edit-attachment"> |
|
72 <button type="button" class="button button-small copy-attachment-url" data-clipboard-text="<?php echo $file_url; ?>"><?php _e( 'Copy URL to clipboard' ); ?></button> |
|
73 <span class="success hidden" aria-hidden="true"><?php _e( 'Copied!' ); ?></span> |
|
74 </span> |
|
75 <?php |
|
76 if ( current_user_can( 'edit_post', $id ) ) { |
|
77 echo '<a class="edit-attachment" href="' . esc_url( get_edit_post_link( $id ) ) . '" target="_blank">' . _x( 'Edit', 'media item' ) . '</a>'; |
|
78 } else { |
|
79 echo '<span class="edit-attachment">' . _x( 'Success', 'media item' ) . '</span>'; |
|
80 } |
|
81 ?> |
|
82 </div> |
|
83 </div> |
|
84 <?php |
65 break; |
85 break; |
66 case 2: |
86 case 2: |
67 add_filter( 'attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2 ); |
87 add_filter( 'attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2 ); |
68 echo get_media_item( |
88 echo get_media_item( |
69 $id, |
89 $id, |
117 $type = $_REQUEST['type']; |
137 $type = $_REQUEST['type']; |
118 |
138 |
119 /** |
139 /** |
120 * Filters the returned ID of an uploaded attachment. |
140 * Filters the returned ID of an uploaded attachment. |
121 * |
141 * |
122 * The dynamic portion of the hook name, `$type`, refers to the attachment type, |
142 * The dynamic portion of the hook name, `$type`, refers to the attachment type. |
123 * such as 'image', 'audio', 'video', 'file', etc. |
143 * |
|
144 * Possible hook names include: |
|
145 * |
|
146 * - `async_upload_audio` |
|
147 * - `async_upload_file` |
|
148 * - `async_upload_image` |
|
149 * - `async_upload_video` |
124 * |
150 * |
125 * @since 2.5.0 |
151 * @since 2.5.0 |
126 * |
152 * |
127 * @param int $id Uploaded attachment ID. |
153 * @param int $id Uploaded attachment ID. |
128 */ |
154 */ |