97 echo "</ul>\n"; |
100 echo "</ul>\n"; |
98 } |
101 } |
99 } |
102 } |
100 |
103 |
101 /** |
104 /** |
102 * {@internal Missing Short Description}} |
105 * Retrieves the image HTML to send to the editor. |
103 * |
106 * |
104 * @since 2.5.0 |
107 * @since 2.5.0 |
105 * |
108 * |
106 * @param integer $id image attachment id |
109 * @param int $id Image attachment id. |
107 * @param string $caption image caption |
110 * @param string $caption Image caption. |
108 * @param string $alt image alt attribute |
111 * @param string $title Image title attribute. |
109 * @param string $title image title attribute |
112 * @param string $align Image CSS alignment property. |
110 * @param string $align image css alignment property |
113 * @param string $url Optional. Image src URL. Default empty. |
111 * @param string $url image src url |
114 * @param bool|string $rel Optional. Value for rel attribute or whether to add a default value. Default false. |
112 * @param string|bool $rel image rel attribute |
115 * @param string|array $size Optional. Image size. Accepts any valid image size, or an array of width |
113 * @param string $size image size (thumbnail, medium, large, full or added with add_image_size() ) |
116 * and height values in pixels (in that order). Default 'medium'. |
114 * @return string the html to insert into editor |
117 * @param string $alt Optional. Image alt attribute. Default empty. |
115 */ |
118 * @return string The HTML output to insert into the editor. |
116 function get_image_send_to_editor($id, $caption, $title, $align, $url='', $rel = false, $size='medium', $alt = '') { |
119 */ |
117 |
120 function get_image_send_to_editor( $id, $caption, $title, $align, $url = '', $rel = false, $size = 'medium', $alt = '' ) { |
118 $html = get_image_tag($id, $alt, '', $align, $size); |
121 |
119 |
122 $html = get_image_tag( $id, $alt, '', $align, $size ); |
120 $rel = $rel ? ' rel="attachment wp-att-' . esc_attr($id).'"' : ''; |
123 |
|
124 if ( $rel ) { |
|
125 if ( is_string( $rel ) ) { |
|
126 $rel = ' rel="' . esc_attr( $rel ) . '"'; |
|
127 } else { |
|
128 $rel = ' rel="attachment wp-att-' . intval( $id ) . '"'; |
|
129 } |
|
130 } else { |
|
131 $rel = ''; |
|
132 } |
121 |
133 |
122 if ( $url ) |
134 if ( $url ) |
123 $html = '<a href="' . esc_attr($url) . "\"$rel>$html</a>"; |
135 $html = '<a href="' . esc_attr( $url ) . '"' . $rel . '>' . $html . '</a>'; |
124 |
136 |
125 /** |
137 /** |
126 * Filter the image HTML markup to send to the editor. |
138 * Filters the image HTML markup to send to the editor when inserting an image. |
127 * |
139 * |
128 * @since 2.5.0 |
140 * @since 2.5.0 |
129 * |
141 * |
130 * @param string $html The image HTML markup to send. |
142 * @param string $html The image HTML markup to send. |
131 * @param int $id The attachment id. |
143 * @param int $id The attachment id. |
132 * @param string $caption The image caption. |
144 * @param string $caption The image caption. |
133 * @param string $title The image title. |
145 * @param string $title The image title. |
134 * @param string $align The image alignment. |
146 * @param string $align The image alignment. |
135 * @param string $url The image source URL. |
147 * @param string $url The image source URL. |
136 * @param string $size The image size. |
148 * @param string|array $size Size of image. Image size or array of width and height values |
137 * @param string $alt The image alternative, or alt, text. |
149 * (in that order). Default 'medium'. |
|
150 * @param string $alt The image alternative, or alt, text. |
138 */ |
151 */ |
139 $html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt ); |
152 $html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt ); |
140 |
153 |
141 return $html; |
154 return $html; |
142 } |
155 } |
147 * @since 2.6.0 |
160 * @since 2.6.0 |
148 * |
161 * |
149 * @param string $html |
162 * @param string $html |
150 * @param integer $id |
163 * @param integer $id |
151 * @param string $caption image caption |
164 * @param string $caption image caption |
152 * @param string $alt image alt attribute |
|
153 * @param string $title image title attribute |
165 * @param string $title image title attribute |
154 * @param string $align image css alignment property |
166 * @param string $align image css alignment property |
155 * @param string $url image src url |
167 * @param string $url image src url |
156 * @param string $size image size (thumbnail, medium, large, full or added with add_image_size() ) |
168 * @param string $size image size (thumbnail, medium, large, full or added with add_image_size() ) |
|
169 * @param string $alt image alt attribute |
157 * @return string |
170 * @return string |
158 */ |
171 */ |
159 function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) { |
172 function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) { |
160 |
173 |
161 /** |
174 /** |
162 * Filter the caption text. |
175 * Filters the caption text. |
163 * |
176 * |
164 * Note: If the caption text is empty, the caption shortcode will not be appended |
177 * Note: If the caption text is empty, the caption shortcode will not be appended |
165 * to the image HTML when inserted into the editor. |
178 * to the image HTML when inserted into the editor. |
166 * |
179 * |
167 * Passing an empty value also prevents the {@see 'image_add_caption_shortcode'} |
180 * Passing an empty value also prevents the {@see 'image_add_caption_shortcode'} |
168 * filter from being evaluated at the end of {@see image_add_caption()}. |
181 * Filters from being evaluated at the end of image_add_caption(). |
169 * |
182 * |
170 * @since 4.1.0 |
183 * @since 4.1.0 |
171 * |
184 * |
172 * @param string $caption The original caption text. |
185 * @param string $caption The original caption text. |
173 * @param int $id The attachment ID. |
186 * @param int $id The attachment ID. |
174 */ |
187 */ |
175 $caption = apply_filters( 'image_add_caption_text', $caption, $id ); |
188 $caption = apply_filters( 'image_add_caption_text', $caption, $id ); |
176 |
189 |
177 /** |
190 /** |
178 * Filter whether to disable captions. |
191 * Filters whether to disable captions. |
179 * |
192 * |
180 * Prevents image captions from being appended to image HTML when inserted into the editor. |
193 * Prevents image captions from being appended to image HTML when inserted into the editor. |
181 * |
194 * |
182 * @since 2.6.0 |
195 * @since 2.6.0 |
183 * |
196 * |
205 $align = 'none'; |
218 $align = 'none'; |
206 |
219 |
207 $shcode = '[caption id="' . $id . '" align="align' . $align . '" width="' . $width . '"]' . $html . ' ' . $caption . '[/caption]'; |
220 $shcode = '[caption id="' . $id . '" align="align' . $align . '" width="' . $width . '"]' . $html . ' ' . $caption . '[/caption]'; |
208 |
221 |
209 /** |
222 /** |
210 * Filter the image HTML markup including the caption shortcode. |
223 * Filters the image HTML markup including the caption shortcode. |
211 * |
224 * |
212 * @since 2.6.0 |
225 * @since 2.6.0 |
213 * |
226 * |
214 * @param string $shcode The image HTML markup with caption shortcode. |
227 * @param string $shcode The image HTML markup with caption shortcode. |
215 * @param string $html The image HTML markup. |
228 * @param string $html The image HTML markup. |
216 */ |
229 */ |
217 return apply_filters( 'image_add_caption_shortcode', $shcode, $html ); |
230 return apply_filters( 'image_add_caption_shortcode', $shcode, $html ); |
218 } |
231 } |
219 add_filter( 'image_send_to_editor', 'image_add_caption', 20, 8 ); |
|
220 |
232 |
221 /** |
233 /** |
222 * Private preg_replace callback used in image_add_caption() |
234 * Private preg_replace callback used in image_add_caption() |
223 * |
235 * |
224 * @access private |
236 * @access private |
238 */ |
250 */ |
239 function media_send_to_editor($html) { |
251 function media_send_to_editor($html) { |
240 ?> |
252 ?> |
241 <script type="text/javascript"> |
253 <script type="text/javascript"> |
242 var win = window.dialogArguments || opener || parent || top; |
254 var win = window.dialogArguments || opener || parent || top; |
243 win.send_to_editor('<?php echo addslashes($html); ?>'); |
255 win.send_to_editor( <?php echo wp_json_encode( $html ); ?> ); |
244 </script> |
256 </script> |
245 <?php |
257 <?php |
246 exit; |
258 exit; |
247 } |
259 } |
248 |
260 |
249 /** |
261 /** |
250 * Save a file submitted from a POST request and create an attachment post for it. |
262 * Save a file submitted from a POST request and create an attachment post for it. |
251 * |
263 * |
252 * @since 2.5.0 |
264 * @since 2.5.0 |
253 * |
265 * |
254 * @param string $file_id Index of the {@link $_FILES} array that the file was sent. Required. |
266 * @param string $file_id Index of the `$_FILES` array that the file was sent. Required. |
255 * @param int $post_id The post ID of a post to attach the media item to. Required, but can |
267 * @param int $post_id The post ID of a post to attach the media item to. Required, but can |
256 * be set to 0, creating a media item that has no relationship to a post. |
268 * be set to 0, creating a media item that has no relationship to a post. |
257 * @param array $post_data Overwrite some of the attachment. Optional. |
269 * @param array $post_data Overwrite some of the attachment. Optional. |
258 * @param array $overrides Override the {@link wp_handle_upload()} behavior. Optional. |
270 * @param array $overrides Override the wp_handle_upload() behavior. Optional. |
259 * @return int|WP_Error ID of the attachment or a WP_Error object on failure. |
271 * @return int|WP_Error ID of the attachment or a WP_Error object on failure. |
260 */ |
272 */ |
261 function media_handle_upload($file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false )) { |
273 function media_handle_upload($file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false )) { |
262 |
274 |
263 $time = current_time('mysql'); |
275 $time = current_time('mysql'); |
264 if ( $post = get_post($post_id) ) { |
276 if ( $post = get_post($post_id) ) { |
265 if ( substr( $post->post_date, 0, 4 ) > 0 ) |
277 // The post date doesn't usually matter for pages, so don't backdate this upload. |
|
278 if ( 'page' !== $post->post_type && substr( $post->post_date, 0, 4 ) > 0 ) |
266 $time = $post->post_date; |
279 $time = $post->post_date; |
267 } |
280 } |
268 |
281 |
269 $name = $_FILES[$file_id]['name']; |
|
270 $file = wp_handle_upload($_FILES[$file_id], $overrides, $time); |
282 $file = wp_handle_upload($_FILES[$file_id], $overrides, $time); |
271 |
283 |
272 if ( isset($file['error']) ) |
284 if ( isset($file['error']) ) |
273 return new WP_Error( 'upload_error', $file['error'] ); |
285 return new WP_Error( 'upload_error', $file['error'] ); |
274 |
286 |
275 $name_parts = pathinfo($name); |
287 $name = $_FILES[$file_id]['name']; |
276 $name = trim( substr( $name, 0, -(1 + strlen($name_parts['extension'])) ) ); |
288 $ext = pathinfo( $name, PATHINFO_EXTENSION ); |
|
289 $name = wp_basename( $name, ".$ext" ); |
277 |
290 |
278 $url = $file['url']; |
291 $url = $file['url']; |
279 $type = $file['type']; |
292 $type = $file['type']; |
280 $file = $file['file']; |
293 $file = $file['file']; |
281 $title = $name; |
294 $title = sanitize_text_field( $name ); |
282 $content = ''; |
295 $content = ''; |
283 $excerpt = ''; |
296 $excerpt = ''; |
284 |
297 |
285 if ( preg_match( '#^audio#', $type ) ) { |
298 if ( preg_match( '#^audio#', $type ) ) { |
286 $meta = wp_read_audio_metadata( $file ); |
299 $meta = wp_read_audio_metadata( $file ); |
299 $content .= sprintf( __( '"%1$s" from %2$s.' ), $title, $meta['album'] ); |
312 $content .= sprintf( __( '"%1$s" from %2$s.' ), $title, $meta['album'] ); |
300 } elseif ( ! empty( $meta['artist'] ) ) { |
313 } elseif ( ! empty( $meta['artist'] ) ) { |
301 /* translators: 1: audio track title, 2: artist name */ |
314 /* translators: 1: audio track title, 2: artist name */ |
302 $content .= sprintf( __( '"%1$s" by %2$s.' ), $title, $meta['artist'] ); |
315 $content .= sprintf( __( '"%1$s" by %2$s.' ), $title, $meta['artist'] ); |
303 } else { |
316 } else { |
|
317 /* translators: 1: audio track title */ |
304 $content .= sprintf( __( '"%s".' ), $title ); |
318 $content .= sprintf( __( '"%s".' ), $title ); |
305 } |
319 } |
306 |
320 |
307 } elseif ( ! empty( $meta['album'] ) ) { |
321 } elseif ( ! empty( $meta['album'] ) ) { |
308 |
322 |
317 |
331 |
318 $content .= $meta['artist'] . '.'; |
332 $content .= $meta['artist'] . '.'; |
319 |
333 |
320 } |
334 } |
321 |
335 |
322 if ( ! empty( $meta['year'] ) ) |
336 if ( ! empty( $meta['year'] ) ) { |
|
337 /* translators: Audio file track information. 1: Year of audio track release */ |
323 $content .= ' ' . sprintf( __( 'Released: %d.' ), $meta['year'] ); |
338 $content .= ' ' . sprintf( __( 'Released: %d.' ), $meta['year'] ); |
|
339 } |
324 |
340 |
325 if ( ! empty( $meta['track_number'] ) ) { |
341 if ( ! empty( $meta['track_number'] ) ) { |
326 $track_number = explode( '/', $meta['track_number'] ); |
342 $track_number = explode( '/', $meta['track_number'] ); |
327 if ( isset( $track_number[1] ) ) |
343 if ( isset( $track_number[1] ) ) { |
|
344 /* translators: Audio file track information. 1: Audio track number, 2: Total audio tracks */ |
328 $content .= ' ' . sprintf( __( 'Track %1$s of %2$s.' ), number_format_i18n( $track_number[0] ), number_format_i18n( $track_number[1] ) ); |
345 $content .= ' ' . sprintf( __( 'Track %1$s of %2$s.' ), number_format_i18n( $track_number[0] ), number_format_i18n( $track_number[1] ) ); |
329 else |
346 } else { |
|
347 /* translators: Audio file track information. 1: Audio track number */ |
330 $content .= ' ' . sprintf( __( 'Track %1$s.' ), number_format_i18n( $track_number[0] ) ); |
348 $content .= ' ' . sprintf( __( 'Track %1$s.' ), number_format_i18n( $track_number[0] ) ); |
331 } |
349 } |
332 |
350 } |
333 if ( ! empty( $meta['genre'] ) ) |
351 |
|
352 if ( ! empty( $meta['genre'] ) ) { |
|
353 /* translators: Audio file genre information. 1: Audio genre name */ |
334 $content .= ' ' . sprintf( __( 'Genre: %s.' ), $meta['genre'] ); |
354 $content .= ' ' . sprintf( __( 'Genre: %s.' ), $meta['genre'] ); |
|
355 } |
335 |
356 |
336 // Use image exif/iptc data for title and caption defaults if possible. |
357 // Use image exif/iptc data for title and caption defaults if possible. |
337 } elseif ( 0 === strpos( $type, 'image/' ) && $image_meta = @wp_read_image_metadata( $file ) ) { |
358 } elseif ( 0 === strpos( $type, 'image/' ) && $image_meta = wp_read_image_metadata( $file ) ) { |
338 if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) { |
359 if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) { |
339 $title = $image_meta['title']; |
360 $title = $image_meta['title']; |
340 } |
361 } |
341 |
362 |
342 if ( trim( $image_meta['caption'] ) ) { |
363 if ( trim( $image_meta['caption'] ) ) { |
353 'post_content' => $content, |
374 'post_content' => $content, |
354 'post_excerpt' => $excerpt, |
375 'post_excerpt' => $excerpt, |
355 ), $post_data ); |
376 ), $post_data ); |
356 |
377 |
357 // This should never be set as it would then overwrite an existing attachment. |
378 // This should never be set as it would then overwrite an existing attachment. |
358 if ( isset( $attachment['ID'] ) ) |
379 unset( $attachment['ID'] ); |
359 unset( $attachment['ID'] ); |
|
360 |
380 |
361 // Save the data |
381 // Save the data |
362 $id = wp_insert_attachment($attachment, $file, $post_id); |
382 $id = wp_insert_attachment( $attachment, $file, $post_id, true ); |
363 if ( !is_wp_error($id) ) { |
383 if ( !is_wp_error($id) ) { |
364 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); |
384 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); |
365 } |
385 } |
366 |
386 |
367 return $id; |
387 return $id; |
368 |
388 |
369 } |
389 } |
370 |
390 |
371 /** |
391 /** |
372 * This handles a sideloaded file in the same way as an uploaded file is handled by {@link media_handle_upload()} |
392 * Handles a side-loaded file in the same way as an uploaded file is handled by media_handle_upload(). |
373 * |
393 * |
374 * @since 2.6.0 |
394 * @since 2.6.0 |
375 * |
395 * |
376 * @param array $file_array Array similar to a {@link $_FILES} upload array |
396 * @param array $file_array Array similar to a `$_FILES` upload array. |
377 * @param int $post_id The post ID the media is associated with |
397 * @param int $post_id The post ID the media is associated with. |
378 * @param string $desc Description of the sideloaded file |
398 * @param string $desc Optional. Description of the side-loaded file. Default null. |
379 * @param array $post_data allows you to overwrite some of the attachment |
399 * @param array $post_data Optional. Post data to override. Default empty array. |
380 * @return int|object The ID of the attachment or a WP_Error on failure |
400 * @return int|object The ID of the attachment or a WP_Error on failure. |
381 */ |
401 */ |
382 function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) { |
402 function media_handle_sideload( $file_array, $post_id, $desc = null, $post_data = array() ) { |
383 $overrides = array('test_form'=>false); |
403 $overrides = array('test_form'=>false); |
384 |
404 |
385 $time = current_time( 'mysql' ); |
405 $time = current_time( 'mysql' ); |
386 if ( $post = get_post( $post_id ) ) { |
406 if ( $post = get_post( $post_id ) ) { |
387 if ( substr( $post->post_date, 0, 4 ) > 0 ) |
407 if ( substr( $post->post_date, 0, 4 ) > 0 ) |
397 $file = $file['file']; |
417 $file = $file['file']; |
398 $title = preg_replace('/\.[^.]+$/', '', basename($file)); |
418 $title = preg_replace('/\.[^.]+$/', '', basename($file)); |
399 $content = ''; |
419 $content = ''; |
400 |
420 |
401 // Use image exif/iptc data for title and caption defaults if possible. |
421 // Use image exif/iptc data for title and caption defaults if possible. |
402 if ( $image_meta = @wp_read_image_metadata($file) ) { |
422 if ( $image_meta = wp_read_image_metadata( $file ) ) { |
403 if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) |
423 if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) |
404 $title = $image_meta['title']; |
424 $title = $image_meta['title']; |
405 if ( trim( $image_meta['caption'] ) ) |
425 if ( trim( $image_meta['caption'] ) ) |
406 $content = $image_meta['caption']; |
426 $content = $image_meta['caption']; |
407 } |
427 } |
417 'post_title' => $title, |
437 'post_title' => $title, |
418 'post_content' => $content, |
438 'post_content' => $content, |
419 ), $post_data ); |
439 ), $post_data ); |
420 |
440 |
421 // This should never be set as it would then overwrite an existing attachment. |
441 // This should never be set as it would then overwrite an existing attachment. |
422 if ( isset( $attachment['ID'] ) ) |
442 unset( $attachment['ID'] ); |
423 unset( $attachment['ID'] ); |
|
424 |
443 |
425 // Save the attachment metadata |
444 // Save the attachment metadata |
426 $id = wp_insert_attachment($attachment, $file, $post_id); |
445 $id = wp_insert_attachment($attachment, $file, $post_id); |
427 if ( !is_wp_error($id) ) |
446 if ( !is_wp_error($id) ) |
428 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); |
447 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); |
445 |
466 |
446 wp_enqueue_style( 'colors' ); |
467 wp_enqueue_style( 'colors' ); |
447 // Check callback name for 'media' |
468 // Check callback name for 'media' |
448 if ( ( is_array( $content_func ) && ! empty( $content_func[1] ) && 0 === strpos( (string) $content_func[1], 'media' ) ) |
469 if ( ( is_array( $content_func ) && ! empty( $content_func[1] ) && 0 === strpos( (string) $content_func[1], 'media' ) ) |
449 || ( ! is_array( $content_func ) && 0 === strpos( $content_func, 'media' ) ) ) |
470 || ( ! is_array( $content_func ) && 0 === strpos( $content_func, 'media' ) ) ) |
450 wp_enqueue_style( 'media' ); |
471 wp_enqueue_style( 'deprecated-media' ); |
451 wp_enqueue_style( 'ie' ); |
472 wp_enqueue_style( 'ie' ); |
452 ?> |
473 ?> |
453 <script type="text/javascript"> |
474 <script type="text/javascript"> |
454 addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}; |
475 addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}; |
455 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup', |
476 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup', |
544 ) ); |
569 ) ); |
545 |
570 |
546 $img = '<span class="wp-media-buttons-icon"></span> '; |
571 $img = '<span class="wp-media-buttons-icon"></span> '; |
547 |
572 |
548 $id_attribute = $instance === 1 ? ' id="insert-media-button"' : ''; |
573 $id_attribute = $instance === 1 ? ' id="insert-media-button"' : ''; |
549 printf( '<a href="#"%s class="button insert-media add_media" data-editor="%s" title="%s">%s</a>', |
574 printf( '<button type="button"%s class="button insert-media add_media" data-editor="%s">%s</button>', |
550 $id_attribute, |
575 $id_attribute, |
551 esc_attr( $editor_id ), |
576 esc_attr( $editor_id ), |
552 esc_attr__( 'Add Media' ), |
|
553 $img . __( 'Add Media' ) |
577 $img . __( 'Add Media' ) |
554 ); |
578 ); |
555 /** |
579 /** |
556 * Filter the legacy (pre-3.5.0) media buttons. |
580 * Filters the legacy (pre-3.5.0) media buttons. |
|
581 * |
|
582 * Use {@see 'media_buttons'} action instead. |
557 * |
583 * |
558 * @since 2.5.0 |
584 * @since 2.5.0 |
559 * @deprecated 3.5.0 Use 'media_buttons' action instead. |
585 * @deprecated 3.5.0 Use {@see 'media_buttons'} action instead. |
560 * |
586 * |
561 * @param string $string Media buttons context. Default empty. |
587 * @param string $string Media buttons context. Default empty. |
562 */ |
588 */ |
563 $legacy_filter = apply_filters( 'media_buttons_context', '' ); |
589 $legacy_filter = apply_filters( 'media_buttons_context', '' ); |
564 |
590 |
592 |
617 |
593 if ( ! empty( $tab ) ) |
618 if ( ! empty( $tab ) ) |
594 $upload_iframe_src = add_query_arg('tab', $tab, $upload_iframe_src); |
619 $upload_iframe_src = add_query_arg('tab', $tab, $upload_iframe_src); |
595 |
620 |
596 /** |
621 /** |
597 * Filter the upload iframe source URL for a specific media type. |
622 * Filters the upload iframe source URL for a specific media type. |
598 * |
623 * |
599 * The dynamic portion of the hook name, `$type`, refers to the type |
624 * The dynamic portion of the hook name, `$type`, refers to the type |
600 * of media uploaded. |
625 * of media uploaded. |
601 * |
626 * |
602 * @since 3.0.0 |
627 * @since 3.0.0 |
603 * |
628 * |
604 * @param string $upload_iframe_src The upload iframe source URL by type. |
629 * @param string $upload_iframe_src The upload iframe source URL by type. |
605 */ |
630 */ |
606 $upload_iframe_src = apply_filters( $type . '_upload_iframe_src', $upload_iframe_src ); |
631 $upload_iframe_src = apply_filters( "{$type}_upload_iframe_src", $upload_iframe_src ); |
607 |
632 |
608 return add_query_arg('TB_iframe', true, $upload_iframe_src); |
633 return add_query_arg('TB_iframe', true, $upload_iframe_src); |
609 } |
634 } |
610 |
635 |
611 /** |
636 /** |
612 * {@internal Missing Short Description}} |
637 * Handles form submissions for the legacy media uploader. |
613 * |
638 * |
614 * @since 2.5.0 |
639 * @since 2.5.0 |
615 * |
640 * |
616 * @return mixed void|object WP_Error on failure |
641 * @return mixed void|object WP_Error on failure |
617 */ |
642 */ |
644 if ( isset($attachment['post_parent']) ) |
669 if ( isset($attachment['post_parent']) ) |
645 $post['post_parent'] = $attachment['post_parent']; |
670 $post['post_parent'] = $attachment['post_parent']; |
646 } |
671 } |
647 |
672 |
648 /** |
673 /** |
649 * Filter the attachment fields to be saved. |
674 * Filters the attachment fields to be saved. |
650 * |
675 * |
651 * @since 2.5.0 |
676 * @since 2.5.0 |
652 * |
677 * |
653 * @see wp_get_attachment_metadata() |
678 * @see wp_get_attachment_metadata() |
654 * |
679 * |
655 * @param WP_Post $post The WP_Post object. |
680 * @param array $post An array of post data. |
656 * @param array $attachment An array of attachment metadata. |
681 * @param array $attachment An array of attachment metadata. |
657 */ |
682 */ |
658 $post = apply_filters( 'attachment_fields_to_save', $post, $attachment ); |
683 $post = apply_filters( 'attachment_fields_to_save', $post, $attachment ); |
659 |
684 |
660 if ( isset($attachment['image_alt']) ) { |
685 if ( isset($attachment['image_alt']) ) { |
661 $image_alt = wp_unslash( $attachment['image_alt'] ); |
686 $image_alt = wp_unslash( $attachment['image_alt'] ); |
758 if ( ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) ) && ( $ext_type = wp_ext2type( $ext ) ) |
783 if ( ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) ) && ( $ext_type = wp_ext2type( $ext ) ) |
759 && ( 'audio' == $ext_type || 'video' == $ext_type ) ) |
784 && ( 'audio' == $ext_type || 'video' == $ext_type ) ) |
760 $type = $ext_type; |
785 $type = $ext_type; |
761 |
786 |
762 /** |
787 /** |
763 * Filter the URL sent to the editor for a specific media type. |
788 * Filters the URL sent to the editor for a specific media type. |
764 * |
789 * |
765 * The dynamic portion of the hook name, `$type`, refers to the type |
790 * The dynamic portion of the hook name, `$type`, refers to the type |
766 * of media being sent. |
791 * of media being sent. |
767 * |
792 * |
768 * @since 3.3.0 |
793 * @since 3.3.0 |
769 * |
794 * |
770 * @param string $html HTML markup sent to the editor. |
795 * @param string $html HTML markup sent to the editor. |
771 * @param string $src Media source URL. |
796 * @param string $src Media source URL. |
772 * @param string $title Media title. |
797 * @param string $title Media title. |
773 */ |
798 */ |
774 $html = apply_filters( $type . '_send_to_editor_url', $html, esc_url_raw( $src ), $title ); |
799 $html = apply_filters( "{$type}_send_to_editor_url", $html, esc_url_raw( $src ), $title ); |
775 } else { |
800 } else { |
776 $align = ''; |
801 $align = ''; |
777 $alt = esc_attr( wp_unslash( $_POST['alt'] ) ); |
802 $alt = esc_attr( wp_unslash( $_POST['alt'] ) ); |
778 if ( isset($_POST['align']) ) { |
803 if ( isset($_POST['align']) ) { |
779 $align = esc_attr( wp_unslash( $_POST['align'] ) ); |
804 $align = esc_attr( wp_unslash( $_POST['align'] ) ); |
820 |
847 |
821 return wp_iframe( 'media_upload_type_form', 'image', $errors, $id ); |
848 return wp_iframe( 'media_upload_type_form', 'image', $errors, $id ); |
822 } |
849 } |
823 |
850 |
824 /** |
851 /** |
825 * Download an image from the specified URL and attach it to a post. |
852 * Downloads an image from the specified URL and attaches it to a post. |
826 * |
853 * |
827 * @since 2.6.0 |
854 * @since 2.6.0 |
828 * |
855 * @since 4.2.0 Introduced the `$return` parameter. |
829 * @param string $file The URL of the image to download |
856 * @since 4.8.0 Introduced the 'id' option within the `$return` parameter. |
830 * @param int $post_id The post ID the media is to be associated with |
857 * |
831 * @param string $desc Optional. Description of the image |
858 * @param string $file The URL of the image to download. |
832 * @param string $return Optional. What to return: an image tag (default) or only the src. |
859 * @param int $post_id The post ID the media is to be associated with. |
833 * @return string|WP_Error Populated HTML img tag on success |
860 * @param string $desc Optional. Description of the image. |
|
861 * @param string $return Optional. Accepts 'html' (image tag html) or 'src' (URL), or 'id' (attachment ID). Default 'html'. |
|
862 * @return string|WP_Error Populated HTML img tag on success, WP_Error object otherwise. |
834 */ |
863 */ |
835 function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) { |
864 function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) { |
836 if ( ! empty( $file ) ) { |
865 if ( ! empty( $file ) ) { |
|
866 |
837 // Set variables for storage, fix file filename for query strings. |
867 // Set variables for storage, fix file filename for query strings. |
838 preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches ); |
868 preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches ); |
|
869 if ( ! $matches ) { |
|
870 return new WP_Error( 'image_sideload_failed', __( 'Invalid image URL' ) ); |
|
871 } |
|
872 |
839 $file_array = array(); |
873 $file_array = array(); |
840 $file_array['name'] = basename( $matches[0] ); |
874 $file_array['name'] = basename( $matches[0] ); |
841 |
875 |
842 // Download file to temp location. |
876 // Download file to temp location. |
843 $file_array['tmp_name'] = download_url( $file ); |
877 $file_array['tmp_name'] = download_url( $file ); |
852 |
886 |
853 // If error storing permanently, unlink. |
887 // If error storing permanently, unlink. |
854 if ( is_wp_error( $id ) ) { |
888 if ( is_wp_error( $id ) ) { |
855 @unlink( $file_array['tmp_name'] ); |
889 @unlink( $file_array['tmp_name'] ); |
856 return $id; |
890 return $id; |
|
891 // If attachment id was requested, return it early. |
|
892 } elseif ( $return === 'id' ) { |
|
893 return $id; |
857 } |
894 } |
858 |
895 |
859 $src = wp_get_attachment_url( $id ); |
896 $src = wp_get_attachment_url( $id ); |
860 } |
897 } |
861 |
898 |
862 // Finally check to make sure the file has been saved, then return the HTML. |
899 // Finally, check to make sure the file has been saved, then return the HTML. |
863 if ( ! empty( $src ) ) { |
900 if ( ! empty( $src ) ) { |
864 if ( $return === 'src' ) { |
901 if ( $return === 'src' ) { |
865 return $src; |
902 return $src; |
866 } |
903 } |
867 |
904 |
1048 <button type='button' class='button urlfile' data-link-url='" . esc_attr($file) . "'>" . __('File URL') . "</button> |
1085 <button type='button' class='button urlfile' data-link-url='" . esc_attr($file) . "'>" . __('File URL') . "</button> |
1049 <button type='button' class='button urlpost' data-link-url='" . esc_attr($link) . "'>" . __('Attachment Post URL') . "</button> |
1086 <button type='button' class='button urlpost' data-link-url='" . esc_attr($link) . "'>" . __('Attachment Post URL') . "</button> |
1050 "; |
1087 "; |
1051 } |
1088 } |
1052 |
1089 |
|
1090 /** |
|
1091 * Output a textarea element for inputting an attachment caption. |
|
1092 * |
|
1093 * @since 3.4.0 |
|
1094 * |
|
1095 * @param WP_Post $edit_post Attachment WP_Post object. |
|
1096 * @return string HTML markup for the textarea element. |
|
1097 */ |
1053 function wp_caption_input_textarea($edit_post) { |
1098 function wp_caption_input_textarea($edit_post) { |
1054 // Post data is already escaped. |
1099 // Post data is already escaped. |
1055 $name = "attachments[{$edit_post->ID}][post_excerpt]"; |
1100 $name = "attachments[{$edit_post->ID}][post_excerpt]"; |
1056 |
1101 |
1057 return '<textarea name="' . $name . '" id="' . $name . '">' . $edit_post->post_excerpt . '</textarea>'; |
1102 return '<textarea name="' . $name . '" id="' . $name . '">' . $edit_post->post_excerpt . '</textarea>'; |
1058 } |
1103 } |
1059 |
1104 |
1060 /** |
1105 /** |
1061 * {@internal Missing Short Description}} |
1106 * Retrieves the image attachment fields to edit form fields. |
1062 * |
1107 * |
1063 * @since 2.5.0 |
1108 * @since 2.5.0 |
1064 * |
1109 * |
1065 * @param array $form_fields |
1110 * @param array $form_fields |
1066 * @param object $post |
1111 * @param object $post |
1140 if ( substr($post->post_mime_type, 0, 5) == 'image' ) { |
1183 if ( substr($post->post_mime_type, 0, 5) == 'image' ) { |
1141 $url = $attachment['url']; |
1184 $url = $attachment['url']; |
1142 $align = !empty($attachment['align']) ? $attachment['align'] : 'none'; |
1185 $align = !empty($attachment['align']) ? $attachment['align'] : 'none'; |
1143 $size = !empty($attachment['image-size']) ? $attachment['image-size'] : 'medium'; |
1186 $size = !empty($attachment['image-size']) ? $attachment['image-size'] : 'medium'; |
1144 $alt = !empty($attachment['image_alt']) ? $attachment['image_alt'] : ''; |
1187 $alt = !empty($attachment['image_alt']) ? $attachment['image_alt'] : ''; |
1145 $rel = ( $url == get_attachment_link($attachment_id) ); |
1188 $rel = ( strpos( $url, 'attachment_id') || $url === get_attachment_link( $attachment_id ) ); |
1146 |
1189 |
1147 return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size, $alt); |
1190 return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size, $alt); |
1148 } |
1191 } |
1149 |
1192 |
1150 return $html; |
1193 return $html; |
1151 } |
1194 } |
1152 |
1195 |
1153 add_filter('media_send_to_editor', 'image_media_send_to_editor', 10, 3); |
1196 /** |
1154 |
1197 * Retrieves the attachment fields to edit form fields. |
1155 /** |
|
1156 * {@internal Missing Short Description}} |
|
1157 * |
1198 * |
1158 * @since 2.5.0 |
1199 * @since 2.5.0 |
1159 * |
1200 * |
1160 * @param WP_Post $post |
1201 * @param WP_Post $post |
1161 * @param array $errors |
1202 * @param array $errors |
1227 |
1268 |
1228 $form_fields[$taxonomy] = $t; |
1269 $form_fields[$taxonomy] = $t; |
1229 } |
1270 } |
1230 |
1271 |
1231 // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default |
1272 // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default |
1232 // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing ) |
1273 // The recursive merge is easily traversed with array casting: foreach ( (array) $things as $thing ) |
1233 $form_fields = array_merge_recursive($form_fields, (array) $errors); |
1274 $form_fields = array_merge_recursive($form_fields, (array) $errors); |
1234 |
1275 |
1235 // This was formerly in image_attachment_fields_to_edit(). |
1276 // This was formerly in image_attachment_fields_to_edit(). |
1236 if ( substr($post->post_mime_type, 0, 5) == 'image' ) { |
1277 if ( substr($post->post_mime_type, 0, 5) == 'image' ) { |
1237 $alt = get_post_meta($post->ID, '_wp_attachment_image_alt', true); |
1278 $alt = get_post_meta($post->ID, '_wp_attachment_image_alt', true); |
1350 $r = apply_filters( 'get_media_item_args', $args ); |
1395 $r = apply_filters( 'get_media_item_args', $args ); |
1351 |
1396 |
1352 $toggle_on = __( 'Show' ); |
1397 $toggle_on = __( 'Show' ); |
1353 $toggle_off = __( 'Hide' ); |
1398 $toggle_off = __( 'Hide' ); |
1354 |
1399 |
1355 $filename = esc_html( wp_basename( $post->guid ) ); |
1400 $file = get_attached_file( $post->ID ); |
|
1401 $filename = esc_html( wp_basename( $file ) ); |
1356 $title = esc_attr( $post->post_title ); |
1402 $title = esc_attr( $post->post_title ); |
1357 |
1403 |
1358 $post_mime_types = get_post_mime_types(); |
1404 $post_mime_types = get_post_mime_types(); |
1359 $keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) ); |
1405 $keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) ); |
1360 $type = reset( $keys ); |
1406 $type = reset( $keys ); |
1426 <p>$image_edit_button</p> |
1472 <p>$image_edit_button</p> |
1427 </td> |
1473 </td> |
1428 <td> |
1474 <td> |
1429 <p><strong>" . __('File name:') . "</strong> $filename</p> |
1475 <p><strong>" . __('File name:') . "</strong> $filename</p> |
1430 <p><strong>" . __('File type:') . "</strong> $post->post_mime_type</p> |
1476 <p><strong>" . __('File type:') . "</strong> $post->post_mime_type</p> |
1431 <p><strong>" . __('Upload date:') . "</strong> " . mysql2date( get_option('date_format'), $post->post_date ). '</p>'; |
1477 <p><strong>" . __('Upload date:') . "</strong> " . mysql2date( __( 'F j, Y' ), $post->post_date ). '</p>'; |
1432 if ( !empty( $media_dims ) ) |
1478 if ( !empty( $media_dims ) ) |
1433 $item .= "<p><strong>" . __('Dimensions:') . "</strong> $media_dims</p>\n"; |
1479 $item .= "<p><strong>" . __('Dimensions:') . "</strong> $media_dims</p>\n"; |
1434 |
1480 |
1435 $item .= "</td></tr>\n"; |
1481 $item .= "</td></tr>\n"; |
1436 |
1482 |
1437 $item .= " |
1483 $item .= " |
1438 </thead> |
1484 </thead> |
1439 <tbody> |
1485 <tbody> |
1440 <tr><td colspan='2' class='imgedit-response' id='imgedit-response-$post->ID'></td></tr> |
1486 <tr><td colspan='2' class='imgedit-response' id='imgedit-response-$post->ID'></td></tr>\n |
1441 <tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-$post->ID'></td></tr>\n"; |
1487 <tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-$post->ID'></td></tr>\n |
|
1488 <tr><td colspan='2'><p class='media-types media-types-required-info'>" . sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) . "</p></td></tr>\n"; |
1442 |
1489 |
1443 $defaults = array( |
1490 $defaults = array( |
1444 'input' => 'text', |
1491 'input' => 'text', |
1445 'required' => false, |
1492 'required' => false, |
1446 'value' => '', |
1493 'value' => '', |
1447 'extra_rows' => array(), |
1494 'extra_rows' => array(), |
1448 ); |
1495 ); |
1449 |
1496 |
1450 if ( $r['send'] ) { |
1497 if ( $r['send'] ) { |
1451 $r['send'] = get_submit_button( __( 'Insert into Post' ), 'button', "send[$attachment_id]", false ); |
1498 $r['send'] = get_submit_button( __( 'Insert into Post' ), '', "send[$attachment_id]", false ); |
1452 } |
1499 } |
1453 |
1500 |
1454 $delete = empty( $r['delete'] ) ? '' : $r['delete']; |
1501 $delete = empty( $r['delete'] ) ? '' : $r['delete']; |
1455 if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) { |
1502 if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) { |
1456 if ( !EMPTY_TRASH_DAYS ) { |
1503 if ( !EMPTY_TRASH_DAYS ) { |
1457 $delete = "<a href='" . wp_nonce_url( "post.php?action=delete&post=$attachment_id", 'delete-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete-permanently'>" . __( 'Delete Permanently' ) . '</a>'; |
1504 $delete = "<a href='" . wp_nonce_url( "post.php?action=delete&post=$attachment_id", 'delete-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete-permanently'>" . __( 'Delete Permanently' ) . '</a>'; |
1458 } elseif ( !MEDIA_TRASH ) { |
1505 } elseif ( !MEDIA_TRASH ) { |
1459 $delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete' ) . "</a> |
1506 $delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete' ) . "</a> |
1460 <div id='del_attachment_$attachment_id' class='del-attachment' style='display:none;'><p>" . sprintf( __( 'You are about to delete <strong>%s</strong>.' ), $filename ) . "</p> |
1507 <div id='del_attachment_$attachment_id' class='del-attachment' style='display:none;'>" . |
|
1508 /* translators: %s: file name */ |
|
1509 '<p>' . sprintf( __( 'You are about to delete %s.' ), '<strong>' . $filename . '</strong>' ) . "</p> |
1461 <a href='" . wp_nonce_url( "post.php?action=delete&post=$attachment_id", 'delete-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='button'>" . __( 'Continue' ) . "</a> |
1510 <a href='" . wp_nonce_url( "post.php?action=delete&post=$attachment_id", 'delete-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='button'>" . __( 'Continue' ) . "</a> |
1462 <a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __( 'Cancel' ) . "</a> |
1511 <a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __( 'Cancel' ) . "</a> |
1463 </div>"; |
1512 </div>"; |
1464 } else { |
1513 } else { |
1465 $delete = "<a href='" . wp_nonce_url( "post.php?action=trash&post=$attachment_id", 'trash-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Move to Trash' ) . "</a> |
1514 $delete = "<a href='" . wp_nonce_url( "post.php?action=trash&post=$attachment_id", 'trash-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Move to Trash' ) . "</a> |
1476 } elseif ( isset( $_POST ) && count( $_POST ) ) {// Like for async-upload where $_GET['post_id'] isn't set |
1525 } elseif ( isset( $_POST ) && count( $_POST ) ) {// Like for async-upload where $_GET['post_id'] isn't set |
1477 $calling_post_id = $post->post_parent; |
1526 $calling_post_id = $post->post_parent; |
1478 } |
1527 } |
1479 if ( 'image' == $type && $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) ) |
1528 if ( 'image' == $type && $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) ) |
1480 && post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id ) { |
1529 && post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id ) { |
|
1530 |
|
1531 $calling_post = get_post( $calling_post_id ); |
|
1532 $calling_post_type_object = get_post_type_object( $calling_post->post_type ); |
|
1533 |
1481 $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" ); |
1534 $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" ); |
1482 $thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\", \"$ajax_nonce\");return false;'>" . esc_html__( "Use as featured image" ) . "</a>"; |
1535 $thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\", \"$ajax_nonce\");return false;'>" . esc_html( $calling_post_type_object->labels->use_featured_image ) . "</a>"; |
1483 } |
1536 } |
1484 |
1537 |
1485 if ( ( $r['send'] || $thumbnail || $delete ) && !isset( $form_fields['buttons'] ) ) { |
1538 if ( ( $r['send'] || $thumbnail || $delete ) && !isset( $form_fields['buttons'] ) ) { |
1486 $form_fields['buttons'] = array( 'tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>" . $r['send'] . " $thumbnail $delete</td></tr>\n" ); |
1539 $form_fields['buttons'] = array( 'tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>" . $r['send'] . " $thumbnail $delete</td></tr>\n" ); |
1487 } |
1540 } |
1502 if ( $field['input'] == 'hidden' ) { |
1555 if ( $field['input'] == 'hidden' ) { |
1503 $hidden_fields[$name] = $field['value']; |
1556 $hidden_fields[$name] = $field['value']; |
1504 continue; |
1557 continue; |
1505 } |
1558 } |
1506 |
1559 |
1507 $required = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : ''; |
1560 $required = $field['required'] ? '<span class="required">*</span>' : ''; |
1508 $aria_required = $field['required'] ? " aria-required='true' " : ''; |
1561 $required_attr = $field['required'] ? ' required' : ''; |
|
1562 $aria_required = $field['required'] ? " aria-required='true'" : ''; |
1509 $class = $id; |
1563 $class = $id; |
1510 $class .= $field['required'] ? ' form-required' : ''; |
1564 $class .= $field['required'] ? ' form-required' : ''; |
1511 |
1565 |
1512 $item .= "\t\t<tr class='$class'>\n\t\t\t<th scope='row' class='label'><label for='$name'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label></th>\n\t\t\t<td class='field'>"; |
1566 $item .= "\t\t<tr class='$class'>\n\t\t\t<th scope='row' class='label'><label for='$name'><span class='alignleft'>{$field['label']}{$required}</span><br class='clear' /></label></th>\n\t\t\t<td class='field'>"; |
1513 if ( !empty( $field[ $field['input'] ] ) ) |
1567 if ( !empty( $field[ $field['input'] ] ) ) |
1514 $item .= $field[ $field['input'] ]; |
1568 $item .= $field[ $field['input'] ]; |
1515 elseif ( $field['input'] == 'textarea' ) { |
1569 elseif ( $field['input'] == 'textarea' ) { |
1516 if ( 'post_content' == $id && user_can_richedit() ) { |
1570 if ( 'post_content' == $id && user_can_richedit() ) { |
1517 // Sanitize_post() skips the post_content when user_can_richedit. |
1571 // Sanitize_post() skips the post_content when user_can_richedit. |
1518 $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES ); |
1572 $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES ); |
1519 } |
1573 } |
1520 // Post_excerpt is already escaped by sanitize_post() in get_attachment_fields_to_edit(). |
1574 // Post_excerpt is already escaped by sanitize_post() in get_attachment_fields_to_edit(). |
1521 $item .= "<textarea id='$name' name='$name' $aria_required>" . $field['value'] . '</textarea>'; |
1575 $item .= "<textarea id='$name' name='$name'{$required_attr}{$aria_required}>" . $field['value'] . '</textarea>'; |
1522 } else { |
1576 } else { |
1523 $item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "' $aria_required />"; |
1577 $item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "'{$required_attr}{$aria_required} />"; |
1524 } |
1578 } |
1525 if ( !empty( $field['helps'] ) ) |
1579 if ( !empty( $field['helps'] ) ) |
1526 $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>'; |
1580 $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>'; |
1527 $item .= "</td>\n\t\t</tr>\n"; |
1581 $item .= "</td>\n\t\t</tr>\n"; |
1528 |
1582 |
1600 $form_fields[$taxonomy] = $t; |
1661 $form_fields[$taxonomy] = $t; |
1601 } |
1662 } |
1602 } |
1663 } |
1603 |
1664 |
1604 // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default |
1665 // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default |
1605 // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing ) |
1666 // The recursive merge is easily traversed with array casting: foreach ( (array) $things as $thing ) |
1606 $form_fields = array_merge_recursive($form_fields, (array) $args['errors'] ); |
1667 $form_fields = array_merge_recursive($form_fields, (array) $args['errors'] ); |
1607 |
1668 |
1608 /** This filter is documented in wp-admin/includes/media.php */ |
1669 /** This filter is documented in wp-admin/includes/media.php */ |
1609 $form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post ); |
1670 $form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post ); |
1610 |
1671 |
1648 $hidden_fields[$name] = $field['value']; |
1709 $hidden_fields[$name] = $field['value']; |
1649 continue; |
1710 continue; |
1650 } |
1711 } |
1651 |
1712 |
1652 $readonly = ! $user_can_edit && ! empty( $field['taxonomy'] ) ? " readonly='readonly' " : ''; |
1713 $readonly = ! $user_can_edit && ! empty( $field['taxonomy'] ) ? " readonly='readonly' " : ''; |
1653 $required = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : ''; |
1714 $required = $field['required'] ? '<span class="required">*</span>' : ''; |
1654 $aria_required = $field['required'] ? " aria-required='true' " : ''; |
1715 $required_attr = $field['required'] ? ' required' : ''; |
|
1716 $aria_required = $field['required'] ? " aria-required='true'" : ''; |
1655 $class = 'compat-field-' . $id; |
1717 $class = 'compat-field-' . $id; |
1656 $class .= $field['required'] ? ' form-required' : ''; |
1718 $class .= $field['required'] ? ' form-required' : ''; |
1657 |
1719 |
1658 $item .= "\t\t<tr class='$class'>"; |
1720 $item .= "\t\t<tr class='$class'>"; |
1659 $item .= "\t\t\t<th scope='row' class='label'><label for='$id_attr'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label>"; |
1721 $item .= "\t\t\t<th scope='row' class='label'><label for='$id_attr'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label>"; |
1664 elseif ( $field['input'] == 'textarea' ) { |
1726 elseif ( $field['input'] == 'textarea' ) { |
1665 if ( 'post_content' == $id && user_can_richedit() ) { |
1727 if ( 'post_content' == $id && user_can_richedit() ) { |
1666 // sanitize_post() skips the post_content when user_can_richedit. |
1728 // sanitize_post() skips the post_content when user_can_richedit. |
1667 $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES ); |
1729 $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES ); |
1668 } |
1730 } |
1669 $item .= "<textarea id='$id_attr' name='$name' $aria_required>" . $field['value'] . '</textarea>'; |
1731 $item .= "<textarea id='$id_attr' name='$name'{$required_attr}{$aria_required}>" . $field['value'] . '</textarea>'; |
1670 } else { |
1732 } else { |
1671 $item .= "<input type='text' class='text' id='$id_attr' name='$name' value='" . esc_attr( $field['value'] ) . "' $readonly $aria_required />"; |
1733 $item .= "<input type='text' class='text' id='$id_attr' name='$name' value='" . esc_attr( $field['value'] ) . "' $readonly{$required_attr}{$aria_required} />"; |
1672 } |
1734 } |
1673 if ( !empty( $field['helps'] ) ) |
1735 if ( !empty( $field['helps'] ) ) |
1674 $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>'; |
1736 $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>'; |
1675 $item .= "</td>\n\t\t</tr>\n"; |
1737 $item .= "</td>\n\t\t</tr>\n"; |
1676 |
1738 |
1690 $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n"; |
1752 $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n"; |
1691 } |
1753 } |
1692 |
1754 |
1693 if ( !empty( $form_fields['_final'] ) ) |
1755 if ( !empty( $form_fields['_final'] ) ) |
1694 $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n"; |
1756 $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n"; |
1695 if ( $item ) |
1757 |
1696 $item = '<table class="compat-attachment-fields">' . $item . '</table>'; |
1758 if ( $item ) { |
|
1759 $item = '<p class="media-types media-types-required-info">' . |
|
1760 sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) . '</p> |
|
1761 <table class="compat-attachment-fields">' . $item . '</table>'; |
|
1762 } |
1697 |
1763 |
1698 foreach ( $hidden_fields as $hidden_field => $value ) { |
1764 foreach ( $hidden_fields as $hidden_field => $value ) { |
1699 $item .= '<input type="hidden" name="' . esc_attr( $hidden_field ) . '" value="' . esc_attr( $value ) . '" />' . "\n"; |
1765 $item .= '<input type="hidden" name="' . esc_attr( $hidden_field ) . '" value="' . esc_attr( $value ) . '" />' . "\n"; |
1700 } |
1766 } |
1701 |
1767 |
1707 'meta' => $media_meta, |
1773 'meta' => $media_meta, |
1708 ); |
1774 ); |
1709 } |
1775 } |
1710 |
1776 |
1711 /** |
1777 /** |
1712 * {@internal Missing Short Description}} |
1778 * Outputs the legacy media upload header. |
1713 * |
1779 * |
1714 * @since 2.5.0 |
1780 * @since 2.5.0 |
1715 */ |
1781 */ |
1716 function media_upload_header() { |
1782 function media_upload_header() { |
1717 $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0; |
1783 $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0; |
1718 echo '<script type="text/javascript">post_id = ' . $post_id . ";</script>\n"; |
1784 |
|
1785 echo '<script type="text/javascript">post_id = ' . $post_id . ';</script>'; |
1719 if ( empty( $_GET['chromeless'] ) ) { |
1786 if ( empty( $_GET['chromeless'] ) ) { |
1720 echo '<div id="media-upload-header">'; |
1787 echo '<div id="media-upload-header">'; |
1721 the_media_upload_tabs(); |
1788 the_media_upload_tabs(); |
1722 echo '</div>'; |
1789 echo '</div>'; |
1723 } |
1790 } |
1724 } |
1791 } |
1725 |
1792 |
1726 /** |
1793 /** |
1727 * {@internal Missing Short Description}} |
1794 * Outputs the legacy media upload form. |
1728 * |
1795 * |
1729 * @since 2.5.0 |
1796 * @since 2.5.0 |
|
1797 * |
|
1798 * @global string $type |
|
1799 * @global string $tab |
|
1800 * @global bool $is_IE |
|
1801 * @global bool $is_opera |
1730 * |
1802 * |
1731 * @param array $errors |
1803 * @param array $errors |
1732 */ |
1804 */ |
1733 function media_upload_form( $errors = null ) { |
1805 function media_upload_form( $errors = null ) { |
1734 global $type, $tab, $is_IE, $is_opera; |
1806 global $type, $tab, $is_IE, $is_opera; |
1786 "tab" => $_tab, |
1858 "tab" => $_tab, |
1787 "short" => "1", |
1859 "short" => "1", |
1788 ); |
1860 ); |
1789 |
1861 |
1790 /** |
1862 /** |
1791 * Filter the media upload post parameters. |
1863 * Filters the media upload post parameters. |
1792 * |
1864 * |
1793 * @since 3.1.0 As 'swfupload_post_params' |
1865 * @since 3.1.0 As 'swfupload_post_params' |
1794 * @since 3.3.0 |
1866 * @since 3.3.0 |
1795 * |
1867 * |
1796 * @param array $post_params An array of media upload parameters used by Plupload. |
1868 * @param array $post_params An array of media upload parameters used by Plupload. |
1797 */ |
1869 */ |
1798 $post_params = apply_filters( 'upload_post_params', $post_params ); |
1870 $post_params = apply_filters( 'upload_post_params', $post_params ); |
1799 |
1871 |
|
1872 /* |
|
1873 * Since 4.9 the `runtimes` setting is hardcoded in our version of Plupload to `html5,html4`, |
|
1874 * and the `flash_swf_url` and `silverlight_xap_url` are not used. |
|
1875 */ |
1800 $plupload_init = array( |
1876 $plupload_init = array( |
1801 'runtimes' => 'html5,flash,silverlight,html4', |
|
1802 'browse_button' => 'plupload-browse-button', |
1877 'browse_button' => 'plupload-browse-button', |
1803 'container' => 'plupload-upload-ui', |
1878 'container' => 'plupload-upload-ui', |
1804 'drop_element' => 'drag-drop-area', |
1879 'drop_element' => 'drag-drop-area', |
1805 'file_data_name' => 'async-upload', |
1880 'file_data_name' => 'async-upload', |
1806 'url' => $upload_action_url, |
1881 'url' => $upload_action_url, |
1807 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ), |
|
1808 'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ), |
|
1809 'filters' => array( |
1882 'filters' => array( |
1810 'max_file_size' => $max_upload_size . 'b', |
1883 'max_file_size' => $max_upload_size . 'b', |
1811 ), |
1884 ), |
1812 'multipart_params' => $post_params, |
1885 'multipart_params' => $post_params, |
1813 ); |
1886 ); |
1881 do_action( 'pre-html-upload-ui' ); |
1954 do_action( 'pre-html-upload-ui' ); |
1882 ?> |
1955 ?> |
1883 <p id="async-upload-wrap"> |
1956 <p id="async-upload-wrap"> |
1884 <label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label> |
1957 <label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label> |
1885 <input type="file" name="async-upload" id="async-upload" /> |
1958 <input type="file" name="async-upload" id="async-upload" /> |
1886 <?php submit_button( __( 'Upload' ), 'button', 'html-upload', false ); ?> |
1959 <?php submit_button( __( 'Upload' ), 'primary', 'html-upload', false ); ?> |
1887 <a href="#" onclick="try{top.tb_remove();}catch(e){}; return false;"><?php _e('Cancel'); ?></a> |
1960 <a href="#" onclick="try{top.tb_remove();}catch(e){}; return false;"><?php _e('Cancel'); ?></a> |
1888 </p> |
1961 </p> |
1889 <div class="clear"></div> |
1962 <div class="clear"></div> |
1890 <?php |
1963 <?php |
1891 /** |
1964 /** |
2063 var t = addExtImage; |
2136 var t = addExtImage; |
2064 |
2137 |
2065 t.width = t.height = ''; |
2138 t.width = t.height = ''; |
2066 document.getElementById('go_button').style.color = '#bbb'; |
2139 document.getElementById('go_button').style.color = '#bbb'; |
2067 if ( ! document.forms[0].src.value ) |
2140 if ( ! document.forms[0].src.value ) |
2068 document.getElementById('status_img').innerHTML = '*'; |
2141 document.getElementById('status_img').innerHTML = ''; |
2069 else document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/no.png' ) ); ?>" alt="" />'; |
2142 else document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/no.png' ) ); ?>" alt="" />'; |
2070 }, |
2143 }, |
2071 |
2144 |
2072 updateImageData : function() { |
2145 updateImageData : function() { |
2073 var t = addExtImage; |
2146 var t = addExtImage; |
2179 <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?> |
2256 <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?> |
2180 <?php echo get_media_items($post_id, $errors); ?> |
2257 <?php echo get_media_items($post_id, $errors); ?> |
2181 </div> |
2258 </div> |
2182 |
2259 |
2183 <p class="ml-submit"> |
2260 <p class="ml-submit"> |
2184 <?php submit_button( __( 'Save all changes' ), 'button savebutton', 'save', false, array( 'id' => 'save-all', 'style' => 'display: none;' ) ); ?> |
2261 <?php submit_button( __( 'Save all changes' ), 'savebutton', 'save', false, array( 'id' => 'save-all', 'style' => 'display: none;' ) ); ?> |
2185 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
2262 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
2186 <input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" /> |
2263 <input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" /> |
2187 <input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" /> |
2264 <input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" /> |
2188 </p> |
2265 </p> |
2189 |
2266 |
2266 </form> |
2343 </form> |
2267 <?php |
2344 <?php |
2268 } |
2345 } |
2269 |
2346 |
2270 /** |
2347 /** |
2271 * {@internal Missing Short Description}} |
2348 * Outputs the legacy media upload form for the media library. |
2272 * |
2349 * |
2273 * @since 2.5.0 |
2350 * @since 2.5.0 |
|
2351 * |
|
2352 * @global wpdb $wpdb |
|
2353 * @global WP_Query $wp_query |
|
2354 * @global WP_Locale $wp_locale |
|
2355 * @global string $type |
|
2356 * @global string $tab |
|
2357 * @global array $post_mime_types |
2274 * |
2358 * |
2275 * @param array $errors |
2359 * @param array $errors |
2276 */ |
2360 */ |
2277 function media_upload_library_form($errors) { |
2361 function media_upload_library_form($errors) { |
2278 global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types; |
2362 global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types; |
2312 <input type="hidden" name="context" value="<?php echo isset( $_GET['context'] ) ? esc_attr( $_GET['context'] ) : ''; ?>" /> |
2396 <input type="hidden" name="context" value="<?php echo isset( $_GET['context'] ) ? esc_attr( $_GET['context'] ) : ''; ?>" /> |
2313 |
2397 |
2314 <p id="media-search" class="search-box"> |
2398 <p id="media-search" class="search-box"> |
2315 <label class="screen-reader-text" for="media-search-input"><?php _e('Search Media');?>:</label> |
2399 <label class="screen-reader-text" for="media-search-input"><?php _e('Search Media');?>:</label> |
2316 <input type="search" id="media-search-input" name="s" value="<?php the_search_query(); ?>" /> |
2400 <input type="search" id="media-search-input" name="s" value="<?php the_search_query(); ?>" /> |
2317 <?php submit_button( __( 'Search Media' ), 'button', '', false ); ?> |
2401 <?php submit_button( __( 'Search Media' ), '', '', false ); ?> |
2318 </p> |
2402 </p> |
2319 |
2403 |
2320 <ul class="subsubsub"> |
2404 <ul class="subsubsub"> |
2321 <?php |
2405 <?php |
2322 $type_links = array(); |
2406 $type_links = array(); |
2439 <div id="media-items"> |
2523 <div id="media-items"> |
2440 <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?> |
2524 <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?> |
2441 <?php echo get_media_items(null, $errors); ?> |
2525 <?php echo get_media_items(null, $errors); ?> |
2442 </div> |
2526 </div> |
2443 <p class="ml-submit"> |
2527 <p class="ml-submit"> |
2444 <?php submit_button( __( 'Save all changes' ), 'button savebutton', 'save', false ); ?> |
2528 <?php submit_button( __( 'Save all changes' ), 'savebutton', 'save', false ); ?> |
2445 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
2529 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
2446 </p> |
2530 </p> |
2447 </form> |
2531 </form> |
2448 <?php |
2532 <?php |
2449 } |
2533 } |
2482 $view = $table_class = 'not-image'; |
2566 $view = $table_class = 'not-image'; |
2483 } |
2567 } |
2484 |
2568 |
2485 return ' |
2569 return ' |
2486 <p class="media-types"><label><input type="radio" name="media_type" value="image" id="image-only"' . checked( 'image-only', $view, false ) . ' /> ' . __( 'Image' ) . '</label> <label><input type="radio" name="media_type" value="generic" id="not-image"' . checked( 'not-image', $view, false ) . ' /> ' . __( 'Audio, Video, or Other File' ) . '</label></p> |
2570 <p class="media-types"><label><input type="radio" name="media_type" value="image" id="image-only"' . checked( 'image-only', $view, false ) . ' /> ' . __( 'Image' ) . '</label> <label><input type="radio" name="media_type" value="generic" id="not-image"' . checked( 'not-image', $view, false ) . ' /> ' . __( 'Audio, Video, or Other File' ) . '</label></p> |
|
2571 <p class="media-types media-types-required-info">' . sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) . '</p> |
2487 <table class="describe ' . $table_class . '"><tbody> |
2572 <table class="describe ' . $table_class . '"><tbody> |
2488 <tr> |
2573 <tr> |
2489 <th scope="row" class="label" style="width:130px;"> |
2574 <th scope="row" class="label" style="width:130px;"> |
2490 <label for="src"><span class="alignleft">' . __('URL') . '</span></label> |
2575 <label for="src"><span class="alignleft">' . __( 'URL' ) . '</span> <span class="required">*</span></label> |
2491 <span class="alignright"><abbr id="status_img" title="required" class="required">*</abbr></span> |
2576 <span class="alignright" id="status_img"></span> |
2492 </th> |
2577 </th> |
2493 <td class="field"><input id="src" name="src" value="" type="text" aria-required="true" onblur="addExtImage.getImageData()" /></td> |
2578 <td class="field"><input id="src" name="src" value="" type="text" required aria-required="true" onblur="addExtImage.getImageData()" /></td> |
2494 </tr> |
2579 </tr> |
2495 |
2580 |
2496 <tr> |
2581 <tr> |
2497 <th scope="row" class="label"> |
2582 <th scope="row" class="label"> |
2498 <label for="title"><span class="alignleft">' . __('Title') . '</span></label> |
2583 <label for="title"><span class="alignleft">' . __( 'Title' ) . '</span> <span class="required">*</span></label> |
2499 <span class="alignright"><abbr title="required" class="required">*</abbr></span> |
|
2500 </th> |
2584 </th> |
2501 <td class="field"><input id="title" name="title" value="" type="text" aria-required="true" /></td> |
2585 <td class="field"><input id="title" name="title" value="" type="text" required aria-required="true" /></td> |
2502 </tr> |
2586 </tr> |
2503 |
2587 |
2504 <tr class="not-image"><td></td><td><p class="help">' . __('Link text, e.g. “Ransom Demands (PDF)”') . '</p></td></tr> |
2588 <tr class="not-image"><td></td><td><p class="help">' . __('Link text, e.g. “Ransom Demands (PDF)”') . '</p></td></tr> |
2505 |
2589 |
2506 <tr class="image-only"> |
2590 <tr class="image-only"> |
2642 $thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 450 ), true ); |
2728 $thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 450 ), true ); |
2643 |
2729 |
2644 $alt_text = get_post_meta( $post->ID, '_wp_attachment_image_alt', true ); |
2730 $alt_text = get_post_meta( $post->ID, '_wp_attachment_image_alt', true ); |
2645 |
2731 |
2646 $att_url = wp_get_attachment_url( $post->ID ); ?> |
2732 $att_url = wp_get_attachment_url( $post->ID ); ?> |
2647 <div class="wp_attachment_holder"> |
2733 <div class="wp_attachment_holder wp-clearfix"> |
2648 <?php |
2734 <?php |
2649 if ( wp_attachment_is_image( $post->ID ) ) : |
2735 if ( wp_attachment_is_image( $post->ID ) ) : |
2650 $image_edit_button = ''; |
2736 $image_edit_button = ''; |
2651 if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { |
2737 if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { |
2652 $nonce = wp_create_nonce( "image_editor-$post->ID" ); |
2738 $nonce = wp_create_nonce( "image_editor-$post->ID" ); |
2654 } |
2740 } |
2655 ?> |
2741 ?> |
2656 |
2742 |
2657 <div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div> |
2743 <div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div> |
2658 |
2744 |
2659 <div<?php if ( $open ) echo ' style="display:none"'; ?> class="wp_attachment_image" id="media-head-<?php echo $attachment_id; ?>"> |
2745 <div<?php if ( $open ) echo ' style="display:none"'; ?> class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>"> |
2660 <p id="thumbnail-head-<?php echo $attachment_id; ?>"><img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" /></p> |
2746 <p id="thumbnail-head-<?php echo $attachment_id; ?>"><img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" /></p> |
2661 <p><?php echo $image_edit_button; ?></p> |
2747 <p><?php echo $image_edit_button; ?></p> |
2662 </div> |
2748 </div> |
2663 <div<?php if ( ! $open ) echo ' style="display:none"'; ?> class="image-editor" id="image-editor-<?php echo $attachment_id; ?>"> |
2749 <div<?php if ( ! $open ) echo ' style="display:none"'; ?> class="image-editor" id="image-editor-<?php echo $attachment_id; ?>"> |
2664 <?php if ( $open ) wp_image_editor( $attachment_id ); ?> |
2750 <?php if ( $open ) wp_image_editor( $attachment_id ); ?> |
2691 if ( ! empty( $thumb_id ) ) { |
2777 if ( ! empty( $thumb_id ) ) { |
2692 $attr['poster'] = wp_get_attachment_url( $thumb_id ); |
2778 $attr['poster'] = wp_get_attachment_url( $thumb_id ); |
2693 } |
2779 } |
2694 |
2780 |
2695 echo wp_video_shortcode( $attr ); |
2781 echo wp_video_shortcode( $attr ); |
|
2782 |
|
2783 elseif ( isset( $thumb_url[0] ) ): |
|
2784 |
|
2785 ?> |
|
2786 <div class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>"> |
|
2787 <p id="thumbnail-head-<?php echo $attachment_id; ?>"> |
|
2788 <img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" /> |
|
2789 </p> |
|
2790 </div> |
|
2791 <?php |
|
2792 |
|
2793 else: |
|
2794 |
|
2795 /** |
|
2796 * Fires when an attachment type can't be rendered in the edit form. |
|
2797 * |
|
2798 * @since 4.6.0 |
|
2799 * |
|
2800 * @param WP_Post $post A post object. |
|
2801 */ |
|
2802 do_action( 'wp_edit_form_attachment_display', $post ); |
2696 |
2803 |
2697 endif; ?> |
2804 endif; ?> |
2698 </div> |
2805 </div> |
2699 <div class="wp_attachment_details edit-form-section"> |
2806 <div class="wp_attachment_details edit-form-section"> |
2700 <p> |
2807 <p> |
2733 echo $extras['item']; |
2840 echo $extras['item']; |
2734 echo '<input type="hidden" id="image-edit-context" value="edit-attachment" />' . "\n"; |
2841 echo '<input type="hidden" id="image-edit-context" value="edit-attachment" />' . "\n"; |
2735 } |
2842 } |
2736 |
2843 |
2737 /** |
2844 /** |
2738 * Displays non-editable attachment metadata in the publish metabox |
2845 * Displays non-editable attachment metadata in the publish meta box. |
2739 * |
2846 * |
2740 * @since 3.5.0 |
2847 * @since 3.5.0 |
2741 */ |
2848 */ |
2742 function attachment_submitbox_metadata() { |
2849 function attachment_submitbox_metadata() { |
2743 $post = get_post(); |
2850 $post = get_post(); |
2744 |
2851 |
2745 $filename = esc_html( wp_basename( $post->guid ) ); |
2852 $file = get_attached_file( $post->ID ); |
|
2853 $filename = esc_html( wp_basename( $file ) ); |
2746 |
2854 |
2747 $media_dims = ''; |
2855 $media_dims = ''; |
2748 $meta = wp_get_attachment_metadata( $post->ID ); |
2856 $meta = wp_get_attachment_metadata( $post->ID ); |
2749 if ( isset( $meta['width'], $meta['height'] ) ) |
2857 if ( isset( $meta['width'], $meta['height'] ) ) |
2750 $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']} × {$meta['height']}</span> "; |
2858 $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']} × {$meta['height']}</span> "; |
2752 $media_dims = apply_filters( 'media_meta', $media_dims, $post ); |
2860 $media_dims = apply_filters( 'media_meta', $media_dims, $post ); |
2753 |
2861 |
2754 $att_url = wp_get_attachment_url( $post->ID ); |
2862 $att_url = wp_get_attachment_url( $post->ID ); |
2755 ?> |
2863 ?> |
2756 <div class="misc-pub-section misc-pub-attachment"> |
2864 <div class="misc-pub-section misc-pub-attachment"> |
2757 <label for="attachment_url"><?php _e( 'File URL:' ); ?></label> |
2865 <label for="attachment_url"><?php _e( 'File URL:' ); ?></label> |
2758 <input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" value="<?php echo esc_attr($att_url); ?>" /> |
2866 <input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" id="attachment_url" value="<?php echo esc_attr( $att_url ); ?>" /> |
2759 </div> |
2867 </div> |
2760 <div class="misc-pub-section misc-pub-filename"> |
2868 <div class="misc-pub-section misc-pub-filename"> |
2761 <?php _e( 'File name:' ); ?> <strong><?php echo $filename; ?></strong> |
2869 <?php _e( 'File name:' ); ?> <strong><?php echo $filename; ?></strong> |
2762 </div> |
2870 </div> |
2763 <div class="misc-pub-section misc-pub-filetype"> |
2871 <div class="misc-pub-section misc-pub-filetype"> |
2791 </div> |
2898 </div> |
2792 <?php |
2899 <?php |
2793 endif; |
2900 endif; |
2794 |
2901 |
2795 if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) { |
2902 if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) { |
|
2903 $fields = array( |
|
2904 'length_formatted' => __( 'Length:' ), |
|
2905 'bitrate' => __( 'Bitrate:' ), |
|
2906 ); |
2796 |
2907 |
2797 /** |
2908 /** |
2798 * Filter the audio and video metadata fields to be shown in the publish meta box. |
2909 * Filters the audio and video metadata fields to be shown in the publish meta box. |
2799 * |
2910 * |
2800 * The key for each item in the array should correspond to an attachment |
2911 * The key for each item in the array should correspond to an attachment |
2801 * metadata key, and the value should be the desired label. |
2912 * metadata key, and the value should be the desired label. |
2802 * |
2913 * |
2803 * @since 3.7.0 |
2914 * @since 3.7.0 |
|
2915 * @since 4.9.0 Added the `$post` parameter. |
2804 * |
2916 * |
2805 * @param array $fields An array of the attachment metadata keys and labels. |
2917 * @param array $fields An array of the attachment metadata keys and labels. |
|
2918 * @param WP_Post $post WP_Post object for the current attachment. |
2806 */ |
2919 */ |
2807 $fields = apply_filters( 'media_submitbox_misc_sections', array( |
2920 $fields = apply_filters( 'media_submitbox_misc_sections', $fields, $post ); |
2808 'length_formatted' => __( 'Length:' ), |
|
2809 'bitrate' => __( 'Bitrate:' ), |
|
2810 ) ); |
|
2811 |
2921 |
2812 foreach ( $fields as $key => $label ) { |
2922 foreach ( $fields as $key => $label ) { |
2813 if ( empty( $meta[ $key ] ) ) { |
2923 if ( empty( $meta[ $key ] ) ) { |
2814 continue; |
2924 continue; |
2815 } |
2925 } |
2830 ?></strong> |
2940 ?></strong> |
2831 </div> |
2941 </div> |
2832 <?php |
2942 <?php |
2833 } |
2943 } |
2834 |
2944 |
|
2945 $fields = array( |
|
2946 'dataformat' => __( 'Audio Format:' ), |
|
2947 'codec' => __( 'Audio Codec:' ) |
|
2948 ); |
|
2949 |
2835 /** |
2950 /** |
2836 * Filter the audio attachment metadata fields to be shown in the publish meta box. |
2951 * Filters the audio attachment metadata fields to be shown in the publish meta box. |
2837 * |
2952 * |
2838 * The key for each item in the array should correspond to an attachment |
2953 * The key for each item in the array should correspond to an attachment |
2839 * metadata key, and the value should be the desired label. |
2954 * metadata key, and the value should be the desired label. |
2840 * |
2955 * |
2841 * @since 3.7.0 |
2956 * @since 3.7.0 |
|
2957 * @since 4.9.0 Added the `$post` parameter. |
2842 * |
2958 * |
2843 * @param array $fields An array of the attachment metadata keys and labels. |
2959 * @param array $fields An array of the attachment metadata keys and labels. |
|
2960 * @param WP_Post $post WP_Post object for the current attachment. |
2844 */ |
2961 */ |
2845 $audio_fields = apply_filters( 'audio_submitbox_misc_sections', array( |
2962 $audio_fields = apply_filters( 'audio_submitbox_misc_sections', $fields, $post ); |
2846 'dataformat' => __( 'Audio Format:' ), |
|
2847 'codec' => __( 'Audio Codec:' ) |
|
2848 ) ); |
|
2849 |
2963 |
2850 foreach ( $audio_fields as $key => $label ) { |
2964 foreach ( $audio_fields as $key => $label ) { |
2851 if ( empty( $meta['audio'][ $key ] ) ) { |
2965 if ( empty( $meta['audio'][ $key ] ) ) { |
2852 continue; |
2966 continue; |
2853 } |
2967 } |
2866 </div> |
2980 </div> |
2867 <?php |
2981 <?php |
2868 endif; |
2982 endif; |
2869 } |
2983 } |
2870 |
2984 |
2871 add_filter( 'async_upload_image', 'get_media_item', 10, 2 ); |
|
2872 add_filter( 'async_upload_audio', 'get_media_item', 10, 2 ); |
|
2873 add_filter( 'async_upload_video', 'get_media_item', 10, 2 ); |
|
2874 add_filter( 'async_upload_file', 'get_media_item', 10, 2 ); |
|
2875 |
|
2876 add_action( 'media_upload_image', 'wp_media_upload_handler' ); |
|
2877 add_action( 'media_upload_audio', 'wp_media_upload_handler' ); |
|
2878 add_action( 'media_upload_video', 'wp_media_upload_handler' ); |
|
2879 add_action( 'media_upload_file', 'wp_media_upload_handler' ); |
|
2880 |
|
2881 add_filter( 'media_upload_gallery', 'media_upload_gallery' ); |
|
2882 add_filter( 'media_upload_library', 'media_upload_library' ); |
|
2883 |
|
2884 add_action( 'attachment_submitbox_misc_actions', 'attachment_submitbox_metadata' ); |
|
2885 |
|
2886 /** |
2985 /** |
2887 * Parse ID3v2, ID3v1, and getID3 comments to extract usable data |
2986 * Parse ID3v2, ID3v1, and getID3 comments to extract usable data |
2888 * |
2987 * |
2889 * @since 3.6.0 |
2988 * @since 3.6.0 |
2890 * |
2989 * |
2894 function wp_add_id3_tag_data( &$metadata, $data ) { |
2993 function wp_add_id3_tag_data( &$metadata, $data ) { |
2895 foreach ( array( 'id3v2', 'id3v1' ) as $version ) { |
2994 foreach ( array( 'id3v2', 'id3v1' ) as $version ) { |
2896 if ( ! empty( $data[$version]['comments'] ) ) { |
2995 if ( ! empty( $data[$version]['comments'] ) ) { |
2897 foreach ( $data[$version]['comments'] as $key => $list ) { |
2996 foreach ( $data[$version]['comments'] as $key => $list ) { |
2898 if ( 'length' !== $key && ! empty( $list ) ) { |
2997 if ( 'length' !== $key && ! empty( $list ) ) { |
2899 $metadata[$key] = reset( $list ); |
2998 $metadata[$key] = wp_kses_post( reset( $list ) ); |
2900 // Fix bug in byte stream analysis. |
2999 // Fix bug in byte stream analysis. |
2901 if ( 'terms_of_use' === $key && 0 === strpos( $metadata[$key], 'yright notice.' ) ) |
3000 if ( 'terms_of_use' === $key && 0 === strpos( $metadata[$key], 'yright notice.' ) ) |
2902 $metadata[$key] = 'Cop' . $metadata[$key]; |
3001 $metadata[$key] = 'Cop' . $metadata[$key]; |
2903 } |
3002 } |
2904 } |
3003 } |
2934 * |
3033 * |
2935 * @param string $file Path to file. |
3034 * @param string $file Path to file. |
2936 * @return array|bool Returns array of metadata, if found. |
3035 * @return array|bool Returns array of metadata, if found. |
2937 */ |
3036 */ |
2938 function wp_read_video_metadata( $file ) { |
3037 function wp_read_video_metadata( $file ) { |
2939 if ( ! file_exists( $file ) ) |
3038 if ( ! file_exists( $file ) ) { |
2940 return false; |
3039 return false; |
|
3040 } |
2941 |
3041 |
2942 $metadata = array(); |
3042 $metadata = array(); |
2943 |
3043 |
2944 if ( ! class_exists( 'getID3' ) ) |
3044 if ( ! defined( 'GETID3_TEMP_DIR' ) ) { |
|
3045 define( 'GETID3_TEMP_DIR', get_temp_dir() ); |
|
3046 } |
|
3047 |
|
3048 if ( ! class_exists( 'getID3', false ) ) { |
2945 require( ABSPATH . WPINC . '/ID3/getid3.php' ); |
3049 require( ABSPATH . WPINC . '/ID3/getid3.php' ); |
|
3050 } |
2946 $id3 = new getID3(); |
3051 $id3 = new getID3(); |
2947 $data = $id3->analyze( $file ); |
3052 $data = $id3->analyze( $file ); |
2948 |
3053 |
2949 if ( isset( $data['video']['lossless'] ) ) |
3054 if ( isset( $data['video']['lossless'] ) ) |
2950 $metadata['lossless'] = $data['video']['lossless']; |
3055 $metadata['lossless'] = $data['video']['lossless']; |
2976 if ( ! empty( $data['audio'] ) ) { |
3081 if ( ! empty( $data['audio'] ) ) { |
2977 unset( $data['audio']['streams'] ); |
3082 unset( $data['audio']['streams'] ); |
2978 $metadata['audio'] = $data['audio']; |
3083 $metadata['audio'] = $data['audio']; |
2979 } |
3084 } |
2980 |
3085 |
|
3086 if ( empty( $metadata['created_timestamp'] ) ) { |
|
3087 $created_timestamp = wp_get_media_creation_timestamp( $data ); |
|
3088 |
|
3089 if ( $created_timestamp !== false ) { |
|
3090 $metadata['created_timestamp'] = $created_timestamp; |
|
3091 } |
|
3092 } |
|
3093 |
2981 wp_add_id3_tag_data( $metadata, $data ); |
3094 wp_add_id3_tag_data( $metadata, $data ); |
2982 |
3095 |
2983 return $metadata; |
3096 $file_format = isset( $metadata['fileformat'] ) ? $metadata['fileformat'] : null; |
|
3097 |
|
3098 /** |
|
3099 * Filters the array of metadata retrieved from a video. |
|
3100 * |
|
3101 * In core, usually this selection is what is stored. |
|
3102 * More complete data can be parsed from the `$data` parameter. |
|
3103 * |
|
3104 * @since 4.9.0 |
|
3105 * |
|
3106 * @param array $metadata Filtered Video metadata. |
|
3107 * @param string $file Path to video file. |
|
3108 * @param string $file_format File format of video, as analyzed by getID3. |
|
3109 * @param string $data Raw metadata from getID3. |
|
3110 */ |
|
3111 return apply_filters( 'wp_read_video_metadata', $metadata, $file, $file_format, $data ); |
2984 } |
3112 } |
2985 |
3113 |
2986 /** |
3114 /** |
2987 * Retrieve metadata from a audio file's ID3 tags |
3115 * Retrieve metadata from a audio file's ID3 tags |
2988 * |
3116 * |
2989 * @since 3.6.0 |
3117 * @since 3.6.0 |
2990 * |
3118 * |
2991 * @param string $file Path to file. |
3119 * @param string $file Path to file. |
2992 * @return array|boolean Returns array of metadata, if found. |
3120 * @return array|bool Returns array of metadata, if found. |
2993 */ |
3121 */ |
2994 function wp_read_audio_metadata( $file ) { |
3122 function wp_read_audio_metadata( $file ) { |
2995 if ( ! file_exists( $file ) ) |
3123 if ( ! file_exists( $file ) ) { |
2996 return false; |
3124 return false; |
|
3125 } |
2997 $metadata = array(); |
3126 $metadata = array(); |
2998 |
3127 |
2999 if ( ! class_exists( 'getID3' ) ) |
3128 if ( ! defined( 'GETID3_TEMP_DIR' ) ) { |
|
3129 define( 'GETID3_TEMP_DIR', get_temp_dir() ); |
|
3130 } |
|
3131 |
|
3132 if ( ! class_exists( 'getID3', false ) ) { |
3000 require( ABSPATH . WPINC . '/ID3/getid3.php' ); |
3133 require( ABSPATH . WPINC . '/ID3/getid3.php' ); |
|
3134 } |
3001 $id3 = new getID3(); |
3135 $id3 = new getID3(); |
3002 $data = $id3->analyze( $file ); |
3136 $data = $id3->analyze( $file ); |
3003 |
3137 |
3004 if ( ! empty( $data['audio'] ) ) { |
3138 if ( ! empty( $data['audio'] ) ) { |
3005 unset( $data['audio']['streams'] ); |
3139 unset( $data['audio']['streams'] ); |
3021 |
3155 |
3022 return $metadata; |
3156 return $metadata; |
3023 } |
3157 } |
3024 |
3158 |
3025 /** |
3159 /** |
|
3160 * Parse creation date from media metadata. |
|
3161 * |
|
3162 * The getID3 library doesn't have a standard method for getting creation dates, |
|
3163 * so the location of this data can vary based on the MIME type. |
|
3164 * |
|
3165 * @since 4.9.0 |
|
3166 * |
|
3167 * @link https://github.com/JamesHeinrich/getID3/blob/master/structure.txt |
|
3168 * |
|
3169 * @param array $metadata The metadata returned by getID3::analyze(). |
|
3170 * @return int|bool A UNIX timestamp for the media's creation date if available |
|
3171 * or a boolean FALSE if a timestamp could not be determined. |
|
3172 */ |
|
3173 function wp_get_media_creation_timestamp( $metadata ) { |
|
3174 $creation_date = false; |
|
3175 |
|
3176 if ( empty( $metadata['fileformat'] ) ) { |
|
3177 return $creation_date; |
|
3178 } |
|
3179 |
|
3180 switch ( $metadata['fileformat'] ) { |
|
3181 case 'asf': |
|
3182 if ( isset( $metadata['asf']['file_properties_object']['creation_date_unix'] ) ) { |
|
3183 $creation_date = (int) $metadata['asf']['file_properties_object']['creation_date_unix']; |
|
3184 } |
|
3185 break; |
|
3186 |
|
3187 case 'matroska': |
|
3188 case 'webm': |
|
3189 if ( isset( $metadata['matroska']['comments']['creation_time']['0'] ) ) { |
|
3190 $creation_date = strtotime( $metadata['matroska']['comments']['creation_time']['0'] ); |
|
3191 } |
|
3192 elseif ( isset( $metadata['matroska']['info']['0']['DateUTC_unix'] ) ) { |
|
3193 $creation_date = (int) $metadata['matroska']['info']['0']['DateUTC_unix']; |
|
3194 } |
|
3195 break; |
|
3196 |
|
3197 case 'quicktime': |
|
3198 case 'mp4': |
|
3199 if ( isset( $metadata['quicktime']['moov']['subatoms']['0']['creation_time_unix'] ) ) { |
|
3200 $creation_date = (int) $metadata['quicktime']['moov']['subatoms']['0']['creation_time_unix']; |
|
3201 } |
|
3202 break; |
|
3203 } |
|
3204 |
|
3205 return $creation_date; |
|
3206 } |
|
3207 |
|
3208 /** |
3026 * Encapsulate logic for Attach/Detach actions |
3209 * Encapsulate logic for Attach/Detach actions |
3027 * |
3210 * |
3028 * @since 4.2.0 |
3211 * @since 4.2.0 |
3029 * |
3212 * |
3030 * @global wpdb $wpdb WordPress database abstraction object. |
3213 * @global wpdb $wpdb WordPress database abstraction object. |