268 * be set to 0, creating a media item that has no relationship to a post. |
282 * be set to 0, creating a media item that has no relationship to a post. |
269 * @param array $post_data Overwrite some of the attachment. Optional. |
283 * @param array $post_data Overwrite some of the attachment. Optional. |
270 * @param array $overrides Override the wp_handle_upload() behavior. Optional. |
284 * @param array $overrides Override the wp_handle_upload() behavior. Optional. |
271 * @return int|WP_Error ID of the attachment or a WP_Error object on failure. |
285 * @return int|WP_Error ID of the attachment or a WP_Error object on failure. |
272 */ |
286 */ |
273 function media_handle_upload($file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false )) { |
287 function media_handle_upload( $file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false ) ) { |
274 |
288 |
275 $time = current_time('mysql'); |
289 $time = current_time( 'mysql' ); |
276 if ( $post = get_post($post_id) ) { |
290 if ( $post = get_post( $post_id ) ) { |
277 // The post date doesn't usually matter for pages, so don't backdate this upload. |
291 // 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 ) |
292 if ( 'page' !== $post->post_type && substr( $post->post_date, 0, 4 ) > 0 ) { |
279 $time = $post->post_date; |
293 $time = $post->post_date; |
280 } |
294 } |
281 |
295 } |
282 $file = wp_handle_upload($_FILES[$file_id], $overrides, $time); |
296 |
283 |
297 $file = wp_handle_upload( $_FILES[ $file_id ], $overrides, $time ); |
284 if ( isset($file['error']) ) |
298 |
|
299 if ( isset( $file['error'] ) ) { |
285 return new WP_Error( 'upload_error', $file['error'] ); |
300 return new WP_Error( 'upload_error', $file['error'] ); |
286 |
301 } |
287 $name = $_FILES[$file_id]['name']; |
302 |
|
303 $name = $_FILES[ $file_id ]['name']; |
288 $ext = pathinfo( $name, PATHINFO_EXTENSION ); |
304 $ext = pathinfo( $name, PATHINFO_EXTENSION ); |
289 $name = wp_basename( $name, ".$ext" ); |
305 $name = wp_basename( $name, ".$ext" ); |
290 |
306 |
291 $url = $file['url']; |
307 $url = $file['url']; |
292 $type = $file['type']; |
308 $type = $file['type']; |
293 $file = $file['file']; |
309 $file = $file['file']; |
294 $title = sanitize_text_field( $name ); |
310 $title = sanitize_text_field( $name ); |
295 $content = ''; |
311 $content = ''; |
296 $excerpt = ''; |
312 $excerpt = ''; |
297 |
313 |
298 if ( preg_match( '#^audio#', $type ) ) { |
314 if ( preg_match( '#^audio#', $type ) ) { |
299 $meta = wp_read_audio_metadata( $file ); |
315 $meta = wp_read_audio_metadata( $file ); |
315 $content .= sprintf( __( '"%1$s" by %2$s.' ), $title, $meta['artist'] ); |
331 $content .= sprintf( __( '"%1$s" by %2$s.' ), $title, $meta['artist'] ); |
316 } else { |
332 } else { |
317 /* translators: 1: audio track title */ |
333 /* translators: 1: audio track title */ |
318 $content .= sprintf( __( '"%s".' ), $title ); |
334 $content .= sprintf( __( '"%s".' ), $title ); |
319 } |
335 } |
320 |
|
321 } elseif ( ! empty( $meta['album'] ) ) { |
336 } elseif ( ! empty( $meta['album'] ) ) { |
322 |
337 |
323 if ( ! empty( $meta['artist'] ) ) { |
338 if ( ! empty( $meta['artist'] ) ) { |
324 /* translators: 1: audio album title, 2: artist name */ |
339 /* translators: 1: audio album title, 2: artist name */ |
325 $content .= sprintf( __( '%1$s by %2$s.' ), $meta['album'], $meta['artist'] ); |
340 $content .= sprintf( __( '%1$s by %2$s.' ), $meta['album'], $meta['artist'] ); |
326 } else { |
341 } else { |
327 $content .= $meta['album'] . '.'; |
342 $content .= $meta['album'] . '.'; |
328 } |
343 } |
329 |
|
330 } elseif ( ! empty( $meta['artist'] ) ) { |
344 } elseif ( ! empty( $meta['artist'] ) ) { |
331 |
345 |
332 $content .= $meta['artist'] . '.'; |
346 $content .= $meta['artist'] . '.'; |
333 |
347 |
334 } |
348 } |
335 |
349 |
336 if ( ! empty( $meta['year'] ) ) { |
350 if ( ! empty( $meta['year'] ) ) { |
337 /* translators: Audio file track information. 1: Year of audio track release */ |
351 /* translators: Audio file track information. %d: Year of audio track release */ |
338 $content .= ' ' . sprintf( __( 'Released: %d.' ), $meta['year'] ); |
352 $content .= ' ' . sprintf( __( 'Released: %d.' ), $meta['year'] ); |
339 } |
353 } |
340 |
354 |
341 if ( ! empty( $meta['track_number'] ) ) { |
355 if ( ! empty( $meta['track_number'] ) ) { |
342 $track_number = explode( '/', $meta['track_number'] ); |
356 $track_number = explode( '/', $meta['track_number'] ); |
343 if ( isset( $track_number[1] ) ) { |
357 if ( isset( $track_number[1] ) ) { |
344 /* translators: Audio file track information. 1: Audio track number, 2: Total audio tracks */ |
358 /* translators: Audio file track information. 1: Audio track number, 2: Total audio tracks */ |
345 $content .= ' ' . sprintf( __( 'Track %1$s of %2$s.' ), number_format_i18n( $track_number[0] ), number_format_i18n( $track_number[1] ) ); |
359 $content .= ' ' . sprintf( __( 'Track %1$s of %2$s.' ), number_format_i18n( $track_number[0] ), number_format_i18n( $track_number[1] ) ); |
346 } else { |
360 } else { |
347 /* translators: Audio file track information. 1: Audio track number */ |
361 /* translators: Audio file track information. %s: Audio track number */ |
348 $content .= ' ' . sprintf( __( 'Track %1$s.' ), number_format_i18n( $track_number[0] ) ); |
362 $content .= ' ' . sprintf( __( 'Track %s.' ), number_format_i18n( $track_number[0] ) ); |
349 } |
363 } |
350 } |
364 } |
351 |
365 |
352 if ( ! empty( $meta['genre'] ) ) { |
366 if ( ! empty( $meta['genre'] ) ) { |
353 /* translators: Audio file genre information. 1: Audio genre name */ |
367 /* translators: Audio file genre information. %s: Audio genre name */ |
354 $content .= ' ' . sprintf( __( 'Genre: %s.' ), $meta['genre'] ); |
368 $content .= ' ' . sprintf( __( 'Genre: %s.' ), $meta['genre'] ); |
355 } |
369 } |
356 |
370 |
357 // Use image exif/iptc data for title and caption defaults if possible. |
371 // Use image exif/iptc data for title and caption defaults if possible. |
358 } elseif ( 0 === strpos( $type, 'image/' ) && $image_meta = wp_read_image_metadata( $file ) ) { |
372 } elseif ( 0 === strpos( $type, 'image/' ) && $image_meta = wp_read_image_metadata( $file ) ) { |
359 if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) { |
373 if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) { |
360 $title = $image_meta['title']; |
374 $title = $image_meta['title']; |
361 } |
375 } |
362 |
376 |
398 * @param string $desc Optional. Description of the side-loaded file. Default null. |
415 * @param string $desc Optional. Description of the side-loaded file. Default null. |
399 * @param array $post_data Optional. Post data to override. Default empty array. |
416 * @param array $post_data Optional. Post data to override. Default empty array. |
400 * @return int|object The ID of the attachment or a WP_Error on failure. |
417 * @return int|object The ID of the attachment or a WP_Error on failure. |
401 */ |
418 */ |
402 function media_handle_sideload( $file_array, $post_id, $desc = null, $post_data = array() ) { |
419 function media_handle_sideload( $file_array, $post_id, $desc = null, $post_data = array() ) { |
403 $overrides = array('test_form'=>false); |
420 $overrides = array( 'test_form' => false ); |
404 |
421 |
405 $time = current_time( 'mysql' ); |
422 $time = current_time( 'mysql' ); |
406 if ( $post = get_post( $post_id ) ) { |
423 if ( $post = get_post( $post_id ) ) { |
407 if ( substr( $post->post_date, 0, 4 ) > 0 ) |
424 if ( substr( $post->post_date, 0, 4 ) > 0 ) { |
408 $time = $post->post_date; |
425 $time = $post->post_date; |
|
426 } |
409 } |
427 } |
410 |
428 |
411 $file = wp_handle_sideload( $file_array, $overrides, $time ); |
429 $file = wp_handle_sideload( $file_array, $overrides, $time ); |
412 if ( isset($file['error']) ) |
430 if ( isset( $file['error'] ) ) { |
413 return new WP_Error( 'upload_error', $file['error'] ); |
431 return new WP_Error( 'upload_error', $file['error'] ); |
414 |
432 } |
415 $url = $file['url']; |
433 |
416 $type = $file['type']; |
434 $url = $file['url']; |
417 $file = $file['file']; |
435 $type = $file['type']; |
418 $title = preg_replace('/\.[^.]+$/', '', basename($file)); |
436 $file = $file['file']; |
|
437 $title = preg_replace( '/\.[^.]+$/', '', wp_basename( $file ) ); |
419 $content = ''; |
438 $content = ''; |
420 |
439 |
421 // Use image exif/iptc data for title and caption defaults if possible. |
440 // Use image exif/iptc data for title and caption defaults if possible. |
422 if ( $image_meta = wp_read_image_metadata( $file ) ) { |
441 if ( $image_meta = wp_read_image_metadata( $file ) ) { |
423 if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) |
442 if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) { |
424 $title = $image_meta['title']; |
443 $title = $image_meta['title']; |
425 if ( trim( $image_meta['caption'] ) ) |
444 } |
|
445 if ( trim( $image_meta['caption'] ) ) { |
426 $content = $image_meta['caption']; |
446 $content = $image_meta['caption']; |
427 } |
447 } |
428 |
448 } |
429 if ( isset( $desc ) ) |
449 |
|
450 if ( isset( $desc ) ) { |
430 $title = $desc; |
451 $title = $desc; |
|
452 } |
431 |
453 |
432 // Construct the attachment array. |
454 // Construct the attachment array. |
433 $attachment = array_merge( array( |
455 $attachment = array_merge( |
434 'post_mime_type' => $type, |
456 array( |
435 'guid' => $url, |
457 'post_mime_type' => $type, |
436 'post_parent' => $post_id, |
458 'guid' => $url, |
437 'post_title' => $title, |
459 'post_parent' => $post_id, |
438 'post_content' => $content, |
460 'post_title' => $title, |
439 ), $post_data ); |
461 'post_content' => $content, |
|
462 ), |
|
463 $post_data |
|
464 ); |
440 |
465 |
441 // This should never be set as it would then overwrite an existing attachment. |
466 // This should never be set as it would then overwrite an existing attachment. |
442 unset( $attachment['ID'] ); |
467 unset( $attachment['ID'] ); |
443 |
468 |
444 // Save the attachment metadata |
469 // Save the attachment metadata |
445 $id = wp_insert_attachment($attachment, $file, $post_id); |
470 $id = wp_insert_attachment( $attachment, $file, $post_id, true ); |
446 if ( !is_wp_error($id) ) |
471 if ( ! is_wp_error( $id ) ) { |
447 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); |
472 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); |
|
473 } |
448 |
474 |
449 return $id; |
475 return $id; |
450 } |
476 } |
451 |
477 |
452 /** |
478 /** |
456 * |
482 * |
457 * @global int $body_id |
483 * @global int $body_id |
458 * |
484 * |
459 * @param string|callable $content_func |
485 * @param string|callable $content_func |
460 */ |
486 */ |
461 function wp_iframe($content_func /* ... */) { |
487 function wp_iframe( $content_func /* ... */ ) { |
462 _wp_admin_html_begin(); |
488 _wp_admin_html_begin(); |
463 ?> |
489 ?> |
464 <title><?php bloginfo('name') ?> › <?php _e('Uploads'); ?> — <?php _e('WordPress'); ?></title> |
490 <title><?php bloginfo( 'name' ); ?> › <?php _e( 'Uploads' ); ?> — <?php _e( 'WordPress' ); ?></title> |
465 <?php |
491 <?php |
466 |
492 |
467 wp_enqueue_style( 'colors' ); |
493 wp_enqueue_style( 'colors' ); |
468 // Check callback name for 'media' |
494 // Check callback name for 'media' |
469 if ( ( is_array( $content_func ) && ! empty( $content_func[1] ) && 0 === strpos( (string) $content_func[1], 'media' ) ) |
495 if ( ( is_array( $content_func ) && ! empty( $content_func[1] ) && 0 === strpos( (string) $content_func[1], 'media' ) ) |
470 || ( ! is_array( $content_func ) && 0 === strpos( $content_func, 'media' ) ) ) |
496 || ( ! is_array( $content_func ) && 0 === strpos( $content_func, 'media' ) ) ) { |
471 wp_enqueue_style( 'deprecated-media' ); |
497 wp_enqueue_style( 'deprecated-media' ); |
472 wp_enqueue_style( 'ie' ); |
498 } |
473 ?> |
499 wp_enqueue_style( 'ie' ); |
|
500 ?> |
474 <script type="text/javascript"> |
501 <script type="text/javascript"> |
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();}}}; |
502 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();}}}; |
476 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup', |
503 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup', |
477 isRtl = <?php echo (int) is_rtl(); ?>; |
504 isRtl = <?php echo (int) is_rtl(); ?>; |
478 </script> |
505 </script> |
479 <?php |
506 <?php |
480 /** This action is documented in wp-admin/admin-header.php */ |
507 /** This action is documented in wp-admin/admin-header.php */ |
481 do_action( 'admin_enqueue_scripts', 'media-upload-popup' ); |
508 do_action( 'admin_enqueue_scripts', 'media-upload-popup' ); |
482 |
509 |
483 /** |
510 /** |
484 * Fires when admin styles enqueued for the legacy (pre-3.5.0) media upload popup are printed. |
511 * Fires when admin styles enqueued for the legacy (pre-3.5.0) media upload popup are printed. |
509 do_action( 'admin_head-media-upload-popup' ); |
536 do_action( 'admin_head-media-upload-popup' ); |
510 |
537 |
511 /** This action is documented in wp-admin/admin-header.php */ |
538 /** This action is documented in wp-admin/admin-header.php */ |
512 do_action( 'admin_head' ); |
539 do_action( 'admin_head' ); |
513 |
540 |
514 if ( is_string( $content_func ) ) { |
541 if ( is_string( $content_func ) ) { |
515 /** |
542 /** |
516 * Fires in the admin header for each specific form tab in the legacy |
543 * Fires in the admin header for each specific form tab in the legacy |
517 * (pre-3.5.0) media upload popup. |
544 * (pre-3.5.0) media upload popup. |
518 * |
545 * |
519 * The dynamic portion of the hook, `$content_func`, refers to the form |
546 * The dynamic portion of the hook, `$content_func`, refers to the form |
520 * callback for the media upload type. Possible values include |
547 * callback for the media upload type. Possible values include |
521 * 'media_upload_type_form', 'media_upload_type_url_form', and |
548 * 'media_upload_type_form', 'media_upload_type_url_form', and |
522 * 'media_upload_library_form'. |
549 * 'media_upload_library_form'. |
523 * |
550 * |
524 * @since 2.5.0 |
551 * @since 2.5.0 |
525 */ |
552 */ |
526 do_action( "admin_head_{$content_func}" ); |
553 do_action( "admin_head_{$content_func}" ); |
527 } |
554 } |
528 ?> |
555 |
|
556 $body_id_attr = ''; |
|
557 if ( isset( $GLOBALS['body_id'] ) ) { |
|
558 $body_id_attr = ' id="' . $GLOBALS['body_id'] . '"'; |
|
559 } |
|
560 ?> |
529 </head> |
561 </head> |
530 <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?> class="wp-core-ui no-js"> |
562 <body<?php echo $body_id_attr; ?> class="wp-core-ui no-js"> |
531 <script type="text/javascript"> |
563 <script type="text/javascript"> |
532 document.body.className = document.body.className.replace('no-js', 'js'); |
564 document.body.className = document.body.className.replace('no-js', 'js'); |
533 </script> |
565 </script> |
534 <?php |
566 <?php |
535 $args = func_get_args(); |
567 $args = func_get_args(); |
536 $args = array_slice($args, 1); |
568 $args = array_slice( $args, 1 ); |
537 call_user_func_array($content_func, $args); |
569 call_user_func_array( $content_func, $args ); |
538 |
570 |
539 /** This action is documented in wp-admin/admin-footer.php */ |
571 /** This action is documented in wp-admin/admin-footer.php */ |
540 do_action( 'admin_print_footer_scripts' ); |
572 do_action( 'admin_print_footer_scripts' ); |
541 ?> |
573 ?> |
542 <script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script> |
574 <script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script> |
543 </body> |
575 </body> |
544 </html> |
576 </html> |
545 <?php |
577 <?php |
546 } |
578 } |
547 |
579 |
548 /** |
580 /** |
549 * Adds the media button to the editor |
581 * Adds the media button to the editor |
550 * |
582 * |
588 */ |
624 */ |
589 $legacy_filter = apply_filters( 'media_buttons_context', '' ); |
625 $legacy_filter = apply_filters( 'media_buttons_context', '' ); |
590 |
626 |
591 if ( $legacy_filter ) { |
627 if ( $legacy_filter ) { |
592 // #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag. |
628 // #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag. |
593 if ( 0 === stripos( trim( $legacy_filter ), '</a>' ) ) |
629 if ( 0 === stripos( trim( $legacy_filter ), '</a>' ) ) { |
594 $legacy_filter .= '</a>'; |
630 $legacy_filter .= '</a>'; |
|
631 } |
595 echo $legacy_filter; |
632 echo $legacy_filter; |
596 } |
633 } |
597 } |
634 } |
598 |
635 |
599 /** |
636 /** |
600 * |
|
601 * @global int $post_ID |
637 * @global int $post_ID |
602 * @param string $type |
638 * @param string $type |
603 * @param int $post_id |
639 * @param int $post_id |
604 * @param string $tab |
640 * @param string $tab |
605 * @return string |
641 * @return string |
606 */ |
642 */ |
607 function get_upload_iframe_src( $type = null, $post_id = null, $tab = null ) { |
643 function get_upload_iframe_src( $type = null, $post_id = null, $tab = null ) { |
608 global $post_ID; |
644 global $post_ID; |
609 |
645 |
610 if ( empty( $post_id ) ) |
646 if ( empty( $post_id ) ) { |
611 $post_id = $post_ID; |
647 $post_id = $post_ID; |
612 |
648 } |
613 $upload_iframe_src = add_query_arg( 'post_id', (int) $post_id, admin_url('media-upload.php') ); |
649 |
614 |
650 $upload_iframe_src = add_query_arg( 'post_id', (int) $post_id, admin_url( 'media-upload.php' ) ); |
615 if ( $type && 'media' != $type ) |
651 |
616 $upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src); |
652 if ( $type && 'media' != $type ) { |
617 |
653 $upload_iframe_src = add_query_arg( 'type', $type, $upload_iframe_src ); |
618 if ( ! empty( $tab ) ) |
654 } |
619 $upload_iframe_src = add_query_arg('tab', $tab, $upload_iframe_src); |
655 |
|
656 if ( ! empty( $tab ) ) { |
|
657 $upload_iframe_src = add_query_arg( 'tab', $tab, $upload_iframe_src ); |
|
658 } |
620 |
659 |
621 /** |
660 /** |
622 * Filters the upload iframe source URL for a specific media type. |
661 * Filters the upload iframe source URL for a specific media type. |
623 * |
662 * |
624 * The dynamic portion of the hook name, `$type`, refers to the type |
663 * The dynamic portion of the hook name, `$type`, refers to the type |
628 * |
667 * |
629 * @param string $upload_iframe_src The upload iframe source URL by type. |
668 * @param string $upload_iframe_src The upload iframe source URL by type. |
630 */ |
669 */ |
631 $upload_iframe_src = apply_filters( "{$type}_upload_iframe_src", $upload_iframe_src ); |
670 $upload_iframe_src = apply_filters( "{$type}_upload_iframe_src", $upload_iframe_src ); |
632 |
671 |
633 return add_query_arg('TB_iframe', true, $upload_iframe_src); |
672 return add_query_arg( 'TB_iframe', true, $upload_iframe_src ); |
634 } |
673 } |
635 |
674 |
636 /** |
675 /** |
637 * Handles form submissions for the legacy media uploader. |
676 * Handles form submissions for the legacy media uploader. |
638 * |
677 * |
639 * @since 2.5.0 |
678 * @since 2.5.0 |
640 * |
679 * |
641 * @return mixed void|object WP_Error on failure |
680 * @return mixed void|object WP_Error on failure |
642 */ |
681 */ |
643 function media_upload_form_handler() { |
682 function media_upload_form_handler() { |
644 check_admin_referer('media-form'); |
683 check_admin_referer( 'media-form' ); |
645 |
684 |
646 $errors = null; |
685 $errors = null; |
647 |
686 |
648 if ( isset($_POST['send']) ) { |
687 if ( isset( $_POST['send'] ) ) { |
649 $keys = array_keys( $_POST['send'] ); |
688 $keys = array_keys( $_POST['send'] ); |
650 $send_id = (int) reset( $keys ); |
689 $send_id = (int) reset( $keys ); |
651 } |
690 } |
652 |
691 |
653 if ( !empty($_POST['attachments']) ) foreach ( $_POST['attachments'] as $attachment_id => $attachment ) { |
692 if ( ! empty( $_POST['attachments'] ) ) { |
654 $post = $_post = get_post($attachment_id, ARRAY_A); |
693 foreach ( $_POST['attachments'] as $attachment_id => $attachment ) { |
655 |
694 $post = $_post = get_post( $attachment_id, ARRAY_A ); |
656 if ( !current_user_can( 'edit_post', $attachment_id ) ) |
695 |
657 continue; |
696 if ( ! current_user_can( 'edit_post', $attachment_id ) ) { |
658 |
697 continue; |
659 if ( isset($attachment['post_content']) ) |
698 } |
660 $post['post_content'] = $attachment['post_content']; |
699 |
661 if ( isset($attachment['post_title']) ) |
700 if ( isset( $attachment['post_content'] ) ) { |
662 $post['post_title'] = $attachment['post_title']; |
701 $post['post_content'] = $attachment['post_content']; |
663 if ( isset($attachment['post_excerpt']) ) |
702 } |
664 $post['post_excerpt'] = $attachment['post_excerpt']; |
703 if ( isset( $attachment['post_title'] ) ) { |
665 if ( isset($attachment['menu_order']) ) |
704 $post['post_title'] = $attachment['post_title']; |
666 $post['menu_order'] = $attachment['menu_order']; |
705 } |
667 |
706 if ( isset( $attachment['post_excerpt'] ) ) { |
668 if ( isset($send_id) && $attachment_id == $send_id ) { |
707 $post['post_excerpt'] = $attachment['post_excerpt']; |
669 if ( isset($attachment['post_parent']) ) |
708 } |
670 $post['post_parent'] = $attachment['post_parent']; |
709 if ( isset( $attachment['menu_order'] ) ) { |
671 } |
710 $post['menu_order'] = $attachment['menu_order']; |
672 |
711 } |
673 /** |
712 |
674 * Filters the attachment fields to be saved. |
713 if ( isset( $send_id ) && $attachment_id == $send_id ) { |
675 * |
714 if ( isset( $attachment['post_parent'] ) ) { |
676 * @since 2.5.0 |
715 $post['post_parent'] = $attachment['post_parent']; |
677 * |
716 } |
678 * @see wp_get_attachment_metadata() |
717 } |
679 * |
718 |
680 * @param array $post An array of post data. |
719 /** |
681 * @param array $attachment An array of attachment metadata. |
720 * Filters the attachment fields to be saved. |
682 */ |
721 * |
683 $post = apply_filters( 'attachment_fields_to_save', $post, $attachment ); |
722 * @since 2.5.0 |
684 |
723 * |
685 if ( isset($attachment['image_alt']) ) { |
724 * @see wp_get_attachment_metadata() |
686 $image_alt = wp_unslash( $attachment['image_alt'] ); |
725 * |
687 if ( $image_alt != get_post_meta($attachment_id, '_wp_attachment_image_alt', true) ) { |
726 * @param array $post An array of post data. |
688 $image_alt = wp_strip_all_tags( $image_alt, true ); |
727 * @param array $attachment An array of attachment metadata. |
689 |
728 */ |
690 // Update_meta expects slashed. |
729 $post = apply_filters( 'attachment_fields_to_save', $post, $attachment ); |
691 update_post_meta( $attachment_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) ); |
730 |
692 } |
731 if ( isset( $attachment['image_alt'] ) ) { |
693 } |
732 $image_alt = wp_unslash( $attachment['image_alt'] ); |
694 |
733 if ( $image_alt != get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) { |
695 if ( isset($post['errors']) ) { |
734 $image_alt = wp_strip_all_tags( $image_alt, true ); |
696 $errors[$attachment_id] = $post['errors']; |
735 |
697 unset($post['errors']); |
736 // Update_meta expects slashed. |
698 } |
737 update_post_meta( $attachment_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) ); |
699 |
738 } |
700 if ( $post != $_post ) |
739 } |
701 wp_update_post($post); |
740 |
702 |
741 if ( isset( $post['errors'] ) ) { |
703 foreach ( get_attachment_taxonomies($post) as $t ) { |
742 $errors[ $attachment_id ] = $post['errors']; |
704 if ( isset($attachment[$t]) ) |
743 unset( $post['errors'] ); |
705 wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false); |
744 } |
706 } |
745 |
707 } |
746 if ( $post != $_post ) { |
708 |
747 wp_update_post( $post ); |
709 if ( isset($_POST['insert-gallery']) || isset($_POST['update-gallery']) ) { ?> |
748 } |
|
749 |
|
750 foreach ( get_attachment_taxonomies( $post ) as $t ) { |
|
751 if ( isset( $attachment[ $t ] ) ) { |
|
752 wp_set_object_terms( $attachment_id, array_map( 'trim', preg_split( '/,+/', $attachment[ $t ] ) ), $t, false ); |
|
753 } |
|
754 } |
|
755 } |
|
756 } |
|
757 |
|
758 if ( isset( $_POST['insert-gallery'] ) || isset( $_POST['update-gallery'] ) ) { |
|
759 ?> |
710 <script type="text/javascript"> |
760 <script type="text/javascript"> |
711 var win = window.dialogArguments || opener || parent || top; |
761 var win = window.dialogArguments || opener || parent || top; |
712 win.tb_remove(); |
762 win.tb_remove(); |
713 </script> |
763 </script> |
714 <?php |
764 <?php |
715 exit; |
765 exit; |
716 } |
766 } |
717 |
767 |
718 if ( isset($send_id) ) { |
768 if ( isset( $send_id ) ) { |
719 $attachment = wp_unslash( $_POST['attachments'][$send_id] ); |
769 $attachment = wp_unslash( $_POST['attachments'][ $send_id ] ); |
720 |
770 |
721 $html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : ''; |
771 $html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : ''; |
722 if ( !empty($attachment['url']) ) { |
772 if ( ! empty( $attachment['url'] ) ) { |
723 $rel = ''; |
773 $rel = ''; |
724 if ( strpos($attachment['url'], 'attachment_id') || get_attachment_link($send_id) == $attachment['url'] ) |
774 if ( strpos( $attachment['url'], 'attachment_id' ) || get_attachment_link( $send_id ) == $attachment['url'] ) { |
725 $rel = " rel='attachment wp-att-" . esc_attr($send_id) . "'"; |
775 $rel = " rel='attachment wp-att-" . esc_attr( $send_id ) . "'"; |
|
776 } |
726 $html = "<a href='{$attachment['url']}'$rel>$html</a>"; |
777 $html = "<a href='{$attachment['url']}'$rel>$html</a>"; |
727 } |
778 } |
728 |
779 |
729 /** |
780 /** |
730 * Filters the HTML markup for a media item sent to the editor. |
781 * Filters the HTML markup for a media item sent to the editor. |
751 * |
802 * |
752 * @return null|string |
803 * @return null|string |
753 */ |
804 */ |
754 function wp_media_upload_handler() { |
805 function wp_media_upload_handler() { |
755 $errors = array(); |
806 $errors = array(); |
756 $id = 0; |
807 $id = 0; |
757 |
808 |
758 if ( isset($_POST['html-upload']) && !empty($_FILES) ) { |
809 if ( isset( $_POST['html-upload'] ) && ! empty( $_FILES ) ) { |
759 check_admin_referer('media-form'); |
810 check_admin_referer( 'media-form' ); |
760 // Upload File button was clicked |
811 // Upload File button was clicked |
761 $id = media_handle_upload('async-upload', $_REQUEST['post_id']); |
812 $id = media_handle_upload( 'async-upload', $_REQUEST['post_id'] ); |
762 unset($_FILES); |
813 unset( $_FILES ); |
763 if ( is_wp_error($id) ) { |
814 if ( is_wp_error( $id ) ) { |
764 $errors['upload_error'] = $id; |
815 $errors['upload_error'] = $id; |
765 $id = false; |
816 $id = false; |
766 } |
817 } |
767 } |
818 } |
768 |
819 |
769 if ( !empty($_POST['insertonlybutton']) ) { |
820 if ( ! empty( $_POST['insertonlybutton'] ) ) { |
770 $src = $_POST['src']; |
821 $src = $_POST['src']; |
771 if ( !empty($src) && !strpos($src, '://') ) |
822 if ( ! empty( $src ) && ! strpos( $src, '://' ) ) { |
772 $src = "http://$src"; |
823 $src = "http://$src"; |
|
824 } |
773 |
825 |
774 if ( isset( $_POST['media_type'] ) && 'image' != $_POST['media_type'] ) { |
826 if ( isset( $_POST['media_type'] ) && 'image' != $_POST['media_type'] ) { |
775 $title = esc_html( wp_unslash( $_POST['title'] ) ); |
827 $title = esc_html( wp_unslash( $_POST['title'] ) ); |
776 if ( empty( $title ) ) |
828 if ( empty( $title ) ) { |
777 $title = esc_html( basename( $src ) ); |
829 $title = esc_html( wp_basename( $src ) ); |
778 |
830 } |
779 if ( $title && $src ) |
831 |
780 $html = "<a href='" . esc_url($src) . "'>$title</a>"; |
832 if ( $title && $src ) { |
|
833 $html = "<a href='" . esc_url( $src ) . "'>$title</a>"; |
|
834 } |
781 |
835 |
782 $type = 'file'; |
836 $type = 'file'; |
783 if ( ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) ) && ( $ext_type = wp_ext2type( $ext ) ) |
837 if ( ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) ) && ( $ext_type = wp_ext2type( $ext ) ) |
784 && ( 'audio' == $ext_type || 'video' == $ext_type ) ) |
838 && ( 'audio' == $ext_type || 'video' == $ext_type ) ) { |
785 $type = $ext_type; |
839 $type = $ext_type; |
|
840 } |
786 |
841 |
787 /** |
842 /** |
788 * Filters the URL sent to the editor for a specific media type. |
843 * Filters the URL sent to the editor for a specific media type. |
789 * |
844 * |
790 * The dynamic portion of the hook name, `$type`, refers to the type |
845 * The dynamic portion of the hook name, `$type`, refers to the type |
819 * 'alignleft', 'aligncenter', 'alignright', 'alignnone'. |
875 * 'alignleft', 'aligncenter', 'alignright', 'alignnone'. |
820 */ |
876 */ |
821 $html = apply_filters( 'image_send_to_editor_url', $html, esc_url_raw( $src ), $alt, $align ); |
877 $html = apply_filters( 'image_send_to_editor_url', $html, esc_url_raw( $src ), $alt, $align ); |
822 } |
878 } |
823 |
879 |
824 return media_send_to_editor($html); |
880 return media_send_to_editor( $html ); |
825 } |
881 } |
826 |
882 |
827 if ( isset( $_POST['save'] ) ) { |
883 if ( isset( $_POST['save'] ) ) { |
828 $errors['upload_notice'] = __('Saved.'); |
884 $errors['upload_notice'] = __( 'Saved.' ); |
829 wp_enqueue_script( 'admin-gallery' ); |
885 wp_enqueue_script( 'admin-gallery' ); |
830 return wp_iframe( 'media_upload_gallery_form', $errors ); |
886 return wp_iframe( 'media_upload_gallery_form', $errors ); |
831 |
887 |
832 } elseif ( ! empty( $_POST ) ) { |
888 } elseif ( ! empty( $_POST ) ) { |
833 $return = media_upload_form_handler(); |
889 $return = media_upload_form_handler(); |
834 |
890 |
835 if ( is_string($return) ) |
891 if ( is_string( $return ) ) { |
836 return $return; |
892 return $return; |
837 if ( is_array($return) ) |
893 } |
|
894 if ( is_array( $return ) ) { |
838 $errors = $return; |
895 $errors = $return; |
839 } |
896 } |
840 |
897 } |
841 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) { |
898 |
|
899 if ( isset( $_GET['tab'] ) && $_GET['tab'] == 'type_url' ) { |
842 $type = 'image'; |
900 $type = 'image'; |
843 if ( isset( $_GET['type'] ) && in_array( $_GET['type'], array( 'video', 'audio', 'file' ) ) ) |
901 if ( isset( $_GET['type'] ) && in_array( $_GET['type'], array( 'video', 'audio', 'file' ) ) ) { |
844 $type = $_GET['type']; |
902 $type = $_GET['type']; |
|
903 } |
845 return wp_iframe( 'media_upload_type_url_form', $type, $errors, $id ); |
904 return wp_iframe( 'media_upload_type_url_form', $type, $errors, $id ); |
846 } |
905 } |
847 |
906 |
848 return wp_iframe( 'media_upload_type_form', 'image', $errors, $id ); |
907 return wp_iframe( 'media_upload_type_form', 'image', $errors, $id ); |
849 } |
908 } |
998 * @since 3.3.0 |
1068 * @since 3.3.0 |
999 * |
1069 * |
1000 * @param array $size_names Array of image sizes and their names. Default values |
1070 * @param array $size_names Array of image sizes and their names. Default values |
1001 * include 'Thumbnail', 'Medium', 'Large', 'Full Size'. |
1071 * include 'Thumbnail', 'Medium', 'Large', 'Full Size'. |
1002 */ |
1072 */ |
1003 $size_names = apply_filters( 'image_size_names_choose', array( |
1073 $size_names = apply_filters( |
1004 'thumbnail' => __( 'Thumbnail' ), |
1074 'image_size_names_choose', |
1005 'medium' => __( 'Medium' ), |
1075 array( |
1006 'large' => __( 'Large' ), |
1076 'thumbnail' => __( 'Thumbnail' ), |
1007 'full' => __( 'Full Size' ) |
1077 'medium' => __( 'Medium' ), |
1008 ) ); |
1078 'large' => __( 'Large' ), |
|
1079 'full' => __( 'Full Size' ), |
|
1080 ) |
|
1081 ); |
1009 |
1082 |
1010 if ( empty( $check ) ) { |
1083 if ( empty( $check ) ) { |
1011 $check = get_user_setting('imgsize', 'medium'); |
1084 $check = get_user_setting( 'imgsize', 'medium' ); |
1012 } |
1085 } |
1013 $out = array(); |
1086 $out = array(); |
1014 |
1087 |
1015 foreach ( $size_names as $size => $label ) { |
1088 foreach ( $size_names as $size => $label ) { |
1016 $downsize = image_downsize( $post->ID, $size ); |
1089 $downsize = image_downsize( $post->ID, $size ); |
1017 $checked = ''; |
1090 $checked = ''; |
1018 |
1091 |
1019 // Is this size selectable? |
1092 // Is this size selectable? |
1020 $enabled = ( $downsize[3] || 'full' == $size ); |
1093 $enabled = ( $downsize[3] || 'full' == $size ); |
1021 $css_id = "image-size-{$size}-{$post->ID}"; |
1094 $css_id = "image-size-{$size}-{$post->ID}"; |
1022 |
1095 |
1023 // If this size is the default but that's not available, don't select it. |
1096 // If this size is the default but that's not available, don't select it. |
1024 if ( $size == $check ) { |
1097 if ( $size == $check ) { |
1025 if ( $enabled ) { |
1098 if ( $enabled ) { |
1026 $checked = " checked='checked'"; |
1099 $checked = " checked='checked'"; |
1063 * |
1136 * |
1064 * @param WP_Post $post |
1137 * @param WP_Post $post |
1065 * @param string $url_type |
1138 * @param string $url_type |
1066 * @return string |
1139 * @return string |
1067 */ |
1140 */ |
1068 function image_link_input_fields($post, $url_type = '') { |
1141 function image_link_input_fields( $post, $url_type = '' ) { |
1069 |
1142 |
1070 $file = wp_get_attachment_url($post->ID); |
1143 $file = wp_get_attachment_url( $post->ID ); |
1071 $link = get_attachment_link($post->ID); |
1144 $link = get_attachment_link( $post->ID ); |
1072 |
1145 |
1073 if ( empty($url_type) ) |
1146 if ( empty( $url_type ) ) { |
1074 $url_type = get_user_setting('urlbutton', 'post'); |
1147 $url_type = get_user_setting( 'urlbutton', 'post' ); |
|
1148 } |
1075 |
1149 |
1076 $url = ''; |
1150 $url = ''; |
1077 if ( $url_type == 'file' ) |
1151 if ( $url_type == 'file' ) { |
1078 $url = $file; |
1152 $url = $file; |
1079 elseif ( $url_type == 'post' ) |
1153 } elseif ( $url_type == 'post' ) { |
1080 $url = $link; |
1154 $url = $link; |
|
1155 } |
1081 |
1156 |
1082 return " |
1157 return " |
1083 <input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr($url) . "' /><br /> |
1158 <input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr( $url ) . "' /><br /> |
1084 <button type='button' class='button urlnone' data-link-url=''>" . __('None') . "</button> |
1159 <button type='button' class='button urlnone' data-link-url=''>" . __( 'None' ) . "</button> |
1085 <button type='button' class='button urlfile' data-link-url='" . esc_attr($file) . "'>" . __('File URL') . "</button> |
1160 <button type='button' class='button urlfile' data-link-url='" . esc_attr( $file ) . "'>" . __( 'File URL' ) . "</button> |
1086 <button type='button' class='button urlpost' data-link-url='" . esc_attr($link) . "'>" . __('Attachment Post URL') . "</button> |
1161 <button type='button' class='button urlpost' data-link-url='" . esc_attr( $link ) . "'>" . __( 'Attachment Post URL' ) . '</button> |
1087 "; |
1162 '; |
1088 } |
1163 } |
1089 |
1164 |
1090 /** |
1165 /** |
1091 * Output a textarea element for inputting an attachment caption. |
1166 * Output a textarea element for inputting an attachment caption. |
1092 * |
1167 * |
1093 * @since 3.4.0 |
1168 * @since 3.4.0 |
1094 * |
1169 * |
1095 * @param WP_Post $edit_post Attachment WP_Post object. |
1170 * @param WP_Post $edit_post Attachment WP_Post object. |
1096 * @return string HTML markup for the textarea element. |
1171 * @return string HTML markup for the textarea element. |
1097 */ |
1172 */ |
1098 function wp_caption_input_textarea($edit_post) { |
1173 function wp_caption_input_textarea( $edit_post ) { |
1099 // Post data is already escaped. |
1174 // Post data is already escaped. |
1100 $name = "attachments[{$edit_post->ID}][post_excerpt]"; |
1175 $name = "attachments[{$edit_post->ID}][post_excerpt]"; |
1101 |
1176 |
1102 return '<textarea name="' . $name . '" id="' . $name . '">' . $edit_post->post_excerpt . '</textarea>'; |
1177 return '<textarea name="' . $name . '" id="' . $name . '">' . $edit_post->post_excerpt . '</textarea>'; |
1103 } |
1178 } |
1200 * |
1275 * |
1201 * @param WP_Post $post |
1276 * @param WP_Post $post |
1202 * @param array $errors |
1277 * @param array $errors |
1203 * @return array |
1278 * @return array |
1204 */ |
1279 */ |
1205 function get_attachment_fields_to_edit($post, $errors = null) { |
1280 function get_attachment_fields_to_edit( $post, $errors = null ) { |
1206 if ( is_int($post) ) |
1281 if ( is_int( $post ) ) { |
1207 $post = get_post($post); |
1282 $post = get_post( $post ); |
1208 if ( is_array($post) ) |
1283 } |
|
1284 if ( is_array( $post ) ) { |
1209 $post = new WP_Post( (object) $post ); |
1285 $post = new WP_Post( (object) $post ); |
1210 |
1286 } |
1211 $image_url = wp_get_attachment_url($post->ID); |
1287 |
1212 |
1288 $image_url = wp_get_attachment_url( $post->ID ); |
1213 $edit_post = sanitize_post($post, 'edit'); |
1289 |
|
1290 $edit_post = sanitize_post( $post, 'edit' ); |
1214 |
1291 |
1215 $form_fields = array( |
1292 $form_fields = array( |
1216 'post_title' => array( |
1293 'post_title' => array( |
1217 'label' => __('Title'), |
1294 'label' => __( 'Title' ), |
1218 'value' => $edit_post->post_title |
1295 'value' => $edit_post->post_title, |
1219 ), |
1296 ), |
1220 'image_alt' => array(), |
1297 'image_alt' => array(), |
1221 'post_excerpt' => array( |
1298 'post_excerpt' => array( |
1222 'label' => __('Caption'), |
1299 'label' => __( 'Caption' ), |
1223 'input' => 'html', |
1300 'input' => 'html', |
1224 'html' => wp_caption_input_textarea($edit_post) |
1301 'html' => wp_caption_input_textarea( $edit_post ), |
1225 ), |
1302 ), |
1226 'post_content' => array( |
1303 'post_content' => array( |
1227 'label' => __('Description'), |
1304 'label' => __( 'Description' ), |
1228 'value' => $edit_post->post_content, |
1305 'value' => $edit_post->post_content, |
1229 'input' => 'textarea' |
1306 'input' => 'textarea', |
1230 ), |
1307 ), |
1231 'url' => array( |
1308 'url' => array( |
1232 'label' => __('Link URL'), |
1309 'label' => __( 'Link URL' ), |
1233 'input' => 'html', |
1310 'input' => 'html', |
1234 'html' => image_link_input_fields($post, get_option('image_default_link_type')), |
1311 'html' => image_link_input_fields( $post, get_option( 'image_default_link_type' ) ), |
1235 'helps' => __('Enter a link URL or click above for presets.') |
1312 'helps' => __( 'Enter a link URL or click above for presets.' ), |
1236 ), |
1313 ), |
1237 'menu_order' => array( |
1314 'menu_order' => array( |
1238 'label' => __('Order'), |
1315 'label' => __( 'Order' ), |
1239 'value' => $edit_post->menu_order |
1316 'value' => $edit_post->menu_order, |
1240 ), |
1317 ), |
1241 'image_url' => array( |
1318 'image_url' => array( |
1242 'label' => __('File URL'), |
1319 'label' => __( 'File URL' ), |
1243 'input' => 'html', |
1320 'input' => 'html', |
1244 'html' => "<input type='text' class='text urlfield' readonly='readonly' name='attachments[$post->ID][url]' value='" . esc_attr($image_url) . "' /><br />", |
1321 'html' => "<input type='text' class='text urlfield' readonly='readonly' name='attachments[$post->ID][url]' value='" . esc_attr( $image_url ) . "' /><br />", |
1245 'value' => wp_get_attachment_url($post->ID), |
1322 'value' => wp_get_attachment_url( $post->ID ), |
1246 'helps' => __('Location of the uploaded file.') |
1323 'helps' => __( 'Location of the uploaded file.' ), |
1247 ) |
1324 ), |
1248 ); |
1325 ); |
1249 |
1326 |
1250 foreach ( get_attachment_taxonomies($post) as $taxonomy ) { |
1327 foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) { |
1251 $t = (array) get_taxonomy($taxonomy); |
1328 $t = (array) get_taxonomy( $taxonomy ); |
1252 if ( ! $t['public'] || ! $t['show_ui'] ) |
1329 if ( ! $t['public'] || ! $t['show_ui'] ) { |
1253 continue; |
1330 continue; |
1254 if ( empty($t['label']) ) |
1331 } |
|
1332 if ( empty( $t['label'] ) ) { |
1255 $t['label'] = $taxonomy; |
1333 $t['label'] = $taxonomy; |
1256 if ( empty($t['args']) ) |
1334 } |
|
1335 if ( empty( $t['args'] ) ) { |
1257 $t['args'] = array(); |
1336 $t['args'] = array(); |
1258 |
1337 } |
1259 $terms = get_object_term_cache($post->ID, $taxonomy); |
1338 |
1260 if ( false === $terms ) |
1339 $terms = get_object_term_cache( $post->ID, $taxonomy ); |
1261 $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']); |
1340 if ( false === $terms ) { |
|
1341 $terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] ); |
|
1342 } |
1262 |
1343 |
1263 $values = array(); |
1344 $values = array(); |
1264 |
1345 |
1265 foreach ( $terms as $term ) |
1346 foreach ( $terms as $term ) { |
1266 $values[] = $term->slug; |
1347 $values[] = $term->slug; |
1267 $t['value'] = join(', ', $values); |
1348 } |
1268 |
1349 $t['value'] = join( ', ', $values ); |
1269 $form_fields[$taxonomy] = $t; |
1350 |
|
1351 $form_fields[ $taxonomy ] = $t; |
1270 } |
1352 } |
1271 |
1353 |
1272 // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default |
1354 // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default |
1273 // The recursive merge is easily traversed with array casting: foreach ( (array) $things as $thing ) |
1355 // The recursive merge is easily traversed with array casting: foreach ( (array) $things as $thing ) |
1274 $form_fields = array_merge_recursive($form_fields, (array) $errors); |
1356 $form_fields = array_merge_recursive( $form_fields, (array) $errors ); |
1275 |
1357 |
1276 // This was formerly in image_attachment_fields_to_edit(). |
1358 // This was formerly in image_attachment_fields_to_edit(). |
1277 if ( substr($post->post_mime_type, 0, 5) == 'image' ) { |
1359 if ( substr( $post->post_mime_type, 0, 5 ) == 'image' ) { |
1278 $alt = get_post_meta($post->ID, '_wp_attachment_image_alt', true); |
1360 $alt = get_post_meta( $post->ID, '_wp_attachment_image_alt', true ); |
1279 if ( empty($alt) ) |
1361 if ( empty( $alt ) ) { |
1280 $alt = ''; |
1362 $alt = ''; |
|
1363 } |
1281 |
1364 |
1282 $form_fields['post_title']['required'] = true; |
1365 $form_fields['post_title']['required'] = true; |
1283 |
1366 |
1284 $form_fields['image_alt'] = array( |
1367 $form_fields['image_alt'] = array( |
1285 'value' => $alt, |
1368 'value' => $alt, |
1286 'label' => __('Alternative Text'), |
1369 'label' => __( 'Alternative Text' ), |
1287 'helps' => __('Alt text for the image, e.g. “The Mona Lisa”') |
1370 'helps' => __( 'Alt text for the image, e.g. “The Mona Lisa”' ), |
1288 ); |
1371 ); |
1289 |
1372 |
1290 $form_fields['align'] = array( |
1373 $form_fields['align'] = array( |
1291 'label' => __('Alignment'), |
1374 'label' => __( 'Alignment' ), |
1292 'input' => 'html', |
1375 'input' => 'html', |
1293 'html' => image_align_input_fields($post, get_option('image_default_align')), |
1376 'html' => image_align_input_fields( $post, get_option( 'image_default_align' ) ), |
1294 ); |
1377 ); |
1295 |
1378 |
1296 $form_fields['image-size'] = image_size_input_fields( $post, get_option('image_default_size', 'medium') ); |
1379 $form_fields['image-size'] = image_size_input_fields( $post, get_option( 'image_default_size', 'medium' ) ); |
1297 |
1380 |
1298 } else { |
1381 } else { |
1299 unset( $form_fields['image_alt'] ); |
1382 unset( $form_fields['image_alt'] ); |
1300 } |
1383 } |
1301 |
1384 |
1395 $r = apply_filters( 'get_media_item_args', $args ); |
1491 $r = apply_filters( 'get_media_item_args', $args ); |
1396 |
1492 |
1397 $toggle_on = __( 'Show' ); |
1493 $toggle_on = __( 'Show' ); |
1398 $toggle_off = __( 'Hide' ); |
1494 $toggle_off = __( 'Hide' ); |
1399 |
1495 |
1400 $file = get_attached_file( $post->ID ); |
1496 $file = get_attached_file( $post->ID ); |
1401 $filename = esc_html( wp_basename( $file ) ); |
1497 $filename = esc_html( wp_basename( $file ) ); |
1402 $title = esc_attr( $post->post_title ); |
1498 $title = esc_attr( $post->post_title ); |
1403 |
1499 |
1404 $post_mime_types = get_post_mime_types(); |
1500 $post_mime_types = get_post_mime_types(); |
1405 $keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) ); |
1501 $keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) ); |
1406 $type = reset( $keys ); |
1502 $type = reset( $keys ); |
1407 $type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />"; |
1503 $type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />"; |
1408 |
1504 |
1409 $form_fields = get_attachment_fields_to_edit( $post, $r['errors'] ); |
1505 $form_fields = get_attachment_fields_to_edit( $post, $r['errors'] ); |
1410 |
1506 |
1411 if ( $r['toggle'] ) { |
1507 if ( $r['toggle'] ) { |
1412 $class = empty( $r['errors'] ) ? 'startclosed' : 'startopen'; |
1508 $class = empty( $r['errors'] ) ? 'startclosed' : 'startopen'; |
1413 $toggle_links = " |
1509 $toggle_links = " |
1414 <a class='toggle describe-toggle-on' href='#'>$toggle_on</a> |
1510 <a class='toggle describe-toggle-on' href='#'>$toggle_on</a> |
1415 <a class='toggle describe-toggle-off' href='#'>$toggle_off</a>"; |
1511 <a class='toggle describe-toggle-off' href='#'>$toggle_off</a>"; |
1416 } else { |
1512 } else { |
1417 $class = ''; |
1513 $class = ''; |
1418 $toggle_links = ''; |
1514 $toggle_links = ''; |
1419 } |
1515 } |
1420 |
1516 |
1421 $display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case |
1517 $display_title = ( ! empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case |
1422 $display_title = $r['show_title'] ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60, '…' ) . "</span></div>" : ''; |
1518 $display_title = $r['show_title'] ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60, '…' ) . '</span></div>' : ''; |
1423 |
1519 |
1424 $gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' == $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' == $redir_tab ) ); |
1520 $gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' == $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' == $redir_tab ) ); |
1425 $order = ''; |
1521 $order = ''; |
1426 |
1522 |
1427 foreach ( $form_fields as $key => $val ) { |
1523 foreach ( $form_fields as $key => $val ) { |
1428 if ( 'menu_order' == $key ) { |
1524 if ( 'menu_order' == $key ) { |
1429 if ( $gallery ) |
1525 if ( $gallery ) { |
1430 $order = "<div class='menu_order'> <input class='menu_order_input' type='text' id='attachments[$attachment_id][menu_order]' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ). "' /></div>"; |
1526 $order = "<div class='menu_order'> <input class='menu_order_input' type='text' id='attachments[$attachment_id][menu_order]' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' /></div>"; |
1431 else |
1527 } else { |
1432 $order = "<input type='hidden' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' />"; |
1528 $order = "<input type='hidden' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' />"; |
|
1529 } |
1433 |
1530 |
1434 unset( $form_fields['menu_order'] ); |
1531 unset( $form_fields['menu_order'] ); |
1435 break; |
1532 break; |
1436 } |
1533 } |
1437 } |
1534 } |
1438 |
1535 |
1439 $media_dims = ''; |
1536 $media_dims = ''; |
1440 $meta = wp_get_attachment_metadata( $post->ID ); |
1537 $meta = wp_get_attachment_metadata( $post->ID ); |
1441 if ( isset( $meta['width'], $meta['height'] ) ) |
1538 if ( isset( $meta['width'], $meta['height'] ) ) { |
1442 $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']} × {$meta['height']}</span> "; |
1539 $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']} × {$meta['height']}</span> "; |
|
1540 } |
1443 |
1541 |
1444 /** |
1542 /** |
1445 * Filters the media metadata. |
1543 * Filters the media metadata. |
1446 * |
1544 * |
1447 * @since 2.5.0 |
1545 * @since 2.5.0 |
1498 $r['send'] = get_submit_button( __( 'Insert into Post' ), '', "send[$attachment_id]", false ); |
1597 $r['send'] = get_submit_button( __( 'Insert into Post' ), '', "send[$attachment_id]", false ); |
1499 } |
1598 } |
1500 |
1599 |
1501 $delete = empty( $r['delete'] ) ? '' : $r['delete']; |
1600 $delete = empty( $r['delete'] ) ? '' : $r['delete']; |
1502 if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) { |
1601 if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) { |
1503 if ( !EMPTY_TRASH_DAYS ) { |
1602 if ( ! EMPTY_TRASH_DAYS ) { |
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>'; |
1603 $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>'; |
1505 } elseif ( !MEDIA_TRASH ) { |
1604 } elseif ( ! MEDIA_TRASH ) { |
1506 $delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete' ) . "</a> |
1605 $delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete' ) . "</a> |
1507 <div id='del_attachment_$attachment_id' class='del-attachment' style='display:none;'>" . |
1606 <div id='del_attachment_$attachment_id' class='del-attachment' style='display:none;'>" . |
1508 /* translators: %s: file name */ |
1607 /* translators: %s: file name */ |
1509 '<p>' . sprintf( __( 'You are about to delete %s.' ), '<strong>' . $filename . '</strong>' ) . "</p> |
1608 '<p>' . sprintf( __( 'You are about to delete %s.' ), '<strong>' . $filename . '</strong>' ) . "</p> |
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> |
1609 <a href='" . wp_nonce_url( "post.php?action=delete&post=$attachment_id", 'delete-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='button'>" . __( 'Continue' ) . "</a> |
1511 <a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __( 'Cancel' ) . "</a> |
1610 <a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __( 'Cancel' ) . '</a> |
1512 </div>"; |
1611 </div>'; |
1513 } else { |
1612 } else { |
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> |
1613 $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> |
1515 <a href='" . wp_nonce_url( "post.php?action=untrash&post=$attachment_id", 'untrash-post_' . $attachment_id ) . "' id='undo[$attachment_id]' class='undo hidden'>" . __( 'Undo' ) . "</a>"; |
1614 <a href='" . wp_nonce_url( "post.php?action=untrash&post=$attachment_id", 'untrash-post_' . $attachment_id ) . "' id='undo[$attachment_id]' class='undo hidden'>" . __( 'Undo' ) . '</a>'; |
1516 } |
1615 } |
1517 } else { |
1616 } else { |
1518 $delete = ''; |
1617 $delete = ''; |
1519 } |
1618 } |
1520 |
1619 |
1521 $thumbnail = ''; |
1620 $thumbnail = ''; |
1522 $calling_post_id = 0; |
1621 $calling_post_id = 0; |
1523 if ( isset( $_GET['post_id'] ) ) { |
1622 if ( isset( $_GET['post_id'] ) ) { |
1524 $calling_post_id = absint( $_GET['post_id'] ); |
1623 $calling_post_id = absint( $_GET['post_id'] ); |
1525 } elseif ( isset( $_POST ) && count( $_POST ) ) {// Like for async-upload where $_GET['post_id'] isn't set |
1624 } elseif ( isset( $_POST ) && count( $_POST ) ) {// Like for async-upload where $_GET['post_id'] isn't set |
1526 $calling_post_id = $post->post_parent; |
1625 $calling_post_id = $post->post_parent; |
1527 } |
1626 } |
1528 if ( 'image' == $type && $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) ) |
1627 if ( 'image' == $type && $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) ) |
1529 && post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id ) { |
1628 && post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id ) { |
1530 |
1629 |
1531 $calling_post = get_post( $calling_post_id ); |
1630 $calling_post = get_post( $calling_post_id ); |
1532 $calling_post_type_object = get_post_type_object( $calling_post->post_type ); |
1631 $calling_post_type_object = get_post_type_object( $calling_post->post_type ); |
1533 |
1632 |
1534 $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" ); |
1633 $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" ); |
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>"; |
1634 $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>'; |
1536 } |
1635 } |
1537 |
1636 |
1538 if ( ( $r['send'] || $thumbnail || $delete ) && !isset( $form_fields['buttons'] ) ) { |
1637 if ( ( $r['send'] || $thumbnail || $delete ) && ! isset( $form_fields['buttons'] ) ) { |
1539 $form_fields['buttons'] = array( 'tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>" . $r['send'] . " $thumbnail $delete</td></tr>\n" ); |
1638 $form_fields['buttons'] = array( 'tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>" . $r['send'] . " $thumbnail $delete</td></tr>\n" ); |
1540 } |
1639 } |
1541 $hidden_fields = array(); |
1640 $hidden_fields = array(); |
1542 |
1641 |
1543 foreach ( $form_fields as $id => $field ) { |
1642 foreach ( $form_fields as $id => $field ) { |
1544 if ( $id[0] == '_' ) |
1643 if ( $id[0] == '_' ) { |
1545 continue; |
1644 continue; |
1546 |
1645 } |
1547 if ( !empty( $field['tr'] ) ) { |
1646 |
|
1647 if ( ! empty( $field['tr'] ) ) { |
1548 $item .= $field['tr']; |
1648 $item .= $field['tr']; |
1549 continue; |
1649 continue; |
1550 } |
1650 } |
1551 |
1651 |
1552 $field = array_merge( $defaults, $field ); |
1652 $field = array_merge( $defaults, $field ); |
1553 $name = "attachments[$attachment_id][$id]"; |
1653 $name = "attachments[$attachment_id][$id]"; |
1554 |
1654 |
1555 if ( $field['input'] == 'hidden' ) { |
1655 if ( $field['input'] == 'hidden' ) { |
1556 $hidden_fields[$name] = $field['value']; |
1656 $hidden_fields[ $name ] = $field['value']; |
1557 continue; |
1657 continue; |
1558 } |
1658 } |
1559 |
1659 |
1560 $required = $field['required'] ? '<span class="required">*</span>' : ''; |
1660 $required = $field['required'] ? '<span class="required">*</span>' : ''; |
1561 $required_attr = $field['required'] ? ' required' : ''; |
1661 $required_attr = $field['required'] ? ' required' : ''; |
1562 $aria_required = $field['required'] ? " aria-required='true'" : ''; |
1662 $class = $id; |
1563 $class = $id; |
1663 $class .= $field['required'] ? ' form-required' : ''; |
1564 $class .= $field['required'] ? ' form-required' : ''; |
|
1565 |
1664 |
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'>"; |
1665 $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'>"; |
1567 if ( !empty( $field[ $field['input'] ] ) ) |
1666 if ( ! empty( $field[ $field['input'] ] ) ) { |
1568 $item .= $field[ $field['input'] ]; |
1667 $item .= $field[ $field['input'] ]; |
1569 elseif ( $field['input'] == 'textarea' ) { |
1668 } elseif ( $field['input'] == 'textarea' ) { |
1570 if ( 'post_content' == $id && user_can_richedit() ) { |
1669 if ( 'post_content' == $id && user_can_richedit() ) { |
1571 // Sanitize_post() skips the post_content when user_can_richedit. |
1670 // Sanitize_post() skips the post_content when user_can_richedit. |
1572 $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES ); |
1671 $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES ); |
1573 } |
1672 } |
1574 // Post_excerpt is already escaped by sanitize_post() in get_attachment_fields_to_edit(). |
1673 // Post_excerpt is already escaped by sanitize_post() in get_attachment_fields_to_edit(). |
1575 $item .= "<textarea id='$name' name='$name'{$required_attr}{$aria_required}>" . $field['value'] . '</textarea>'; |
1674 $item .= "<textarea id='$name' name='$name'{$required_attr}>" . $field['value'] . '</textarea>'; |
1576 } else { |
1675 } else { |
1577 $item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "'{$required_attr}{$aria_required} />"; |
1676 $item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "'{$required_attr} />"; |
1578 } |
1677 } |
1579 if ( !empty( $field['helps'] ) ) |
1678 if ( ! empty( $field['helps'] ) ) { |
1580 $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>'; |
1679 $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>'; |
|
1680 } |
1581 $item .= "</td>\n\t\t</tr>\n"; |
1681 $item .= "</td>\n\t\t</tr>\n"; |
1582 |
1682 |
1583 $extra_rows = array(); |
1683 $extra_rows = array(); |
1584 |
1684 |
1585 if ( !empty( $field['errors'] ) ) |
1685 if ( ! empty( $field['errors'] ) ) { |
1586 foreach ( array_unique( (array) $field['errors'] ) as $error ) |
1686 foreach ( array_unique( (array) $field['errors'] ) as $error ) { |
1587 $extra_rows['error'][] = $error; |
1687 $extra_rows['error'][] = $error; |
1588 |
1688 } |
1589 if ( !empty( $field['extra_rows'] ) ) |
1689 } |
1590 foreach ( $field['extra_rows'] as $class => $rows ) |
1690 |
1591 foreach ( (array) $rows as $html ) |
1691 if ( ! empty( $field['extra_rows'] ) ) { |
1592 $extra_rows[$class][] = $html; |
1692 foreach ( $field['extra_rows'] as $class => $rows ) { |
1593 |
1693 foreach ( (array) $rows as $html ) { |
1594 foreach ( $extra_rows as $class => $rows ) |
1694 $extra_rows[ $class ][] = $html; |
1595 foreach ( $rows as $html ) |
1695 } |
|
1696 } |
|
1697 } |
|
1698 |
|
1699 foreach ( $extra_rows as $class => $rows ) { |
|
1700 foreach ( $rows as $html ) { |
1596 $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n"; |
1701 $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n"; |
1597 } |
1702 } |
1598 |
1703 } |
1599 if ( !empty( $form_fields['_final'] ) ) |
1704 } |
|
1705 |
|
1706 if ( ! empty( $form_fields['_final'] ) ) { |
1600 $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n"; |
1707 $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n"; |
|
1708 } |
1601 $item .= "\t</tbody>\n"; |
1709 $item .= "\t</tbody>\n"; |
1602 $item .= "\t</table>\n"; |
1710 $item .= "\t</table>\n"; |
1603 |
1711 |
1604 foreach ( $hidden_fields as $name => $value ) |
1712 foreach ( $hidden_fields as $name => $value ) { |
1605 $item .= "\t<input type='hidden' name='$name' id='$name' value='" . esc_attr( $value ) . "' />\n"; |
1713 $item .= "\t<input type='hidden' name='$name' id='$name' value='" . esc_attr( $value ) . "' />\n"; |
|
1714 } |
1606 |
1715 |
1607 if ( $post->post_parent < 1 && isset( $_REQUEST['post_id'] ) ) { |
1716 if ( $post->post_parent < 1 && isset( $_REQUEST['post_id'] ) ) { |
1608 $parent = (int) $_REQUEST['post_id']; |
1717 $parent = (int) $_REQUEST['post_id']; |
1609 $parent_name = "attachments[$attachment_id][post_parent]"; |
1718 $parent_name = "attachments[$attachment_id][post_parent]"; |
1610 $item .= "\t<input type='hidden' name='$parent_name' id='$parent_name' value='$parent' />\n"; |
1719 $item .= "\t<input type='hidden' name='$parent_name' id='$parent_name' value='$parent' />\n"; |
1611 } |
1720 } |
1612 |
1721 |
1613 return $item; |
1722 return $item; |
1614 } |
1723 } |
1615 |
1724 |
1636 $args = apply_filters( 'get_media_item_args', $args ); |
1745 $args = apply_filters( 'get_media_item_args', $args ); |
1637 |
1746 |
1638 $form_fields = array(); |
1747 $form_fields = array(); |
1639 |
1748 |
1640 if ( $args['in_modal'] ) { |
1749 if ( $args['in_modal'] ) { |
1641 foreach ( get_attachment_taxonomies($post) as $taxonomy ) { |
1750 foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) { |
1642 $t = (array) get_taxonomy($taxonomy); |
1751 $t = (array) get_taxonomy( $taxonomy ); |
1643 if ( ! $t['public'] || ! $t['show_ui'] ) |
1752 if ( ! $t['public'] || ! $t['show_ui'] ) { |
1644 continue; |
1753 continue; |
1645 if ( empty($t['label']) ) |
1754 } |
|
1755 if ( empty( $t['label'] ) ) { |
1646 $t['label'] = $taxonomy; |
1756 $t['label'] = $taxonomy; |
1647 if ( empty($t['args']) ) |
1757 } |
|
1758 if ( empty( $t['args'] ) ) { |
1648 $t['args'] = array(); |
1759 $t['args'] = array(); |
1649 |
1760 } |
1650 $terms = get_object_term_cache($post->ID, $taxonomy); |
1761 |
1651 if ( false === $terms ) |
1762 $terms = get_object_term_cache( $post->ID, $taxonomy ); |
1652 $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']); |
1763 if ( false === $terms ) { |
|
1764 $terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] ); |
|
1765 } |
1653 |
1766 |
1654 $values = array(); |
1767 $values = array(); |
1655 |
1768 |
1656 foreach ( $terms as $term ) |
1769 foreach ( $terms as $term ) { |
1657 $values[] = $term->slug; |
1770 $values[] = $term->slug; |
1658 $t['value'] = join(', ', $values); |
1771 } |
|
1772 $t['value'] = join( ', ', $values ); |
1659 $t['taxonomy'] = true; |
1773 $t['taxonomy'] = true; |
1660 |
1774 |
1661 $form_fields[$taxonomy] = $t; |
1775 $form_fields[ $taxonomy ] = $t; |
1662 } |
1776 } |
1663 } |
1777 } |
1664 |
1778 |
1665 // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default |
1779 // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default |
1666 // The recursive merge is easily traversed with array casting: foreach ( (array) $things as $thing ) |
1780 // The recursive merge is easily traversed with array casting: foreach ( (array) $things as $thing ) |
1667 $form_fields = array_merge_recursive($form_fields, (array) $args['errors'] ); |
1781 $form_fields = array_merge_recursive( $form_fields, (array) $args['errors'] ); |
1668 |
1782 |
1669 /** This filter is documented in wp-admin/includes/media.php */ |
1783 /** This filter is documented in wp-admin/includes/media.php */ |
1670 $form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post ); |
1784 $form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post ); |
1671 |
1785 |
1672 unset( $form_fields['image-size'], $form_fields['align'], $form_fields['image_alt'], |
1786 unset( |
1673 $form_fields['post_title'], $form_fields['post_excerpt'], $form_fields['post_content'], |
1787 $form_fields['image-size'], |
1674 $form_fields['url'], $form_fields['menu_order'], $form_fields['image_url'] ); |
1788 $form_fields['align'], |
|
1789 $form_fields['image_alt'], |
|
1790 $form_fields['post_title'], |
|
1791 $form_fields['post_excerpt'], |
|
1792 $form_fields['post_content'], |
|
1793 $form_fields['url'], |
|
1794 $form_fields['menu_order'], |
|
1795 $form_fields['image_url'] |
|
1796 ); |
1675 |
1797 |
1676 /** This filter is documented in wp-admin/includes/media.php */ |
1798 /** This filter is documented in wp-admin/includes/media.php */ |
1677 $media_meta = apply_filters( 'media_meta', '', $post ); |
1799 $media_meta = apply_filters( 'media_meta', '', $post ); |
1678 |
1800 |
1679 $defaults = array( |
1801 $defaults = array( |
1687 |
1809 |
1688 $hidden_fields = array(); |
1810 $hidden_fields = array(); |
1689 |
1811 |
1690 $item = ''; |
1812 $item = ''; |
1691 foreach ( $form_fields as $id => $field ) { |
1813 foreach ( $form_fields as $id => $field ) { |
1692 if ( $id[0] == '_' ) |
1814 if ( $id[0] == '_' ) { |
1693 continue; |
1815 continue; |
1694 |
1816 } |
1695 $name = "attachments[$attachment_id][$id]"; |
1817 |
|
1818 $name = "attachments[$attachment_id][$id]"; |
1696 $id_attr = "attachments-$attachment_id-$id"; |
1819 $id_attr = "attachments-$attachment_id-$id"; |
1697 |
1820 |
1698 if ( !empty( $field['tr'] ) ) { |
1821 if ( ! empty( $field['tr'] ) ) { |
1699 $item .= $field['tr']; |
1822 $item .= $field['tr']; |
1700 continue; |
1823 continue; |
1701 } |
1824 } |
1702 |
1825 |
1703 $field = array_merge( $defaults, $field ); |
1826 $field = array_merge( $defaults, $field ); |
1704 |
1827 |
1705 if ( ( ! $field['show_in_edit'] && ! $args['in_modal'] ) || ( ! $field['show_in_modal'] && $args['in_modal'] ) ) |
1828 if ( ( ! $field['show_in_edit'] && ! $args['in_modal'] ) || ( ! $field['show_in_modal'] && $args['in_modal'] ) ) { |
1706 continue; |
1829 continue; |
|
1830 } |
1707 |
1831 |
1708 if ( $field['input'] == 'hidden' ) { |
1832 if ( $field['input'] == 'hidden' ) { |
1709 $hidden_fields[$name] = $field['value']; |
1833 $hidden_fields[ $name ] = $field['value']; |
1710 continue; |
1834 continue; |
1711 } |
1835 } |
1712 |
1836 |
1713 $readonly = ! $user_can_edit && ! empty( $field['taxonomy'] ) ? " readonly='readonly' " : ''; |
1837 $readonly = ! $user_can_edit && ! empty( $field['taxonomy'] ) ? " readonly='readonly' " : ''; |
1714 $required = $field['required'] ? '<span class="required">*</span>' : ''; |
1838 $required = $field['required'] ? '<span class="required">*</span>' : ''; |
1715 $required_attr = $field['required'] ? ' required' : ''; |
1839 $required_attr = $field['required'] ? ' required' : ''; |
1716 $aria_required = $field['required'] ? " aria-required='true'" : ''; |
1840 $class = 'compat-field-' . $id; |
1717 $class = 'compat-field-' . $id; |
1841 $class .= $field['required'] ? ' form-required' : ''; |
1718 $class .= $field['required'] ? ' form-required' : ''; |
|
1719 |
1842 |
1720 $item .= "\t\t<tr class='$class'>"; |
1843 $item .= "\t\t<tr class='$class'>"; |
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>"; |
1844 $item .= "\t\t\t<th scope='row' class='label'><label for='$id_attr'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label>"; |
1722 $item .= "</th>\n\t\t\t<td class='field'>"; |
1845 $item .= "</th>\n\t\t\t<td class='field'>"; |
1723 |
1846 |
1724 if ( !empty( $field[ $field['input'] ] ) ) |
1847 if ( ! empty( $field[ $field['input'] ] ) ) { |
1725 $item .= $field[ $field['input'] ]; |
1848 $item .= $field[ $field['input'] ]; |
1726 elseif ( $field['input'] == 'textarea' ) { |
1849 } elseif ( $field['input'] == 'textarea' ) { |
1727 if ( 'post_content' == $id && user_can_richedit() ) { |
1850 if ( 'post_content' == $id && user_can_richedit() ) { |
1728 // sanitize_post() skips the post_content when user_can_richedit. |
1851 // sanitize_post() skips the post_content when user_can_richedit. |
1729 $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES ); |
1852 $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES ); |
1730 } |
1853 } |
1731 $item .= "<textarea id='$id_attr' name='$name'{$required_attr}{$aria_required}>" . $field['value'] . '</textarea>'; |
1854 $item .= "<textarea id='$id_attr' name='$name'{$required_attr}>" . $field['value'] . '</textarea>'; |
1732 } else { |
1855 } else { |
1733 $item .= "<input type='text' class='text' id='$id_attr' name='$name' value='" . esc_attr( $field['value'] ) . "' $readonly{$required_attr}{$aria_required} />"; |
1856 $item .= "<input type='text' class='text' id='$id_attr' name='$name' value='" . esc_attr( $field['value'] ) . "' $readonly{$required_attr} />"; |
1734 } |
1857 } |
1735 if ( !empty( $field['helps'] ) ) |
1858 if ( ! empty( $field['helps'] ) ) { |
1736 $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>'; |
1859 $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>'; |
|
1860 } |
1737 $item .= "</td>\n\t\t</tr>\n"; |
1861 $item .= "</td>\n\t\t</tr>\n"; |
1738 |
1862 |
1739 $extra_rows = array(); |
1863 $extra_rows = array(); |
1740 |
1864 |
1741 if ( !empty( $field['errors'] ) ) |
1865 if ( ! empty( $field['errors'] ) ) { |
1742 foreach ( array_unique( (array) $field['errors'] ) as $error ) |
1866 foreach ( array_unique( (array) $field['errors'] ) as $error ) { |
1743 $extra_rows['error'][] = $error; |
1867 $extra_rows['error'][] = $error; |
1744 |
1868 } |
1745 if ( !empty( $field['extra_rows'] ) ) |
1869 } |
1746 foreach ( $field['extra_rows'] as $class => $rows ) |
1870 |
1747 foreach ( (array) $rows as $html ) |
1871 if ( ! empty( $field['extra_rows'] ) ) { |
1748 $extra_rows[$class][] = $html; |
1872 foreach ( $field['extra_rows'] as $class => $rows ) { |
1749 |
1873 foreach ( (array) $rows as $html ) { |
1750 foreach ( $extra_rows as $class => $rows ) |
1874 $extra_rows[ $class ][] = $html; |
1751 foreach ( $rows as $html ) |
1875 } |
|
1876 } |
|
1877 } |
|
1878 |
|
1879 foreach ( $extra_rows as $class => $rows ) { |
|
1880 foreach ( $rows as $html ) { |
1752 $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n"; |
1881 $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n"; |
1753 } |
1882 } |
1754 |
1883 } |
1755 if ( !empty( $form_fields['_final'] ) ) |
1884 } |
|
1885 |
|
1886 if ( ! empty( $form_fields['_final'] ) ) { |
1756 $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n"; |
1887 $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n"; |
|
1888 } |
1757 |
1889 |
1758 if ( $item ) { |
1890 if ( $item ) { |
1759 $item = '<p class="media-types media-types-required-info">' . |
1891 $item = '<p class="media-types media-types-required-info">' . |
1760 sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) . '</p> |
1892 sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) . '</p> |
1761 <table class="compat-attachment-fields">' . $item . '</table>'; |
1893 <table class="compat-attachment-fields">' . $item . '</table>'; |
1804 */ |
1937 */ |
1805 function media_upload_form( $errors = null ) { |
1938 function media_upload_form( $errors = null ) { |
1806 global $type, $tab, $is_IE, $is_opera; |
1939 global $type, $tab, $is_IE, $is_opera; |
1807 |
1940 |
1808 if ( ! _device_can_upload() ) { |
1941 if ( ! _device_can_upload() ) { |
1809 echo '<p>' . sprintf( __('The web browser on your device cannot be used to upload files. You may be able to use the <a href="%s">native app for your device</a> instead.'), 'https://apps.wordpress.org/' ) . '</p>'; |
1942 echo '<p>' . sprintf( __( 'The web browser on your device cannot be used to upload files. You may be able to use the <a href="%s">native app for your device</a> instead.' ), 'https://apps.wordpress.org/' ) . '</p>'; |
1810 return; |
1943 return; |
1811 } |
1944 } |
1812 |
1945 |
1813 $upload_action_url = admin_url('async-upload.php'); |
1946 $upload_action_url = admin_url( 'async-upload.php' ); |
1814 $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0; |
1947 $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0; |
1815 $_type = isset($type) ? $type : ''; |
1948 $_type = isset( $type ) ? $type : ''; |
1816 $_tab = isset($tab) ? $tab : ''; |
1949 $_tab = isset( $tab ) ? $tab : ''; |
1817 |
1950 |
1818 $max_upload_size = wp_max_upload_size(); |
1951 $max_upload_size = wp_max_upload_size(); |
1819 if ( ! $max_upload_size ) { |
1952 if ( ! $max_upload_size ) { |
1820 $max_upload_size = 0; |
1953 $max_upload_size = 0; |
1821 } |
1954 } |
1822 ?> |
1955 ?> |
1823 |
1956 |
1824 <div id="media-upload-notice"><?php |
1957 <div id="media-upload-notice"> |
1825 |
1958 <?php |
1826 if (isset($errors['upload_notice']) ) |
1959 |
|
1960 if ( isset( $errors['upload_notice'] ) ) { |
1827 echo $errors['upload_notice']; |
1961 echo $errors['upload_notice']; |
1828 |
1962 } |
1829 ?></div> |
1963 |
1830 <div id="media-upload-error"><?php |
1964 ?> |
1831 |
1965 </div> |
1832 if (isset($errors['upload_error']) && is_wp_error($errors['upload_error'])) |
1966 <div id="media-upload-error"> |
|
1967 <?php |
|
1968 |
|
1969 if ( isset( $errors['upload_error'] ) && is_wp_error( $errors['upload_error'] ) ) { |
1833 echo $errors['upload_error']->get_error_message(); |
1970 echo $errors['upload_error']->get_error_message(); |
1834 |
1971 } |
1835 ?></div> |
1972 |
1836 <?php |
1973 ?> |
1837 if ( is_multisite() && !is_upload_space_available() ) { |
1974 </div> |
|
1975 <?php |
|
1976 if ( is_multisite() && ! is_upload_space_available() ) { |
|
1977 /** |
|
1978 * Fires when an upload will exceed the defined upload space quota for a network site. |
|
1979 * |
|
1980 * @since 3.5.0 |
|
1981 */ |
|
1982 do_action( 'upload_ui_over_quota' ); |
|
1983 return; |
|
1984 } |
|
1985 |
1838 /** |
1986 /** |
1839 * Fires when an upload will exceed the defined upload space quota for a network site. |
1987 * Fires just before the legacy (pre-3.5.0) upload interface is loaded. |
1840 * |
1988 * |
1841 * @since 3.5.0 |
1989 * @since 2.6.0 |
1842 */ |
1990 */ |
1843 do_action( 'upload_ui_over_quota' ); |
1991 do_action( 'pre-upload-ui' ); |
1844 return; |
1992 |
1845 } |
1993 $post_params = array( |
1846 |
1994 'post_id' => $post_id, |
1847 /** |
1995 '_wpnonce' => wp_create_nonce( 'media-form' ), |
1848 * Fires just before the legacy (pre-3.5.0) upload interface is loaded. |
1996 'type' => $_type, |
1849 * |
1997 'tab' => $_tab, |
1850 * @since 2.6.0 |
1998 'short' => '1', |
1851 */ |
1999 ); |
1852 do_action( 'pre-upload-ui' ); |
2000 |
1853 |
2001 /** |
1854 $post_params = array( |
2002 * Filters the media upload post parameters. |
1855 "post_id" => $post_id, |
2003 * |
1856 "_wpnonce" => wp_create_nonce('media-form'), |
2004 * @since 3.1.0 As 'swfupload_post_params' |
1857 "type" => $_type, |
2005 * @since 3.3.0 |
1858 "tab" => $_tab, |
2006 * |
1859 "short" => "1", |
2007 * @param array $post_params An array of media upload parameters used by Plupload. |
1860 ); |
2008 */ |
1861 |
2009 $post_params = apply_filters( 'upload_post_params', $post_params ); |
1862 /** |
2010 |
1863 * Filters the media upload post parameters. |
2011 /* |
1864 * |
2012 * Since 4.9 the `runtimes` setting is hardcoded in our version of Plupload to `html5,html4`, |
1865 * @since 3.1.0 As 'swfupload_post_params' |
2013 * and the `flash_swf_url` and `silverlight_xap_url` are not used. |
1866 * @since 3.3.0 |
2014 */ |
1867 * |
2015 $plupload_init = array( |
1868 * @param array $post_params An array of media upload parameters used by Plupload. |
2016 'browse_button' => 'plupload-browse-button', |
1869 */ |
2017 'container' => 'plupload-upload-ui', |
1870 $post_params = apply_filters( 'upload_post_params', $post_params ); |
2018 'drop_element' => 'drag-drop-area', |
1871 |
2019 'file_data_name' => 'async-upload', |
1872 /* |
2020 'url' => $upload_action_url, |
1873 * Since 4.9 the `runtimes` setting is hardcoded in our version of Plupload to `html5,html4`, |
2021 'filters' => array( |
1874 * and the `flash_swf_url` and `silverlight_xap_url` are not used. |
2022 'max_file_size' => $max_upload_size . 'b', |
1875 */ |
2023 ), |
1876 $plupload_init = array( |
2024 'multipart_params' => $post_params, |
1877 'browse_button' => 'plupload-browse-button', |
2025 ); |
1878 'container' => 'plupload-upload-ui', |
2026 |
1879 'drop_element' => 'drag-drop-area', |
2027 // Currently only iOS Safari supports multiple files uploading but iOS 7.x has a bug that prevents uploading of videos |
1880 'file_data_name' => 'async-upload', |
2028 // when enabled. See #29602. |
1881 'url' => $upload_action_url, |
2029 if ( wp_is_mobile() && strpos( $_SERVER['HTTP_USER_AGENT'], 'OS 7_' ) !== false && |
1882 'filters' => array( |
|
1883 'max_file_size' => $max_upload_size . 'b', |
|
1884 ), |
|
1885 'multipart_params' => $post_params, |
|
1886 ); |
|
1887 |
|
1888 // Currently only iOS Safari supports multiple files uploading but iOS 7.x has a bug that prevents uploading of videos |
|
1889 // when enabled. See #29602. |
|
1890 if ( wp_is_mobile() && strpos( $_SERVER['HTTP_USER_AGENT'], 'OS 7_' ) !== false && |
|
1891 strpos( $_SERVER['HTTP_USER_AGENT'], 'like Mac OS X' ) !== false ) { |
2030 strpos( $_SERVER['HTTP_USER_AGENT'], 'like Mac OS X' ) !== false ) { |
1892 |
2031 |
1893 $plupload_init['multi_selection'] = false; |
2032 $plupload_init['multi_selection'] = false; |
1894 } |
2033 } |
1895 |
2034 |
1896 /** |
2035 /** |
1897 * Filters the default Plupload settings. |
2036 * Filters the default Plupload settings. |
1898 * |
2037 * |
1899 * @since 3.3.0 |
2038 * @since 3.3.0 |
1900 * |
2039 * |
1901 * @param array $plupload_init An array of default settings used by Plupload. |
2040 * @param array $plupload_init An array of default settings used by Plupload. |
1902 */ |
2041 */ |
1903 $plupload_init = apply_filters( 'plupload_init', $plupload_init ); |
2042 $plupload_init = apply_filters( 'plupload_init', $plupload_init ); |
1904 |
2043 |
1905 ?> |
2044 ?> |
1906 |
2045 |
1907 <script type="text/javascript"> |
2046 <script type="text/javascript"> |
1908 <?php |
2047 <?php |
1909 // Verify size is an int. If not return default value. |
2048 // Verify size is an int. If not return default value. |
1910 $large_size_h = absint( get_option('large_size_h') ); |
2049 $large_size_h = absint( get_option( 'large_size_h' ) ); |
1911 if( !$large_size_h ) |
2050 if ( ! $large_size_h ) { |
1912 $large_size_h = 1024; |
2051 $large_size_h = 1024; |
1913 $large_size_w = absint( get_option('large_size_w') ); |
2052 } |
1914 if( !$large_size_w ) |
2053 $large_size_w = absint( get_option( 'large_size_w' ) ); |
1915 $large_size_w = 1024; |
2054 if ( ! $large_size_w ) { |
1916 ?> |
2055 $large_size_w = 1024; |
|
2056 } |
|
2057 ?> |
1917 var resize_height = <?php echo $large_size_h; ?>, resize_width = <?php echo $large_size_w; ?>, |
2058 var resize_height = <?php echo $large_size_h; ?>, resize_width = <?php echo $large_size_w; ?>, |
1918 wpUploaderInit = <?php echo wp_json_encode( $plupload_init ); ?>; |
2059 wpUploaderInit = <?php echo wp_json_encode( $plupload_init ); ?>; |
1919 </script> |
2060 </script> |
1920 |
2061 |
1921 <div id="plupload-upload-ui" class="hide-if-no-js"> |
2062 <div id="plupload-upload-ui" class="hide-if-no-js"> |
1922 <?php |
2063 <?php |
1923 /** |
2064 /** |
1924 * Fires before the upload interface loads. |
2065 * Fires before the upload interface loads. |
1925 * |
2066 * |
1926 * @since 2.6.0 As 'pre-flash-upload-ui' |
2067 * @since 2.6.0 As 'pre-flash-upload-ui' |
1927 * @since 3.3.0 |
2068 * @since 3.3.0 |
1928 */ |
2069 */ |
1929 do_action( 'pre-plupload-upload-ui' ); ?> |
2070 do_action( 'pre-plupload-upload-ui' ); |
|
2071 ?> |
1930 <div id="drag-drop-area"> |
2072 <div id="drag-drop-area"> |
1931 <div class="drag-drop-inside"> |
2073 <div class="drag-drop-inside"> |
1932 <p class="drag-drop-info"><?php _e('Drop files here'); ?></p> |
2074 <p class="drag-drop-info"><?php _e( 'Drop files here' ); ?></p> |
1933 <p><?php _ex('or', 'Uploader: Drop files here - or - Select Files'); ?></p> |
2075 <p><?php _ex( 'or', 'Uploader: Drop files here - or - Select Files' ); ?></p> |
1934 <p class="drag-drop-buttons"><input id="plupload-browse-button" type="button" value="<?php esc_attr_e('Select Files'); ?>" class="button" /></p> |
2076 <p class="drag-drop-buttons"><input id="plupload-browse-button" type="button" value="<?php esc_attr_e( 'Select Files' ); ?>" class="button" /></p> |
1935 </div> |
2077 </div> |
1936 </div> |
2078 </div> |
1937 <?php |
2079 <?php |
1938 /** |
2080 /** |
1939 * Fires after the upload interface loads. |
2081 * Fires after the upload interface loads. |
1940 * |
2082 * |
1941 * @since 2.6.0 As 'post-flash-upload-ui' |
2083 * @since 2.6.0 As 'post-flash-upload-ui' |
1942 * @since 3.3.0 |
2084 * @since 3.3.0 |
1943 */ |
2085 */ |
1944 do_action( 'post-plupload-upload-ui' ); ?> |
2086 do_action( 'post-plupload-upload-ui' ); |
|
2087 ?> |
1945 </div> |
2088 </div> |
1946 |
2089 |
1947 <div id="html-upload-ui" class="hide-if-js"> |
2090 <div id="html-upload-ui" class="hide-if-js"> |
1948 <?php |
2091 <?php |
1949 /** |
2092 /** |
1990 * |
2133 * |
1991 * @param string $type |
2134 * @param string $type |
1992 * @param object $errors |
2135 * @param object $errors |
1993 * @param integer $id |
2136 * @param integer $id |
1994 */ |
2137 */ |
1995 function media_upload_type_form($type = 'file', $errors = null, $id = null) { |
2138 function media_upload_type_form( $type = 'file', $errors = null, $id = null ) { |
1996 |
2139 |
1997 media_upload_header(); |
2140 media_upload_header(); |
1998 |
2141 |
1999 $post_id = isset( $_REQUEST['post_id'] )? intval( $_REQUEST['post_id'] ) : 0; |
2142 $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0; |
2000 |
2143 |
2001 $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id"); |
2144 $form_action_url = admin_url( "media-upload.php?type=$type&tab=type&post_id=$post_id" ); |
2002 |
2145 |
2003 /** |
2146 /** |
2004 * Filters the media upload form action URL. |
2147 * Filters the media upload form action URL. |
2005 * |
2148 * |
2006 * @since 2.6.0 |
2149 * @since 2.6.0 |
2007 * |
2150 * |
2008 * @param string $form_action_url The media upload form action URL. |
2151 * @param string $form_action_url The media upload form action URL. |
2009 * @param string $type The type of media. Default 'file'. |
2152 * @param string $type The type of media. Default 'file'. |
2010 */ |
2153 */ |
2011 $form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type ); |
2154 $form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type ); |
2012 $form_class = 'media-upload-form type-form validate'; |
2155 $form_class = 'media-upload-form type-form validate'; |
2013 |
2156 |
2014 if ( get_user_setting('uploader') ) |
2157 if ( get_user_setting( 'uploader' ) ) { |
2015 $form_class .= ' html-uploader'; |
2158 $form_class .= ' html-uploader'; |
2016 ?> |
2159 } |
|
2160 ?> |
2017 |
2161 |
2018 <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form"> |
2162 <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form"> |
2019 <?php submit_button( '', 'hidden', 'save', false ); ?> |
2163 <?php submit_button( '', 'hidden', 'save', false ); ?> |
2020 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
2164 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
2021 <?php wp_nonce_field('media-form'); ?> |
2165 <?php wp_nonce_field( 'media-form' ); ?> |
2022 |
2166 |
2023 <h3 class="media-title"><?php _e('Add media files from your computer'); ?></h3> |
2167 <h3 class="media-title"><?php _e( 'Add media files from your computer' ); ?></h3> |
2024 |
2168 |
2025 <?php media_upload_form( $errors ); ?> |
2169 <?php media_upload_form( $errors ); ?> |
2026 |
2170 |
2027 <script type="text/javascript"> |
2171 <script type="text/javascript"> |
2028 jQuery(function($){ |
2172 jQuery(function($){ |
2029 var preloaded = $(".media-item.preloaded"); |
2173 var preloaded = $(".media-item.preloaded"); |
2030 if ( preloaded.length > 0 ) { |
2174 if ( preloaded.length > 0 ) { |
2031 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); |
2175 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); |
2032 } |
2176 } |
2033 updateMediaForm(); |
2177 updateMediaForm(); |
2034 }); |
2178 }); |
2035 </script> |
2179 </script> |
2036 <div id="media-items"><?php |
2180 <div id="media-items"> |
2037 |
2181 <?php |
2038 if ( $id ) { |
2182 |
2039 if ( !is_wp_error($id) ) { |
2183 if ( $id ) { |
2040 add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); |
2184 if ( ! is_wp_error( $id ) ) { |
2041 echo get_media_items( $id, $errors ); |
2185 add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 ); |
2042 } else { |
2186 echo get_media_items( $id, $errors ); |
2043 echo '<div id="media-upload-error">'.esc_html($id->get_error_message()).'</div></div>'; |
2187 } else { |
2044 exit; |
2188 echo '<div id="media-upload-error">' . esc_html( $id->get_error_message() ) . '</div></div>'; |
2045 } |
2189 exit; |
2046 } |
2190 } |
2047 ?></div> |
2191 } |
|
2192 ?> |
|
2193 </div> |
2048 |
2194 |
2049 <p class="savebutton ml-submit"> |
2195 <p class="savebutton ml-submit"> |
2050 <?php submit_button( __( 'Save all changes' ), '', 'save', false ); ?> |
2196 <?php submit_button( __( 'Save all changes' ), '', 'save', false ); ?> |
2051 </p> |
2197 </p> |
2052 </form> |
2198 </form> |
2053 <?php |
2199 <?php |
2054 } |
2200 } |
2055 |
2201 |
2056 /** |
2202 /** |
2057 * Outputs the legacy media upload form for external media. |
2203 * Outputs the legacy media upload form for external media. |
2058 * |
2204 * |
2231 } |
2380 } |
2232 }); |
2381 }); |
2233 </script> |
2382 </script> |
2234 <div id="sort-buttons" class="hide-if-no-js"> |
2383 <div id="sort-buttons" class="hide-if-no-js"> |
2235 <span> |
2384 <span> |
2236 <?php _e('All Tabs:'); ?> |
2385 <?php _e( 'All Tabs:' ); ?> |
2237 <a href="#" id="showall"><?php _e('Show'); ?></a> |
2386 <a href="#" id="showall"><?php _e( 'Show' ); ?></a> |
2238 <a href="#" id="hideall" style="display:none;"><?php _e('Hide'); ?></a> |
2387 <a href="#" id="hideall" style="display:none;"><?php _e( 'Hide' ); ?></a> |
2239 </span> |
2388 </span> |
2240 <?php _e('Sort Order:'); ?> |
2389 <?php _e( 'Sort Order:' ); ?> |
2241 <a href="#" id="asc"><?php _e('Ascending'); ?></a> | |
2390 <a href="#" id="asc"><?php _e( 'Ascending' ); ?></a> | |
2242 <a href="#" id="desc"><?php _e('Descending'); ?></a> | |
2391 <a href="#" id="desc"><?php _e( 'Descending' ); ?></a> | |
2243 <a href="#" id="clear"><?php _ex('Clear', 'verb'); ?></a> |
2392 <a href="#" id="clear"><?php _ex( 'Clear', 'verb' ); ?></a> |
2244 </div> |
2393 </div> |
2245 <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="gallery-form"> |
2394 <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="gallery-form"> |
2246 <?php wp_nonce_field('media-form'); ?> |
2395 <?php wp_nonce_field( 'media-form' ); ?> |
2247 <?php //media_upload_form( $errors ); ?> |
2396 <?php //media_upload_form( $errors ); ?> |
2248 <table class="widefat"> |
2397 <table class="widefat"> |
2249 <thead><tr> |
2398 <thead><tr> |
2250 <th><?php _e('Media'); ?></th> |
2399 <th><?php _e( 'Media' ); ?></th> |
2251 <th class="order-head"><?php _e('Order'); ?></th> |
2400 <th class="order-head"><?php _e( 'Order' ); ?></th> |
2252 <th class="actions-head"><?php _e('Actions'); ?></th> |
2401 <th class="actions-head"><?php _e( 'Actions' ); ?></th> |
2253 </tr></thead> |
2402 </tr></thead> |
2254 </table> |
2403 </table> |
2255 <div id="media-items"> |
2404 <div id="media-items"> |
2256 <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?> |
2405 <?php add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 ); ?> |
2257 <?php echo get_media_items($post_id, $errors); ?> |
2406 <?php echo get_media_items( $post_id, $errors ); ?> |
2258 </div> |
2407 </div> |
2259 |
2408 |
2260 <p class="ml-submit"> |
2409 <p class="ml-submit"> |
2261 <?php submit_button( __( 'Save all changes' ), 'savebutton', 'save', false, array( 'id' => 'save-all', 'style' => 'display: none;' ) ); ?> |
2410 <?php |
|
2411 submit_button( |
|
2412 __( 'Save all changes' ), |
|
2413 'savebutton', |
|
2414 'save', |
|
2415 false, |
|
2416 array( |
|
2417 'id' => 'save-all', |
|
2418 'style' => 'display: none;', |
|
2419 ) |
|
2420 ); |
|
2421 ?> |
2262 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
2422 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
2263 <input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" /> |
2423 <input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" /> |
2264 <input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" /> |
2424 <input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" /> |
2265 </p> |
2425 </p> |
2266 |
2426 |
2267 <div id="gallery-settings" style="display:none;"> |
2427 <div id="gallery-settings" style="display:none;"> |
2268 <div class="title"><?php _e('Gallery Settings'); ?></div> |
2428 <div class="title"><?php _e( 'Gallery Settings' ); ?></div> |
2269 <table id="basic" class="describe"><tbody> |
2429 <table id="basic" class="describe"><tbody> |
2270 <tr> |
2430 <tr> |
2271 <th scope="row" class="label"> |
2431 <th scope="row" class="label"> |
2272 <label> |
2432 <label> |
2273 <span class="alignleft"><?php _e('Link thumbnails to:'); ?></span> |
2433 <span class="alignleft"><?php _e( 'Link thumbnails to:' ); ?></span> |
2274 </label> |
2434 </label> |
2275 </th> |
2435 </th> |
2276 <td class="field"> |
2436 <td class="field"> |
2277 <input type="radio" name="linkto" id="linkto-file" value="file" /> |
2437 <input type="radio" name="linkto" id="linkto-file" value="file" /> |
2278 <label for="linkto-file" class="radio"><?php _e('Image File'); ?></label> |
2438 <label for="linkto-file" class="radio"><?php _e( 'Image File' ); ?></label> |
2279 |
2439 |
2280 <input type="radio" checked="checked" name="linkto" id="linkto-post" value="post" /> |
2440 <input type="radio" checked="checked" name="linkto" id="linkto-post" value="post" /> |
2281 <label for="linkto-post" class="radio"><?php _e('Attachment Page'); ?></label> |
2441 <label for="linkto-post" class="radio"><?php _e( 'Attachment Page' ); ?></label> |
2282 </td> |
2442 </td> |
2283 </tr> |
2443 </tr> |
2284 |
2444 |
2285 <tr> |
2445 <tr> |
2286 <th scope="row" class="label"> |
2446 <th scope="row" class="label"> |
2287 <label> |
2447 <label> |
2288 <span class="alignleft"><?php _e('Order images by:'); ?></span> |
2448 <span class="alignleft"><?php _e( 'Order images by:' ); ?></span> |
2289 </label> |
2449 </label> |
2290 </th> |
2450 </th> |
2291 <td class="field"> |
2451 <td class="field"> |
2292 <select id="orderby" name="orderby"> |
2452 <select id="orderby" name="orderby"> |
2293 <option value="menu_order" selected="selected"><?php _e('Menu order'); ?></option> |
2453 <option value="menu_order" selected="selected"><?php _e( 'Menu order' ); ?></option> |
2294 <option value="title"><?php _e('Title'); ?></option> |
2454 <option value="title"><?php _e( 'Title' ); ?></option> |
2295 <option value="post_date"><?php _e('Date/Time'); ?></option> |
2455 <option value="post_date"><?php _e( 'Date/Time' ); ?></option> |
2296 <option value="rand"><?php _e('Random'); ?></option> |
2456 <option value="rand"><?php _e( 'Random' ); ?></option> |
2297 </select> |
2457 </select> |
2298 </td> |
2458 </td> |
2299 </tr> |
2459 </tr> |
2300 |
2460 |
2301 <tr> |
2461 <tr> |
2302 <th scope="row" class="label"> |
2462 <th scope="row" class="label"> |
2303 <label> |
2463 <label> |
2304 <span class="alignleft"><?php _e('Order:'); ?></span> |
2464 <span class="alignleft"><?php _e( 'Order:' ); ?></span> |
2305 </label> |
2465 </label> |
2306 </th> |
2466 </th> |
2307 <td class="field"> |
2467 <td class="field"> |
2308 <input type="radio" checked="checked" name="order" id="order-asc" value="asc" /> |
2468 <input type="radio" checked="checked" name="order" id="order-asc" value="asc" /> |
2309 <label for="order-asc" class="radio"><?php _e('Ascending'); ?></label> |
2469 <label for="order-asc" class="radio"><?php _e( 'Ascending' ); ?></label> |
2310 |
2470 |
2311 <input type="radio" name="order" id="order-desc" value="desc" /> |
2471 <input type="radio" name="order" id="order-desc" value="desc" /> |
2312 <label for="order-desc" class="radio"><?php _e('Descending'); ?></label> |
2472 <label for="order-desc" class="radio"><?php _e( 'Descending' ); ?></label> |
2313 </td> |
2473 </td> |
2314 </tr> |
2474 </tr> |
2315 |
2475 |
2316 <tr> |
2476 <tr> |
2317 <th scope="row" class="label"> |
2477 <th scope="row" class="label"> |
2318 <label> |
2478 <label> |
2319 <span class="alignleft"><?php _e('Gallery columns:'); ?></span> |
2479 <span class="alignleft"><?php _e( 'Gallery columns:' ); ?></span> |
2320 </label> |
2480 </label> |
2321 </th> |
2481 </th> |
2322 <td class="field"> |
2482 <td class="field"> |
2323 <select id="columns" name="columns"> |
2483 <select id="columns" name="columns"> |
2324 <option value="1">1</option> |
2484 <option value="1">1</option> |
2356 * @global string $tab |
2516 * @global string $tab |
2357 * @global array $post_mime_types |
2517 * @global array $post_mime_types |
2358 * |
2518 * |
2359 * @param array $errors |
2519 * @param array $errors |
2360 */ |
2520 */ |
2361 function media_upload_library_form($errors) { |
2521 function media_upload_library_form( $errors ) { |
2362 global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types; |
2522 global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types; |
2363 |
2523 |
2364 media_upload_header(); |
2524 media_upload_header(); |
2365 |
2525 |
2366 $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0; |
2526 $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0; |
2367 |
2527 |
2368 $form_action_url = admin_url("media-upload.php?type=$type&tab=library&post_id=$post_id"); |
2528 $form_action_url = admin_url( "media-upload.php?type=$type&tab=library&post_id=$post_id" ); |
2369 /** This filter is documented in wp-admin/includes/media.php */ |
2529 /** This filter is documented in wp-admin/includes/media.php */ |
2370 $form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type ); |
2530 $form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type ); |
2371 $form_class = 'media-upload-form validate'; |
2531 $form_class = 'media-upload-form validate'; |
2372 |
2532 |
2373 if ( get_user_setting('uploader') ) |
2533 if ( get_user_setting( 'uploader' ) ) { |
2374 $form_class .= ' html-uploader'; |
2534 $form_class .= ' html-uploader'; |
2375 |
2535 } |
2376 $q = $_GET; |
2536 |
|
2537 $q = $_GET; |
2377 $q['posts_per_page'] = 10; |
2538 $q['posts_per_page'] = 10; |
2378 $q['paged'] = isset( $q['paged'] ) ? intval( $q['paged'] ) : 0; |
2539 $q['paged'] = isset( $q['paged'] ) ? intval( $q['paged'] ) : 0; |
2379 if ( $q['paged'] < 1 ) { |
2540 if ( $q['paged'] < 1 ) { |
2380 $q['paged'] = 1; |
2541 $q['paged'] = 1; |
2381 } |
2542 } |
2382 $q['offset'] = ( $q['paged'] - 1 ) * 10; |
2543 $q['offset'] = ( $q['paged'] - 1 ) * 10; |
2383 if ( $q['offset'] < 1 ) { |
2544 if ( $q['offset'] < 1 ) { |
2384 $q['offset'] = 0; |
2545 $q['offset'] = 0; |
2385 } |
2546 } |
2386 |
2547 |
2387 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query( $q ); |
2548 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query( $q ); |
2388 |
2549 |
2389 ?> |
2550 ?> |
2390 |
2551 |
2391 <form id="filter" method="get"> |
2552 <form id="filter" method="get"> |
2392 <input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" /> |
2553 <input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" /> |
2393 <input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" /> |
2554 <input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" /> |
2394 <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" /> |
2555 <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" /> |
2395 <input type="hidden" name="post_mime_type" value="<?php echo isset( $_GET['post_mime_type'] ) ? esc_attr( $_GET['post_mime_type'] ) : ''; ?>" /> |
2556 <input type="hidden" name="post_mime_type" value="<?php echo isset( $_GET['post_mime_type'] ) ? esc_attr( $_GET['post_mime_type'] ) : ''; ?>" /> |
2396 <input type="hidden" name="context" value="<?php echo isset( $_GET['context'] ) ? esc_attr( $_GET['context'] ) : ''; ?>" /> |
2557 <input type="hidden" name="context" value="<?php echo isset( $_GET['context'] ) ? esc_attr( $_GET['context'] ) : ''; ?>" /> |
2397 |
2558 |
2398 <p id="media-search" class="search-box"> |
2559 <p id="media-search" class="search-box"> |
2399 <label class="screen-reader-text" for="media-search-input"><?php _e('Search Media');?>:</label> |
2560 <label class="screen-reader-text" for="media-search-input"><?php _e( 'Search Media' ); ?>:</label> |
2400 <input type="search" id="media-search-input" name="s" value="<?php the_search_query(); ?>" /> |
2561 <input type="search" id="media-search-input" name="s" value="<?php the_search_query(); ?>" /> |
2401 <?php submit_button( __( 'Search Media' ), '', '', false ); ?> |
2562 <?php submit_button( __( 'Search Media' ), '', '', false ); ?> |
2402 </p> |
2563 </p> |
2403 |
2564 |
2404 <ul class="subsubsub"> |
2565 <ul class="subsubsub"> |
2405 <?php |
2566 <?php |
2406 $type_links = array(); |
2567 $type_links = array(); |
2407 $_num_posts = (array) wp_count_attachments(); |
2568 $_num_posts = (array) wp_count_attachments(); |
2408 $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts)); |
2569 $matches = wp_match_mime_types( array_keys( $post_mime_types ), array_keys( $_num_posts ) ); |
2409 foreach ( $matches as $_type => $reals ) |
2570 foreach ( $matches as $_type => $reals ) { |
2410 foreach ( $reals as $real ) |
2571 foreach ( $reals as $real ) { |
2411 if ( isset($num_posts[$_type]) ) |
2572 if ( isset( $num_posts[ $_type ] ) ) { |
2412 $num_posts[$_type] += $_num_posts[$real]; |
2573 $num_posts[ $_type ] += $_num_posts[ $real ]; |
2413 else |
2574 } else { |
2414 $num_posts[$_type] = $_num_posts[$real]; |
2575 $num_posts[ $_type ] = $_num_posts[ $real ]; |
2415 // If available type specified by media button clicked, filter by that type |
2576 } |
2416 if ( empty($_GET['post_mime_type']) && !empty($num_posts[$type]) ) { |
2577 } |
2417 $_GET['post_mime_type'] = $type; |
2578 } |
2418 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); |
2579 // If available type specified by media button clicked, filter by that type |
2419 } |
2580 if ( empty( $_GET['post_mime_type'] ) && ! empty( $num_posts[ $type ] ) ) { |
2420 if ( empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all' ) |
2581 $_GET['post_mime_type'] = $type; |
2421 $class = ' class="current"'; |
2582 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); |
2422 else |
2583 } |
2423 $class = ''; |
2584 if ( empty( $_GET['post_mime_type'] ) || $_GET['post_mime_type'] == 'all' ) { |
2424 $type_links[] = '<li><a href="' . esc_url(add_query_arg(array('post_mime_type'=>'all', 'paged'=>false, 'm'=>false))) . '"' . $class . '>' . __('All Types') . '</a>'; |
|
2425 foreach ( $post_mime_types as $mime_type => $label ) { |
|
2426 $class = ''; |
|
2427 |
|
2428 if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) ) |
|
2429 continue; |
|
2430 |
|
2431 if ( isset($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) ) |
|
2432 $class = ' class="current"'; |
2585 $class = ' class="current"'; |
2433 |
2586 } else { |
2434 $type_links[] = '<li><a href="' . esc_url(add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false))) . '"' . $class . '>' . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), '<span id="' . $mime_type . '-counter">' . number_format_i18n( $num_posts[$mime_type] ) . '</span>') . '</a>'; |
2587 $class = ''; |
2435 } |
2588 } |
2436 /** |
2589 $type_links[] = '<li><a href="' . esc_url( |
2437 * Filters the media upload mime type list items. |
2590 add_query_arg( |
2438 * |
2591 array( |
2439 * Returned values should begin with an `<li>` tag. |
2592 'post_mime_type' => 'all', |
2440 * |
2593 'paged' => false, |
2441 * @since 3.1.0 |
2594 'm' => false, |
2442 * |
2595 ) |
2443 * @param array $type_links An array of list items containing mime type link HTML. |
2596 ) |
2444 */ |
2597 ) . '"' . $class . '>' . __( 'All Types' ) . '</a>'; |
2445 echo implode(' | </li>', apply_filters( 'media_upload_mime_type_links', $type_links ) ) . '</li>'; |
2598 foreach ( $post_mime_types as $mime_type => $label ) { |
2446 unset($type_links); |
2599 $class = ''; |
2447 ?> |
2600 |
|
2601 if ( ! wp_match_mime_types( $mime_type, $avail_post_mime_types ) ) { |
|
2602 continue; |
|
2603 } |
|
2604 |
|
2605 if ( isset( $_GET['post_mime_type'] ) && wp_match_mime_types( $mime_type, $_GET['post_mime_type'] ) ) { |
|
2606 $class = ' class="current"'; |
|
2607 } |
|
2608 |
|
2609 $type_links[] = '<li><a href="' . esc_url( |
|
2610 add_query_arg( |
|
2611 array( |
|
2612 'post_mime_type' => $mime_type, |
|
2613 'paged' => false, |
|
2614 ) |
|
2615 ) |
|
2616 ) . '"' . $class . '>' . sprintf( translate_nooped_plural( $label[2], $num_posts[ $mime_type ] ), '<span id="' . $mime_type . '-counter">' . number_format_i18n( $num_posts[ $mime_type ] ) . '</span>' ) . '</a>'; |
|
2617 } |
|
2618 /** |
|
2619 * Filters the media upload mime type list items. |
|
2620 * |
|
2621 * Returned values should begin with an `<li>` tag. |
|
2622 * |
|
2623 * @since 3.1.0 |
|
2624 * |
|
2625 * @param string[] $type_links An array of list items containing mime type link HTML. |
|
2626 */ |
|
2627 echo implode( ' | </li>', apply_filters( 'media_upload_mime_type_links', $type_links ) ) . '</li>'; |
|
2628 unset( $type_links ); |
|
2629 ?> |
2448 </ul> |
2630 </ul> |
2449 |
2631 |
2450 <div class="tablenav"> |
2632 <div class="tablenav"> |
2451 |
2633 |
2452 <?php |
2634 <?php |
2453 $page_links = paginate_links( array( |
2635 $page_links = paginate_links( |
2454 'base' => add_query_arg( 'paged', '%#%' ), |
2636 array( |
2455 'format' => '', |
2637 'base' => add_query_arg( 'paged', '%#%' ), |
2456 'prev_text' => __('«'), |
2638 'format' => '', |
2457 'next_text' => __('»'), |
2639 'prev_text' => __( '«' ), |
2458 'total' => ceil($wp_query->found_posts / 10), |
2640 'next_text' => __( '»' ), |
2459 'current' => $q['paged'], |
2641 'total' => ceil( $wp_query->found_posts / 10 ), |
2460 )); |
2642 'current' => $q['paged'], |
2461 |
2643 ) |
2462 if ( $page_links ) |
2644 ); |
2463 echo "<div class='tablenav-pages'>$page_links</div>"; |
2645 |
2464 ?> |
2646 if ( $page_links ) { |
|
2647 echo "<div class='tablenav-pages'>$page_links</div>"; |
|
2648 } |
|
2649 ?> |
2465 |
2650 |
2466 <div class="alignleft actions"> |
2651 <div class="alignleft actions"> |
2467 <?php |
2652 <?php |
2468 |
2653 |
2469 $arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'attachment' ORDER BY post_date DESC"; |
2654 $arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'attachment' ORDER BY post_date DESC"; |
2470 |
2655 |
2471 $arc_result = $wpdb->get_results( $arc_query ); |
2656 $arc_result = $wpdb->get_results( $arc_query ); |
2472 |
2657 |
2473 $month_count = count($arc_result); |
2658 $month_count = count( $arc_result ); |
2474 $selected_month = isset( $_GET['m'] ) ? $_GET['m'] : 0; |
2659 $selected_month = isset( $_GET['m'] ) ? $_GET['m'] : 0; |
2475 |
2660 |
2476 if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?> |
2661 if ( $month_count && ! ( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { |
|
2662 ?> |
2477 <select name='m'> |
2663 <select name='m'> |
2478 <option<?php selected( $selected_month, 0 ); ?> value='0'><?php _e( 'All dates' ); ?></option> |
2664 <option<?php selected( $selected_month, 0 ); ?> value='0'><?php _e( 'All dates' ); ?></option> |
2479 <?php |
2665 <?php |
2480 foreach ($arc_result as $arc_row) { |
2666 foreach ( $arc_result as $arc_row ) { |
2481 if ( $arc_row->yyear == 0 ) |
2667 if ( $arc_row->yyear == 0 ) { |
2482 continue; |
2668 continue; |
2483 $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 ); |
2669 } |
2484 |
2670 $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 ); |
2485 if ( $arc_row->yyear . $arc_row->mmonth == $selected_month ) |
2671 |
2486 $default = ' selected="selected"'; |
2672 if ( $arc_row->yyear . $arc_row->mmonth == $selected_month ) { |
2487 else |
2673 $default = ' selected="selected"'; |
2488 $default = ''; |
2674 } else { |
2489 |
2675 $default = ''; |
2490 echo "<option$default value='" . esc_attr( $arc_row->yyear . $arc_row->mmonth ) . "'>"; |
2676 } |
2491 echo esc_html( $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear" ); |
2677 |
2492 echo "</option>\n"; |
2678 echo "<option$default value='" . esc_attr( $arc_row->yyear . $arc_row->mmonth ) . "'>"; |
2493 } |
2679 echo esc_html( $wp_locale->get_month( $arc_row->mmonth ) . " $arc_row->yyear" ); |
2494 ?> |
2680 echo "</option>\n"; |
|
2681 } |
|
2682 ?> |
2495 </select> |
2683 </select> |
2496 <?php } ?> |
2684 <?php } ?> |
2497 |
2685 |
2498 <?php submit_button( __( 'Filter »' ), '', 'post-query-submit', false ); ?> |
2686 <?php submit_button( __( 'Filter »' ), '', 'post-query-submit', false ); ?> |
2499 |
2687 |
2500 </div> |
2688 </div> |
2501 |
2689 |
2502 <br class="clear" /> |
2690 <br class="clear" /> |
2503 </div> |
2691 </div> |
2504 </form> |
2692 </form> |
2505 |
2693 |
2506 <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="library-form"> |
2694 <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="library-form"> |
2507 |
2695 |
2508 <?php wp_nonce_field('media-form'); ?> |
2696 <?php wp_nonce_field( 'media-form' ); ?> |
2509 <?php //media_upload_form( $errors ); ?> |
2697 <?php //media_upload_form( $errors ); ?> |
2510 |
2698 |
2511 <script type="text/javascript"> |
2699 <script type="text/javascript"> |
2512 <!-- |
2700 <!-- |
2513 jQuery(function($){ |
2701 jQuery(function($){ |
2514 var preloaded = $(".media-item.preloaded"); |
2702 var preloaded = $(".media-item.preloaded"); |
2573 <tr> |
2762 <tr> |
2574 <th scope="row" class="label" style="width:130px;"> |
2763 <th scope="row" class="label" style="width:130px;"> |
2575 <label for="src"><span class="alignleft">' . __( 'URL' ) . '</span> <span class="required">*</span></label> |
2764 <label for="src"><span class="alignleft">' . __( 'URL' ) . '</span> <span class="required">*</span></label> |
2576 <span class="alignright" id="status_img"></span> |
2765 <span class="alignright" id="status_img"></span> |
2577 </th> |
2766 </th> |
2578 <td class="field"><input id="src" name="src" value="" type="text" required aria-required="true" onblur="addExtImage.getImageData()" /></td> |
2767 <td class="field"><input id="src" name="src" value="" type="text" required onblur="addExtImage.getImageData()" /></td> |
2579 </tr> |
2768 </tr> |
2580 |
2769 |
2581 <tr> |
2770 <tr> |
2582 <th scope="row" class="label"> |
2771 <th scope="row" class="label"> |
2583 <label for="title"><span class="alignleft">' . __( 'Title' ) . '</span> <span class="required">*</span></label> |
2772 <label for="title"><span class="alignleft">' . __( 'Title' ) . '</span> <span class="required">*</span></label> |
2584 </th> |
2773 </th> |
2585 <td class="field"><input id="title" name="title" value="" type="text" required aria-required="true" /></td> |
2774 <td class="field"><input id="title" name="title" value="" type="text" required /></td> |
2586 </tr> |
2775 </tr> |
2587 |
2776 |
2588 <tr class="not-image"><td></td><td><p class="help">' . __('Link text, e.g. “Ransom Demands (PDF)”') . '</p></td></tr> |
2777 <tr class="not-image"><td></td><td><p class="help">' . __( 'Link text, e.g. “Ransom Demands (PDF)”' ) . '</p></td></tr> |
2589 |
2778 |
2590 <tr class="image-only"> |
2779 <tr class="image-only"> |
2591 <th scope="row" class="label"> |
2780 <th scope="row" class="label"> |
2592 <label for="alt"><span class="alignleft">' . __('Alternative Text') . '</span></label> |
2781 <label for="alt"><span class="alignleft">' . __( 'Alternative Text' ) . '</span></label> |
2593 </th> |
2782 </th> |
2594 <td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" /> |
2783 <td class="field"><input id="alt" name="alt" value="" type="text" required /> |
2595 <p class="help">' . __('Alt text for the image, e.g. “The Mona Lisa”') . '</p></td> |
2784 <p class="help">' . __( 'Alt text for the image, e.g. “The Mona Lisa”' ) . '</p></td> |
2596 </tr> |
2785 </tr> |
2597 ' . $caption . ' |
2786 ' . $caption . ' |
2598 <tr class="align image-only"> |
2787 <tr class="align image-only"> |
2599 <th scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th> |
2788 <th scope="row" class="label"><p><label for="align">' . __( 'Alignment' ) . '</label></p></th> |
2600 <td class="field"> |
2789 <td class="field"> |
2601 <input name="align" id="align-none" value="none" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'none' ? ' checked="checked"' : '').' /> |
2790 <input name="align" id="align-none" value="none" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ( $default_align == 'none' ? ' checked="checked"' : '' ) . ' /> |
2602 <label for="align-none" class="align image-align-none-label">' . __('None') . '</label> |
2791 <label for="align-none" class="align image-align-none-label">' . __( 'None' ) . '</label> |
2603 <input name="align" id="align-left" value="left" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'left' ? ' checked="checked"' : '').' /> |
2792 <input name="align" id="align-left" value="left" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ( $default_align == 'left' ? ' checked="checked"' : '' ) . ' /> |
2604 <label for="align-left" class="align image-align-left-label">' . __('Left') . '</label> |
2793 <label for="align-left" class="align image-align-left-label">' . __( 'Left' ) . '</label> |
2605 <input name="align" id="align-center" value="center" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'center' ? ' checked="checked"' : '').' /> |
2794 <input name="align" id="align-center" value="center" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ( $default_align == 'center' ? ' checked="checked"' : '' ) . ' /> |
2606 <label for="align-center" class="align image-align-center-label">' . __('Center') . '</label> |
2795 <label for="align-center" class="align image-align-center-label">' . __( 'Center' ) . '</label> |
2607 <input name="align" id="align-right" value="right" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'right' ? ' checked="checked"' : '').' /> |
2796 <input name="align" id="align-right" value="right" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ( $default_align == 'right' ? ' checked="checked"' : '' ) . ' /> |
2608 <label for="align-right" class="align image-align-right-label">' . __('Right') . '</label> |
2797 <label for="align-right" class="align image-align-right-label">' . __( 'Right' ) . '</label> |
2609 </td> |
2798 </td> |
2610 </tr> |
2799 </tr> |
2611 |
2800 |
2612 <tr class="image-only"> |
2801 <tr class="image-only"> |
2613 <th scope="row" class="label"> |
2802 <th scope="row" class="label"> |
2614 <label for="url"><span class="alignleft">' . __('Link Image To:') . '</span></label> |
2803 <label for="url"><span class="alignleft">' . __( 'Link Image To:' ) . '</span></label> |
2615 </th> |
2804 </th> |
2616 <td class="field"><input id="url" name="url" value="" type="text" /><br /> |
2805 <td class="field"><input id="url" name="url" value="" type="text" /><br /> |
2617 |
2806 |
2618 <button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __('None') . '</button> |
2807 <button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __( 'None' ) . '</button> |
2619 <button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __('Link to image') . '</button> |
2808 <button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __( 'Link to image' ) . '</button> |
2620 <p class="help">' . __('Enter a link URL or click above for presets.') . '</p></td> |
2809 <p class="help">' . __( 'Enter a link URL or click above for presets.' ) . '</p></td> |
2621 </tr> |
2810 </tr> |
2622 <tr class="image-only"> |
2811 <tr class="image-only"> |
2623 <td></td> |
2812 <td></td> |
2624 <td> |
2813 <td> |
2625 <input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . esc_attr__('Insert into Post') . '" /> |
2814 <input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . esc_attr__( 'Insert into Post' ) . '" /> |
2626 </td> |
2815 </td> |
2627 </tr> |
2816 </tr> |
2628 <tr class="not-image"> |
2817 <tr class="not-image"> |
2629 <td></td> |
2818 <td></td> |
2630 <td> |
2819 <td> |
2718 * |
2912 * |
2719 * @param WP_Post $post A post object. |
2913 * @param WP_Post $post A post object. |
2720 */ |
2914 */ |
2721 function edit_form_image_editor( $post ) { |
2915 function edit_form_image_editor( $post ) { |
2722 $open = isset( $_GET['image-editor'] ); |
2916 $open = isset( $_GET['image-editor'] ); |
2723 if ( $open ) |
2917 if ( $open ) { |
2724 require_once ABSPATH . 'wp-admin/includes/image-edit.php'; |
2918 require_once ABSPATH . 'wp-admin/includes/image-edit.php'; |
|
2919 } |
2725 |
2920 |
2726 $thumb_url = false; |
2921 $thumb_url = false; |
2727 if ( $attachment_id = intval( $post->ID ) ) |
2922 if ( $attachment_id = intval( $post->ID ) ) { |
2728 $thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 450 ), true ); |
2923 $thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 450 ), true ); |
|
2924 } |
2729 |
2925 |
2730 $alt_text = get_post_meta( $post->ID, '_wp_attachment_image_alt', true ); |
2926 $alt_text = get_post_meta( $post->ID, '_wp_attachment_image_alt', true ); |
2731 |
2927 |
2732 $att_url = wp_get_attachment_url( $post->ID ); ?> |
2928 $att_url = wp_get_attachment_url( $post->ID ); |
|
2929 ?> |
2733 <div class="wp_attachment_holder wp-clearfix"> |
2930 <div class="wp_attachment_holder wp-clearfix"> |
2734 <?php |
2931 <?php |
2735 if ( wp_attachment_is_image( $post->ID ) ) : |
2932 if ( wp_attachment_is_image( $post->ID ) ) : |
2736 $image_edit_button = ''; |
2933 $image_edit_button = ''; |
2737 if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { |
2934 if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { |
2738 $nonce = wp_create_nonce( "image_editor-$post->ID" ); |
2935 $nonce = wp_create_nonce( "image_editor-$post->ID" ); |
2739 $image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>"; |
2936 $image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>"; |
2740 } |
2937 } |
2741 ?> |
2938 |
|
2939 $open_style = $not_open_style = ''; |
|
2940 if ( $open ) { |
|
2941 $open_style = ' style="display:none"'; |
|
2942 } else { |
|
2943 $not_open_style = ' style="display:none"'; |
|
2944 } |
|
2945 ?> |
2742 |
2946 |
2743 <div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div> |
2947 <div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div> |
2744 |
2948 |
2745 <div<?php if ( $open ) echo ' style="display:none"'; ?> class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>"> |
2949 <div<?php echo $open_style; ?> class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>"> |
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> |
2950 <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> |
2747 <p><?php echo $image_edit_button; ?></p> |
2951 <p><?php echo $image_edit_button; ?></p> |
2748 </div> |
2952 </div> |
2749 <div<?php if ( ! $open ) echo ' style="display:none"'; ?> class="image-editor" id="image-editor-<?php echo $attachment_id; ?>"> |
2953 <div<?php echo $not_open_style; ?> class="image-editor" id="image-editor-<?php echo $attachment_id; ?>"> |
2750 <?php if ( $open ) wp_image_editor( $attachment_id ); ?> |
2954 <?php |
|
2955 if ( $open ) { |
|
2956 wp_image_editor( $attachment_id );} |
|
2957 ?> |
2751 </div> |
2958 </div> |
2752 <?php |
2959 <?php |
2753 elseif ( $attachment_id && wp_attachment_is( 'audio', $post ) ): |
2960 elseif ( $attachment_id && wp_attachment_is( 'audio', $post ) ) : |
2754 |
2961 |
2755 wp_maybe_generate_attachment_metadata( $post ); |
2962 wp_maybe_generate_attachment_metadata( $post ); |
2756 |
2963 |
2757 echo wp_audio_shortcode( array( 'src' => $att_url ) ); |
2964 echo wp_audio_shortcode( array( 'src' => $att_url ) ); |
2758 |
2965 |
2759 elseif ( $attachment_id && wp_attachment_is( 'video', $post ) ): |
2966 elseif ( $attachment_id && wp_attachment_is( 'video', $post ) ) : |
2760 |
2967 |
2761 wp_maybe_generate_attachment_metadata( $post ); |
2968 wp_maybe_generate_attachment_metadata( $post ); |
2762 |
2969 |
2763 $meta = wp_get_attachment_metadata( $attachment_id ); |
2970 $meta = wp_get_attachment_metadata( $attachment_id ); |
2764 $w = ! empty( $meta['width'] ) ? min( $meta['width'], 640 ) : 0; |
2971 $w = ! empty( $meta['width'] ) ? min( $meta['width'], 640 ) : 0; |
2765 $h = ! empty( $meta['height'] ) ? $meta['height'] : 0; |
2972 $h = ! empty( $meta['height'] ) ? $meta['height'] : 0; |
2766 if ( $h && $w < $meta['width'] ) { |
2973 if ( $h && $w < $meta['width'] ) { |
2767 $h = round( ( $meta['height'] * $w ) / $meta['width'] ); |
2974 $h = round( ( $meta['height'] * $w ) / $meta['width'] ); |
2768 } |
2975 } |
2769 |
2976 |
2770 $attr = array( 'src' => $att_url ); |
2977 $attr = array( 'src' => $att_url ); |
2771 if ( ! empty( $w ) && ! empty( $h ) ) { |
2978 if ( ! empty( $w ) && ! empty( $h ) ) { |
2772 $attr['width'] = $w; |
2979 $attr['width'] = $w; |
2773 $attr['height'] = $h; |
2980 $attr['height'] = $h; |
2774 } |
2981 } |
2775 |
2982 |
2776 $thumb_id = get_post_thumbnail_id( $attachment_id ); |
2983 $thumb_id = get_post_thumbnail_id( $attachment_id ); |
2777 if ( ! empty( $thumb_id ) ) { |
2984 if ( ! empty( $thumb_id ) ) { |
2778 $attr['poster'] = wp_get_attachment_url( $thumb_id ); |
2985 $attr['poster'] = wp_get_attachment_url( $thumb_id ); |
2779 } |
2986 } |
2780 |
2987 |
2781 echo wp_video_shortcode( $attr ); |
2988 echo wp_video_shortcode( $attr ); |
2782 |
2989 |
2783 elseif ( isset( $thumb_url[0] ) ): |
2990 elseif ( isset( $thumb_url[0] ) ) : |
2784 |
2991 |
2785 ?> |
2992 ?> |
2786 <div class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>"> |
2993 <div class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>"> |
2787 <p id="thumbnail-head-<?php echo $attachment_id; ?>"> |
2994 <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="" /> |
2995 <img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" /> |
2789 </p> |
2996 </p> |
2790 </div> |
2997 </div> |
2791 <?php |
2998 <?php |
2792 |
2999 |
2793 else: |
3000 else : |
2794 |
3001 |
2795 /** |
3002 /** |
2796 * Fires when an attachment type can't be rendered in the edit form. |
3003 * Fires when an attachment type can't be rendered in the edit form. |
2797 * |
3004 * |
2798 * @since 4.6.0 |
3005 * @since 4.6.0 |
2799 * |
3006 * |
2800 * @param WP_Post $post A post object. |
3007 * @param WP_Post $post A post object. |
2801 */ |
3008 */ |
2802 do_action( 'wp_edit_form_attachment_display', $post ); |
3009 do_action( 'wp_edit_form_attachment_display', $post ); |
2803 |
3010 |
2804 endif; ?> |
3011 endif; |
|
3012 ?> |
2805 </div> |
3013 </div> |
2806 <div class="wp_attachment_details edit-form-section"> |
3014 <div class="wp_attachment_details edit-form-section"> |
|
3015 <?php if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) : ?> |
|
3016 <p class="attachment-alt-text"> |
|
3017 <label for="attachment_alt"><strong><?php _e( 'Alternative Text' ); ?></strong></label><br /> |
|
3018 <input type="text" class="widefat" name="_wp_attachment_image_alt" id="attachment_alt" aria-describedby="alt-text-description" value="<?php echo esc_attr( $alt_text ); ?>" /> |
|
3019 </p> |
|
3020 <p class="attachment-alt-text-description" id="alt-text-description"> |
|
3021 <?php |
|
3022 printf( |
|
3023 /* translators: 1: link to tutorial, 2: additional link attributes, 3: accessibility text */ |
|
3024 __( '<a href="%1$s" %2$s>Describe the purpose of the image%3$s</a>. Leave empty if the image is purely decorative.' ), |
|
3025 esc_url( 'https://www.w3.org/WAI/tutorials/images/decision-tree' ), |
|
3026 'target="_blank" rel="noopener noreferrer"', |
|
3027 sprintf( |
|
3028 '<span class="screen-reader-text"> %s</span>', |
|
3029 /* translators: accessibility text */ |
|
3030 __( '(opens in a new tab)' ) |
|
3031 ) |
|
3032 ); |
|
3033 ?> |
|
3034 </p> |
|
3035 <?php endif; ?> |
|
3036 |
2807 <p> |
3037 <p> |
2808 <label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br /> |
3038 <label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br /> |
2809 <textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea> |
3039 <textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea> |
2810 </p> |
3040 </p> |
2811 |
3041 |
2812 |
|
2813 <?php if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) : ?> |
|
2814 <p> |
|
2815 <label for="attachment_alt"><strong><?php _e( 'Alternative Text' ); ?></strong></label><br /> |
|
2816 <input type="text" class="widefat" name="_wp_attachment_image_alt" id="attachment_alt" value="<?php echo esc_attr( $alt_text ); ?>" /> |
|
2817 </p> |
|
2818 <?php endif; ?> |
|
2819 |
|
2820 <?php |
3042 <?php |
2821 $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' ); |
3043 $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' ); |
2822 $editor_args = array( |
3044 $editor_args = array( |
2823 'textarea_name' => 'content', |
3045 'textarea_name' => 'content', |
2824 'textarea_rows' => 5, |
3046 'textarea_rows' => 5, |
2825 'media_buttons' => false, |
3047 'media_buttons' => false, |
2826 'tinymce' => false, |
3048 'tinymce' => false, |
2827 'quicktags' => $quicktags_settings, |
3049 'quicktags' => $quicktags_settings, |
2828 ); |
3050 ); |
2829 ?> |
3051 ?> |
2830 |
3052 |
2831 <label for="attachment_content"><strong><?php _e( 'Description' ); ?></strong><?php |
3053 <label for="attachment_content"><strong><?php _e( 'Description' ); ?></strong> |
2832 if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) { |
3054 <?php |
2833 echo ': ' . __( 'Displayed on attachment pages.' ); |
3055 if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) { |
2834 } ?></label> |
3056 echo ': ' . __( 'Displayed on attachment pages.' ); |
|
3057 } |
|
3058 ?> |
|
3059 </label> |
2835 <?php wp_editor( $post->post_content, 'attachment_content', $editor_args ); ?> |
3060 <?php wp_editor( $post->post_content, 'attachment_content', $editor_args ); ?> |
2836 |
3061 |
2837 </div> |
3062 </div> |
2838 <?php |
3063 <?php |
2839 $extras = get_compat_media_markup( $post->ID ); |
3064 $extras = get_compat_media_markup( $post->ID ); |
2847 * @since 3.5.0 |
3072 * @since 3.5.0 |
2848 */ |
3073 */ |
2849 function attachment_submitbox_metadata() { |
3074 function attachment_submitbox_metadata() { |
2850 $post = get_post(); |
3075 $post = get_post(); |
2851 |
3076 |
2852 $file = get_attached_file( $post->ID ); |
3077 $file = get_attached_file( $post->ID ); |
2853 $filename = esc_html( wp_basename( $file ) ); |
3078 $filename = esc_html( wp_basename( $file ) ); |
2854 |
3079 |
2855 $media_dims = ''; |
3080 $media_dims = ''; |
2856 $meta = wp_get_attachment_metadata( $post->ID ); |
3081 $meta = wp_get_attachment_metadata( $post->ID ); |
2857 if ( isset( $meta['width'], $meta['height'] ) ) |
3082 if ( isset( $meta['width'], $meta['height'] ) ) { |
2858 $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']} × {$meta['height']}</span> "; |
3083 $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']} × {$meta['height']}</span> "; |
|
3084 } |
2859 /** This filter is documented in wp-admin/includes/media.php */ |
3085 /** This filter is documented in wp-admin/includes/media.php */ |
2860 $media_dims = apply_filters( 'media_meta', $media_dims, $post ); |
3086 $media_dims = apply_filters( 'media_meta', $media_dims, $post ); |
2861 |
3087 |
2862 $att_url = wp_get_attachment_url( $post->ID ); |
3088 $att_url = wp_get_attachment_url( $post->ID ); |
2863 ?> |
3089 ?> |
2864 <div class="misc-pub-section misc-pub-attachment"> |
3090 <div class="misc-pub-section misc-pub-attachment"> |
2865 <label for="attachment_url"><?php _e( 'File URL:' ); ?></label> |
3091 <label for="attachment_url"><?php _e( 'File URL:' ); ?></label> |
2866 <input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" id="attachment_url" value="<?php echo esc_attr( $att_url ); ?>" /> |
3092 <input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" id="attachment_url" value="<?php echo esc_attr( $att_url ); ?>" /> |
2867 </div> |
3093 </div> |
2868 <div class="misc-pub-section misc-pub-filename"> |
3094 <div class="misc-pub-section misc-pub-filename"> |
2869 <?php _e( 'File name:' ); ?> <strong><?php echo $filename; ?></strong> |
3095 <?php _e( 'File name:' ); ?> <strong><?php echo $filename; ?></strong> |
2870 </div> |
3096 </div> |
2871 <div class="misc-pub-section misc-pub-filetype"> |
3097 <div class="misc-pub-section misc-pub-filetype"> |
2872 <?php _e( 'File type:' ); ?> <strong><?php |
3098 <?php _e( 'File type:' ); ?> <strong> |
2873 if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) ) { |
3099 <?php |
2874 echo esc_html( strtoupper( $matches[1] ) ); |
3100 if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) ) { |
2875 list( $mime_type ) = explode( '/', $post->post_mime_type ); |
3101 echo esc_html( strtoupper( $matches[1] ) ); |
2876 if ( $mime_type !== 'image' && ! empty( $meta['mime_type'] ) ) { |
3102 list( $mime_type ) = explode( '/', $post->post_mime_type ); |
2877 if ( $meta['mime_type'] !== "$mime_type/" . strtolower( $matches[1] ) ) { |
3103 if ( $mime_type !== 'image' && ! empty( $meta['mime_type'] ) ) { |
2878 echo ' (' . $meta['mime_type'] . ')'; |
3104 if ( $meta['mime_type'] !== "$mime_type/" . strtolower( $matches[1] ) ) { |
|
3105 echo ' (' . $meta['mime_type'] . ')'; |
|
3106 } |
|
3107 } |
|
3108 } else { |
|
3109 echo strtoupper( str_replace( 'image/', '', $post->post_mime_type ) ); |
2879 } |
3110 } |
2880 } |
3111 ?> |
2881 } else { |
3112 </strong> |
2882 echo strtoupper( str_replace( 'image/', '', $post->post_mime_type ) ); |
|
2883 } |
|
2884 ?></strong> |
|
2885 </div> |
3113 </div> |
2886 |
3114 |
2887 <?php |
3115 <?php |
2888 $file_size = false; |
3116 $file_size = false; |
2889 |
3117 |
2890 if ( isset( $meta['filesize'] ) ) |
3118 if ( isset( $meta['filesize'] ) ) { |
2891 $file_size = $meta['filesize']; |
3119 $file_size = $meta['filesize']; |
2892 elseif ( file_exists( $file ) ) |
3120 } elseif ( file_exists( $file ) ) { |
2893 $file_size = filesize( $file ); |
3121 $file_size = filesize( $file ); |
2894 |
3122 } |
2895 if ( ! empty( $file_size ) ) : ?> |
3123 |
|
3124 if ( ! empty( $file_size ) ) : |
|
3125 ?> |
2896 <div class="misc-pub-section misc-pub-filesize"> |
3126 <div class="misc-pub-section misc-pub-filesize"> |
2897 <?php _e( 'File size:' ); ?> <strong><?php echo size_format( $file_size ); ?></strong> |
3127 <?php _e( 'File size:' ); ?> <strong><?php echo size_format( $file_size ); ?></strong> |
2898 </div> |
3128 </div> |
2899 <?php |
3129 <?php |
2900 endif; |
3130 endif; |
2990 * @param array $metadata An existing array with data |
3222 * @param array $metadata An existing array with data |
2991 * @param array $data Data supplied by ID3 tags |
3223 * @param array $data Data supplied by ID3 tags |
2992 */ |
3224 */ |
2993 function wp_add_id3_tag_data( &$metadata, $data ) { |
3225 function wp_add_id3_tag_data( &$metadata, $data ) { |
2994 foreach ( array( 'id3v2', 'id3v1' ) as $version ) { |
3226 foreach ( array( 'id3v2', 'id3v1' ) as $version ) { |
2995 if ( ! empty( $data[$version]['comments'] ) ) { |
3227 if ( ! empty( $data[ $version ]['comments'] ) ) { |
2996 foreach ( $data[$version]['comments'] as $key => $list ) { |
3228 foreach ( $data[ $version ]['comments'] as $key => $list ) { |
2997 if ( 'length' !== $key && ! empty( $list ) ) { |
3229 if ( 'length' !== $key && ! empty( $list ) ) { |
2998 $metadata[$key] = wp_kses_post( reset( $list ) ); |
3230 $metadata[ $key ] = wp_kses_post( reset( $list ) ); |
2999 // Fix bug in byte stream analysis. |
3231 // Fix bug in byte stream analysis. |
3000 if ( 'terms_of_use' === $key && 0 === strpos( $metadata[$key], 'yright notice.' ) ) |
3232 if ( 'terms_of_use' === $key && 0 === strpos( $metadata[ $key ], 'yright notice.' ) ) { |
3001 $metadata[$key] = 'Cop' . $metadata[$key]; |
3233 $metadata[ $key ] = 'Cop' . $metadata[ $key ]; |
|
3234 } |
3002 } |
3235 } |
3003 } |
3236 } |
3004 break; |
3237 break; |
3005 } |
3238 } |
3006 } |
3239 } |
3007 |
3240 |
3008 if ( ! empty( $data['id3v2']['APIC'] ) ) { |
3241 if ( ! empty( $data['id3v2']['APIC'] ) ) { |
3009 $image = reset( $data['id3v2']['APIC']); |
3242 $image = reset( $data['id3v2']['APIC'] ); |
3010 if ( ! empty( $image['data'] ) ) { |
3243 if ( ! empty( $image['data'] ) ) { |
3011 $metadata['image'] = array( |
3244 $metadata['image'] = array( |
3012 'data' => $image['data'], |
3245 'data' => $image['data'], |
3013 'mime' => $image['image_mime'], |
3246 'mime' => $image['image_mime'], |
3014 'width' => $image['image_width'], |
3247 'width' => $image['image_width'], |
3015 'height' => $image['image_height'] |
3248 'height' => $image['image_height'], |
3016 ); |
3249 ); |
3017 } |
3250 } |
3018 } elseif ( ! empty( $data['comments']['picture'] ) ) { |
3251 } elseif ( ! empty( $data['comments']['picture'] ) ) { |
3019 $image = reset( $data['comments']['picture'] ); |
3252 $image = reset( $data['comments']['picture'] ); |
3020 if ( ! empty( $image['data'] ) ) { |
3253 if ( ! empty( $image['data'] ) ) { |
3021 $metadata['image'] = array( |
3254 $metadata['image'] = array( |
3022 'data' => $image['data'], |
3255 'data' => $image['data'], |
3023 'mime' => $image['image_mime'] |
3256 'mime' => $image['image_mime'], |
3024 ); |
3257 ); |
3025 } |
3258 } |
3026 } |
3259 } |
3027 } |
3260 } |
3028 |
3261 |
3046 } |
3279 } |
3047 |
3280 |
3048 if ( ! class_exists( 'getID3', false ) ) { |
3281 if ( ! class_exists( 'getID3', false ) ) { |
3049 require( ABSPATH . WPINC . '/ID3/getid3.php' ); |
3282 require( ABSPATH . WPINC . '/ID3/getid3.php' ); |
3050 } |
3283 } |
3051 $id3 = new getID3(); |
3284 $id3 = new getID3(); |
3052 $data = $id3->analyze( $file ); |
3285 $data = $id3->analyze( $file ); |
3053 |
3286 |
3054 if ( isset( $data['video']['lossless'] ) ) |
3287 if ( isset( $data['video']['lossless'] ) ) { |
3055 $metadata['lossless'] = $data['video']['lossless']; |
3288 $metadata['lossless'] = $data['video']['lossless']; |
3056 if ( ! empty( $data['video']['bitrate'] ) ) |
3289 } |
|
3290 if ( ! empty( $data['video']['bitrate'] ) ) { |
3057 $metadata['bitrate'] = (int) $data['video']['bitrate']; |
3291 $metadata['bitrate'] = (int) $data['video']['bitrate']; |
3058 if ( ! empty( $data['video']['bitrate_mode'] ) ) |
3292 } |
|
3293 if ( ! empty( $data['video']['bitrate_mode'] ) ) { |
3059 $metadata['bitrate_mode'] = $data['video']['bitrate_mode']; |
3294 $metadata['bitrate_mode'] = $data['video']['bitrate_mode']; |
3060 if ( ! empty( $data['filesize'] ) ) |
3295 } |
|
3296 if ( ! empty( $data['filesize'] ) ) { |
3061 $metadata['filesize'] = (int) $data['filesize']; |
3297 $metadata['filesize'] = (int) $data['filesize']; |
3062 if ( ! empty( $data['mime_type'] ) ) |
3298 } |
|
3299 if ( ! empty( $data['mime_type'] ) ) { |
3063 $metadata['mime_type'] = $data['mime_type']; |
3300 $metadata['mime_type'] = $data['mime_type']; |
3064 if ( ! empty( $data['playtime_seconds'] ) ) |
3301 } |
|
3302 if ( ! empty( $data['playtime_seconds'] ) ) { |
3065 $metadata['length'] = (int) round( $data['playtime_seconds'] ); |
3303 $metadata['length'] = (int) round( $data['playtime_seconds'] ); |
3066 if ( ! empty( $data['playtime_string'] ) ) |
3304 } |
|
3305 if ( ! empty( $data['playtime_string'] ) ) { |
3067 $metadata['length_formatted'] = $data['playtime_string']; |
3306 $metadata['length_formatted'] = $data['playtime_string']; |
3068 if ( ! empty( $data['video']['resolution_x'] ) ) |
3307 } |
|
3308 if ( ! empty( $data['video']['resolution_x'] ) ) { |
3069 $metadata['width'] = (int) $data['video']['resolution_x']; |
3309 $metadata['width'] = (int) $data['video']['resolution_x']; |
3070 if ( ! empty( $data['video']['resolution_y'] ) ) |
3310 } |
|
3311 if ( ! empty( $data['video']['resolution_y'] ) ) { |
3071 $metadata['height'] = (int) $data['video']['resolution_y']; |
3312 $metadata['height'] = (int) $data['video']['resolution_y']; |
3072 if ( ! empty( $data['fileformat'] ) ) |
3313 } |
|
3314 if ( ! empty( $data['fileformat'] ) ) { |
3073 $metadata['fileformat'] = $data['fileformat']; |
3315 $metadata['fileformat'] = $data['fileformat']; |
3074 if ( ! empty( $data['video']['dataformat'] ) ) |
3316 } |
|
3317 if ( ! empty( $data['video']['dataformat'] ) ) { |
3075 $metadata['dataformat'] = $data['video']['dataformat']; |
3318 $metadata['dataformat'] = $data['video']['dataformat']; |
3076 if ( ! empty( $data['video']['encoder'] ) ) |
3319 } |
|
3320 if ( ! empty( $data['video']['encoder'] ) ) { |
3077 $metadata['encoder'] = $data['video']['encoder']; |
3321 $metadata['encoder'] = $data['video']['encoder']; |
3078 if ( ! empty( $data['video']['codec'] ) ) |
3322 } |
|
3323 if ( ! empty( $data['video']['codec'] ) ) { |
3079 $metadata['codec'] = $data['video']['codec']; |
3324 $metadata['codec'] = $data['video']['codec']; |
|
3325 } |
3080 |
3326 |
3081 if ( ! empty( $data['audio'] ) ) { |
3327 if ( ! empty( $data['audio'] ) ) { |
3082 unset( $data['audio']['streams'] ); |
3328 unset( $data['audio']['streams'] ); |
3083 $metadata['audio'] = $data['audio']; |
3329 $metadata['audio'] = $data['audio']; |
3084 } |
3330 } |