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']) && ($id = intval($_REQUEST['attachment_id'])) && $_REQUEST['fetch'] ) { |
42 if ( isset( $_REQUEST['attachment_id'] ) && ( $id = intval( $_REQUEST['attachment_id'] ) ) && $_REQUEST['fetch'] ) { |
43 $post = get_post( $id ); |
43 $post = get_post( $id ); |
44 if ( 'attachment' != $post->post_type ) |
44 if ( 'attachment' != $post->post_type ) { |
45 wp_die( __( 'Invalid post type.' ) ); |
45 wp_die( __( 'Invalid post type.' ) ); |
46 if ( ! current_user_can( 'edit_post', $id ) ) |
46 } |
|
47 if ( ! current_user_can( 'edit_post', $id ) ) { |
47 wp_die( __( 'Sorry, you are not allowed to edit this item.' ) ); |
48 wp_die( __( 'Sorry, you are not allowed to edit this item.' ) ); |
|
49 } |
48 |
50 |
49 switch ( $_REQUEST['fetch'] ) { |
51 switch ( $_REQUEST['fetch'] ) { |
50 case 3 : |
52 case 3: |
51 if ( $thumb_url = wp_get_attachment_image_src( $id, 'thumbnail', true ) ) |
53 if ( $thumb_url = wp_get_attachment_image_src( $id, 'thumbnail', true ) ) { |
52 echo '<img class="pinkynail" src="' . esc_url( $thumb_url[0] ) . '" alt="" />'; |
54 echo '<img class="pinkynail" src="' . esc_url( $thumb_url[0] ) . '" alt="" />'; |
|
55 } |
53 echo '<a class="edit-attachment" href="' . esc_url( get_edit_post_link( $id ) ) . '" target="_blank">' . _x( 'Edit', 'media item' ) . '</a>'; |
56 echo '<a class="edit-attachment" href="' . esc_url( get_edit_post_link( $id ) ) . '" target="_blank">' . _x( 'Edit', 'media item' ) . '</a>'; |
54 |
57 |
55 // Title shouldn't ever be empty, but use filename just in case. |
58 // Title shouldn't ever be empty, but use filename just in case. |
56 $file = get_attached_file( $post->ID ); |
59 $file = get_attached_file( $post->ID ); |
57 $title = $post->post_title ? $post->post_title : wp_basename( $file ); |
60 $title = $post->post_title ? $post->post_title : wp_basename( $file ); |
58 echo '<div class="filename new"><span class="title">' . esc_html( wp_html_excerpt( $title, 60, '…' ) ) . '</span></div>'; |
61 echo '<div class="filename new"><span class="title">' . esc_html( wp_html_excerpt( $title, 60, '…' ) ) . '</span></div>'; |
59 break; |
62 break; |
60 case 2 : |
63 case 2: |
61 add_filter('attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2); |
64 add_filter( 'attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2 ); |
62 echo get_media_item($id, array( 'send' => false, 'delete' => true )); |
65 echo get_media_item( |
|
66 $id, |
|
67 array( |
|
68 'send' => false, |
|
69 'delete' => true, |
|
70 ) |
|
71 ); |
63 break; |
72 break; |
64 default: |
73 default: |
65 add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); |
74 add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 ); |
66 echo get_media_item($id); |
75 echo get_media_item( $id ); |
67 break; |
76 break; |
68 } |
77 } |
69 exit; |
78 exit; |
70 } |
79 } |
71 |
80 |
72 check_admin_referer('media-form'); |
81 check_admin_referer( 'media-form' ); |
73 |
82 |
74 $post_id = 0; |
83 $post_id = 0; |
75 if ( isset( $_REQUEST['post_id'] ) ) { |
84 if ( isset( $_REQUEST['post_id'] ) ) { |
76 $post_id = absint( $_REQUEST['post_id'] ); |
85 $post_id = absint( $_REQUEST['post_id'] ); |
77 if ( ! get_post( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) |
86 if ( ! get_post( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) { |
78 $post_id = 0; |
87 $post_id = 0; |
|
88 } |
79 } |
89 } |
80 |
90 |
81 $id = media_handle_upload( 'async-upload', $post_id ); |
91 $id = media_handle_upload( 'async-upload', $post_id ); |
82 if ( is_wp_error($id) ) { |
92 if ( is_wp_error( $id ) ) { |
83 echo '<div class="error-div error"> |
93 echo '<div class="error-div error"> |
84 <a class="dismiss" href="#" onclick="jQuery(this).parents(\'div.media-item\').slideUp(200, function(){jQuery(this).remove();});">' . __('Dismiss') . '</a> |
94 <button type="button" class="dismiss button-link" onclick="jQuery(this).parents(\'div.media-item\').slideUp(200, function(){jQuery(this).remove();});">' . __( 'Dismiss' ) . '</button> |
85 <strong>' . sprintf(__('“%s” has failed to upload.'), esc_html($_FILES['async-upload']['name']) ) . '</strong><br />' . |
95 <strong>' . sprintf( __( '“%s” has failed to upload.' ), esc_html( $_FILES['async-upload']['name'] ) ) . '</strong><br />' . |
86 esc_html($id->get_error_message()) . '</div>'; |
96 esc_html( $id->get_error_message() ) . '</div>'; |
87 exit; |
97 exit; |
88 } |
98 } |
89 |
99 |
90 if ( $_REQUEST['short'] ) { |
100 if ( $_REQUEST['short'] ) { |
91 // Short form response - attachment ID only. |
101 // Short form response - attachment ID only. |
92 echo $id; |
102 echo $id; |
93 } else { |
103 } else { |
94 // Long form response - big chunk o html. |
104 // Long form response - big chunk of html. |
95 $type = $_REQUEST['type']; |
105 $type = $_REQUEST['type']; |
96 |
106 |
97 /** |
107 /** |
98 * Filters the returned ID of an uploaded attachment. |
108 * Filters the returned ID of an uploaded attachment. |
99 * |
109 * |