243 */ |
246 */ |
244 return apply_filters( 'image_add_caption_shortcode', $shcode, $html ); |
247 return apply_filters( 'image_add_caption_shortcode', $shcode, $html ); |
245 } |
248 } |
246 |
249 |
247 /** |
250 /** |
248 * Private preg_replace callback used in image_add_caption() |
251 * Private preg_replace callback used in image_add_caption(). |
249 * |
252 * |
250 * @access private |
253 * @access private |
251 * @since 3.4.0 |
254 * @since 3.4.0 |
252 */ |
255 */ |
253 function _cleanup_image_add_caption( $matches ) { |
256 function _cleanup_image_add_caption( $matches ) { |
254 // Remove any line breaks from inside the tags. |
257 // Remove any line breaks from inside the tags. |
255 return preg_replace( '/[\r\n\t]+/', ' ', $matches[0] ); |
258 return preg_replace( '/[\r\n\t]+/', ' ', $matches[0] ); |
256 } |
259 } |
257 |
260 |
258 /** |
261 /** |
259 * Adds image html to editor |
262 * Adds image HTML to editor. |
260 * |
263 * |
261 * @since 2.5.0 |
264 * @since 2.5.0 |
262 * |
265 * |
263 * @param string $html |
266 * @param string $html |
264 */ |
267 */ |
265 function media_send_to_editor( $html ) { |
268 function media_send_to_editor( $html ) { |
266 ?> |
269 ?> |
267 <script type="text/javascript"> |
270 <script type="text/javascript"> |
268 var win = window.dialogArguments || opener || parent || top; |
271 var win = window.dialogArguments || opener || parent || top; |
269 win.send_to_editor( <?php echo wp_json_encode( $html ); ?> ); |
272 win.send_to_editor( <?php echo wp_json_encode( $html ); ?> ); |
270 </script> |
273 </script> |
271 <?php |
274 <?php |
272 exit; |
275 exit; |
273 } |
276 } |
274 |
277 |
275 /** |
278 /** |
276 * Save a file submitted from a POST request and create an attachment post for it. |
279 * Saves a file submitted from a POST request and create an attachment post for it. |
277 * |
280 * |
278 * @since 2.5.0 |
281 * @since 2.5.0 |
279 * |
282 * |
280 * @param string $file_id Index of the `$_FILES` array that the file was sent. Required. |
283 * @param string $file_id Index of the `$_FILES` array that the file was sent. Required. |
281 * @param int $post_id The post ID of a post to attach the media item to. Required, but can |
284 * @param int $post_id The post ID of a post to attach the media item to. Required, but can |
282 * be set to 0, creating a media item that has no relationship to a post. |
285 * be set to 0, creating a media item that has no relationship to a post. |
283 * @param array $post_data Overwrite some of the attachment. Optional. |
286 * @param array $post_data Optional. Overwrite some of the attachment. |
284 * @param array $overrides Override the wp_handle_upload() behavior. Optional. |
287 * @param array $overrides Optional. Override the wp_handle_upload() behavior. |
285 * @return int|WP_Error ID of the attachment or a WP_Error object on failure. |
288 * @return int|WP_Error ID of the attachment or a WP_Error object on failure. |
286 */ |
289 */ |
287 function media_handle_upload( $file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false ) ) { |
290 function media_handle_upload( $file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false ) ) { |
288 |
|
289 $time = current_time( 'mysql' ); |
291 $time = current_time( 'mysql' ); |
290 if ( $post = get_post( $post_id ) ) { |
292 $post = get_post( $post_id ); |
|
293 |
|
294 if ( $post ) { |
291 // The post date doesn't usually matter for pages, so don't backdate this upload. |
295 // The post date doesn't usually matter for pages, so don't backdate this upload. |
292 if ( 'page' !== $post->post_type && substr( $post->post_date, 0, 4 ) > 0 ) { |
296 if ( 'page' !== $post->post_type && substr( $post->post_date, 0, 4 ) > 0 ) { |
293 $time = $post->post_date; |
297 $time = $post->post_date; |
294 } |
298 } |
295 } |
299 } |
319 } |
323 } |
320 |
324 |
321 if ( ! empty( $title ) ) { |
325 if ( ! empty( $title ) ) { |
322 |
326 |
323 if ( ! empty( $meta['album'] ) && ! empty( $meta['artist'] ) ) { |
327 if ( ! empty( $meta['album'] ) && ! empty( $meta['artist'] ) ) { |
324 /* translators: 1: audio track title, 2: album title, 3: artist name */ |
328 /* translators: 1: Audio track title, 2: Album title, 3: Artist name. */ |
325 $content .= sprintf( __( '"%1$s" from %2$s by %3$s.' ), $title, $meta['album'], $meta['artist'] ); |
329 $content .= sprintf( __( '"%1$s" from %2$s by %3$s.' ), $title, $meta['album'], $meta['artist'] ); |
326 } elseif ( ! empty( $meta['album'] ) ) { |
330 } elseif ( ! empty( $meta['album'] ) ) { |
327 /* translators: 1: audio track title, 2: album title */ |
331 /* translators: 1: Audio track title, 2: Album title. */ |
328 $content .= sprintf( __( '"%1$s" from %2$s.' ), $title, $meta['album'] ); |
332 $content .= sprintf( __( '"%1$s" from %2$s.' ), $title, $meta['album'] ); |
329 } elseif ( ! empty( $meta['artist'] ) ) { |
333 } elseif ( ! empty( $meta['artist'] ) ) { |
330 /* translators: 1: audio track title, 2: artist name */ |
334 /* translators: 1: Audio track title, 2: Artist name. */ |
331 $content .= sprintf( __( '"%1$s" by %2$s.' ), $title, $meta['artist'] ); |
335 $content .= sprintf( __( '"%1$s" by %2$s.' ), $title, $meta['artist'] ); |
332 } else { |
336 } else { |
333 /* translators: 1: audio track title */ |
337 /* translators: %s: Audio track title. */ |
334 $content .= sprintf( __( '"%s".' ), $title ); |
338 $content .= sprintf( __( '"%s".' ), $title ); |
335 } |
339 } |
336 } elseif ( ! empty( $meta['album'] ) ) { |
340 } elseif ( ! empty( $meta['album'] ) ) { |
337 |
341 |
338 if ( ! empty( $meta['artist'] ) ) { |
342 if ( ! empty( $meta['artist'] ) ) { |
339 /* translators: 1: audio album title, 2: artist name */ |
343 /* translators: 1: Audio album title, 2: Artist name. */ |
340 $content .= sprintf( __( '%1$s by %2$s.' ), $meta['album'], $meta['artist'] ); |
344 $content .= sprintf( __( '%1$s by %2$s.' ), $meta['album'], $meta['artist'] ); |
341 } else { |
345 } else { |
342 $content .= $meta['album'] . '.'; |
346 $content .= $meta['album'] . '.'; |
343 } |
347 } |
344 } elseif ( ! empty( $meta['artist'] ) ) { |
348 } elseif ( ! empty( $meta['artist'] ) ) { |
346 $content .= $meta['artist'] . '.'; |
350 $content .= $meta['artist'] . '.'; |
347 |
351 |
348 } |
352 } |
349 |
353 |
350 if ( ! empty( $meta['year'] ) ) { |
354 if ( ! empty( $meta['year'] ) ) { |
351 /* translators: Audio file track information. %d: Year of audio track release */ |
355 /* translators: Audio file track information. %d: Year of audio track release. */ |
352 $content .= ' ' . sprintf( __( 'Released: %d.' ), $meta['year'] ); |
356 $content .= ' ' . sprintf( __( 'Released: %d.' ), $meta['year'] ); |
353 } |
357 } |
354 |
358 |
355 if ( ! empty( $meta['track_number'] ) ) { |
359 if ( ! empty( $meta['track_number'] ) ) { |
356 $track_number = explode( '/', $meta['track_number'] ); |
360 $track_number = explode( '/', $meta['track_number'] ); |
|
361 |
357 if ( isset( $track_number[1] ) ) { |
362 if ( isset( $track_number[1] ) ) { |
358 /* translators: Audio file track information. 1: Audio track number, 2: Total audio tracks */ |
363 /* translators: Audio file track information. 1: Audio track number, 2: Total audio tracks. */ |
359 $content .= ' ' . sprintf( __( 'Track %1$s of %2$s.' ), number_format_i18n( $track_number[0] ), number_format_i18n( $track_number[1] ) ); |
364 $content .= ' ' . sprintf( __( 'Track %1$s of %2$s.' ), number_format_i18n( $track_number[0] ), number_format_i18n( $track_number[1] ) ); |
360 } else { |
365 } else { |
361 /* translators: Audio file track information. %s: Audio track number */ |
366 /* translators: Audio file track information. %s: Audio track number. */ |
362 $content .= ' ' . sprintf( __( 'Track %s.' ), number_format_i18n( $track_number[0] ) ); |
367 $content .= ' ' . sprintf( __( 'Track %s.' ), number_format_i18n( $track_number[0] ) ); |
363 } |
368 } |
364 } |
369 } |
365 |
370 |
366 if ( ! empty( $meta['genre'] ) ) { |
371 if ( ! empty( $meta['genre'] ) ) { |
367 /* translators: Audio file genre information. %s: Audio genre name */ |
372 /* translators: Audio file genre information. %s: Audio genre name. */ |
368 $content .= ' ' . sprintf( __( 'Genre: %s.' ), $meta['genre'] ); |
373 $content .= ' ' . sprintf( __( 'Genre: %s.' ), $meta['genre'] ); |
369 } |
374 } |
370 |
375 |
371 // Use image exif/iptc data for title and caption defaults if possible. |
376 // Use image exif/iptc data for title and caption defaults if possible. |
372 } elseif ( 0 === strpos( $type, 'image/' ) && $image_meta = wp_read_image_metadata( $file ) ) { |
377 } elseif ( 0 === strpos( $type, 'image/' ) ) { |
373 if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) { |
378 $image_meta = wp_read_image_metadata( $file ); |
374 $title = $image_meta['title']; |
379 |
375 } |
380 if ( $image_meta ) { |
376 |
381 if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) { |
377 if ( trim( $image_meta['caption'] ) ) { |
382 $title = $image_meta['title']; |
378 $excerpt = $image_meta['caption']; |
383 } |
379 } |
384 |
380 } |
385 if ( trim( $image_meta['caption'] ) ) { |
381 |
386 $excerpt = $image_meta['caption']; |
382 // Construct the attachment array |
387 } |
|
388 } |
|
389 } |
|
390 |
|
391 // Construct the attachment array. |
383 $attachment = array_merge( |
392 $attachment = array_merge( |
384 array( |
393 array( |
385 'post_mime_type' => $type, |
394 'post_mime_type' => $type, |
386 'guid' => $url, |
395 'guid' => $url, |
387 'post_parent' => $post_id, |
396 'post_parent' => $post_id, |
393 ); |
402 ); |
394 |
403 |
395 // This should never be set as it would then overwrite an existing attachment. |
404 // This should never be set as it would then overwrite an existing attachment. |
396 unset( $attachment['ID'] ); |
405 unset( $attachment['ID'] ); |
397 |
406 |
398 // Save the data |
407 // Save the data. |
399 $id = wp_insert_attachment( $attachment, $file, $post_id, true ); |
408 $attachment_id = wp_insert_attachment( $attachment, $file, $post_id, true ); |
400 if ( ! is_wp_error( $id ) ) { |
409 |
401 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); |
410 if ( ! is_wp_error( $attachment_id ) ) { |
402 } |
411 // Set a custom header with the attachment_id. |
403 |
412 // Used by the browser/client to resume creating image sub-sizes after a PHP fatal error. |
404 return $id; |
413 if ( ! headers_sent() ) { |
405 |
414 header( 'X-WP-Upload-Attachment-ID: ' . $attachment_id ); |
|
415 } |
|
416 |
|
417 // The image sub-sizes are created during wp_generate_attachment_metadata(). |
|
418 // This is generally slow and may cause timeouts or out of memory errors. |
|
419 wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) ); |
|
420 } |
|
421 |
|
422 return $attachment_id; |
406 } |
423 } |
407 |
424 |
408 /** |
425 /** |
409 * Handles a side-loaded file in the same way as an uploaded file is handled by media_handle_upload(). |
426 * Handles a side-loaded file in the same way as an uploaded file is handled by media_handle_upload(). |
410 * |
427 * |
411 * @since 2.6.0 |
428 * @since 2.6.0 |
|
429 * @since 5.3.0 The `$post_id` parameter was made optional. |
412 * |
430 * |
413 * @param array $file_array Array similar to a `$_FILES` upload array. |
431 * @param array $file_array Array similar to a `$_FILES` upload array. |
414 * @param int $post_id The post ID the media is associated with. |
432 * @param int $post_id Optional. The post ID the media is associated with. |
415 * @param string $desc Optional. Description of the side-loaded file. Default null. |
433 * @param string $desc Optional. Description of the side-loaded file. Default null. |
416 * @param array $post_data Optional. Post data to override. Default empty array. |
434 * @param array $post_data Optional. Post data to override. Default empty array. |
417 * @return int|object The ID of the attachment or a WP_Error on failure. |
435 * @return int|WP_Error The ID of the attachment or a WP_Error on failure. |
418 */ |
436 */ |
419 function media_handle_sideload( $file_array, $post_id, $desc = null, $post_data = array() ) { |
437 function media_handle_sideload( $file_array, $post_id = 0, $desc = null, $post_data = array() ) { |
420 $overrides = array( 'test_form' => false ); |
438 $overrides = array( 'test_form' => false ); |
421 |
439 |
422 $time = current_time( 'mysql' ); |
440 $time = current_time( 'mysql' ); |
423 if ( $post = get_post( $post_id ) ) { |
441 $post = get_post( $post_id ); |
|
442 |
|
443 if ( $post ) { |
424 if ( substr( $post->post_date, 0, 4 ) > 0 ) { |
444 if ( substr( $post->post_date, 0, 4 ) > 0 ) { |
425 $time = $post->post_date; |
445 $time = $post->post_date; |
426 } |
446 } |
427 } |
447 } |
428 |
448 |
429 $file = wp_handle_sideload( $file_array, $overrides, $time ); |
449 $file = wp_handle_sideload( $file_array, $overrides, $time ); |
|
450 |
430 if ( isset( $file['error'] ) ) { |
451 if ( isset( $file['error'] ) ) { |
431 return new WP_Error( 'upload_error', $file['error'] ); |
452 return new WP_Error( 'upload_error', $file['error'] ); |
432 } |
453 } |
433 |
454 |
434 $url = $file['url']; |
455 $url = $file['url']; |
464 ); |
488 ); |
465 |
489 |
466 // This should never be set as it would then overwrite an existing attachment. |
490 // This should never be set as it would then overwrite an existing attachment. |
467 unset( $attachment['ID'] ); |
491 unset( $attachment['ID'] ); |
468 |
492 |
469 // Save the attachment metadata |
493 // Save the attachment metadata. |
470 $id = wp_insert_attachment( $attachment, $file, $post_id, true ); |
494 $attachment_id = wp_insert_attachment( $attachment, $file, $post_id, true ); |
471 if ( ! is_wp_error( $id ) ) { |
495 |
472 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); |
496 if ( ! is_wp_error( $attachment_id ) ) { |
473 } |
497 wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) ); |
474 |
498 } |
475 return $id; |
499 |
476 } |
500 return $attachment_id; |
477 |
501 } |
478 /** |
502 |
479 * Adds the iframe to display content for the media upload page |
503 /** |
|
504 * Outputs the iframe to display the media upload page. |
480 * |
505 * |
481 * @since 2.5.0 |
506 * @since 2.5.0 |
|
507 * @since 5.3.0 Formalized the existing and already documented `...$args` parameter |
|
508 * by adding it to the function signature. |
482 * |
509 * |
483 * @global int $body_id |
510 * @global int $body_id |
484 * |
511 * |
485 * @param string|callable $content_func |
512 * @param callable $content_func Function that outputs the content. |
486 */ |
513 * @param mixed ...$args Optional additional parameters to pass to the callback function when it's called. |
487 function wp_iframe( $content_func /* ... */ ) { |
514 */ |
|
515 function wp_iframe( $content_func, ...$args ) { |
488 _wp_admin_html_begin(); |
516 _wp_admin_html_begin(); |
489 ?> |
517 ?> |
490 <title><?php bloginfo( 'name' ); ?> › <?php _e( 'Uploads' ); ?> — <?php _e( 'WordPress' ); ?></title> |
518 <title><?php bloginfo( 'name' ); ?> › <?php _e( 'Uploads' ); ?> — <?php _e( 'WordPress' ); ?></title> |
491 <?php |
519 <?php |
492 |
520 |
493 wp_enqueue_style( 'colors' ); |
521 wp_enqueue_style( 'colors' ); |
494 // Check callback name for 'media' |
522 // Check callback name for 'media'. |
495 if ( ( is_array( $content_func ) && ! empty( $content_func[1] ) && 0 === strpos( (string) $content_func[1], 'media' ) ) |
523 if ( |
496 || ( ! is_array( $content_func ) && 0 === strpos( $content_func, 'media' ) ) ) { |
524 ( is_array( $content_func ) && ! empty( $content_func[1] ) && 0 === strpos( (string) $content_func[1], 'media' ) ) || |
|
525 ( ! is_array( $content_func ) && 0 === strpos( $content_func, 'media' ) ) |
|
526 ) { |
497 wp_enqueue_style( 'deprecated-media' ); |
527 wp_enqueue_style( 'deprecated-media' ); |
498 } |
528 } |
499 wp_enqueue_style( 'ie' ); |
529 |
500 ?> |
530 ?> |
501 <script type="text/javascript"> |
531 <script type="text/javascript"> |
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();}}}; |
532 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();}}}; |
503 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup', |
533 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup', |
504 isRtl = <?php echo (int) is_rtl(); ?>; |
534 isRtl = <?php echo (int) is_rtl(); ?>; |
505 </script> |
535 </script> |
506 <?php |
536 <?php |
507 /** This action is documented in wp-admin/admin-header.php */ |
537 /** This action is documented in wp-admin/admin-header.php */ |
508 do_action( 'admin_enqueue_scripts', 'media-upload-popup' ); |
538 do_action( 'admin_enqueue_scripts', 'media-upload-popup' ); |
509 |
539 |
510 /** |
540 /** |
511 * Fires when admin styles enqueued for the legacy (pre-3.5.0) media upload popup are printed. |
541 * Fires when admin styles enqueued for the legacy (pre-3.5.0) media upload popup are printed. |
512 * |
542 * |
513 * @since 2.9.0 |
543 * @since 2.9.0 |
514 */ |
544 */ |
515 do_action( 'admin_print_styles-media-upload-popup' ); |
545 do_action( 'admin_print_styles-media-upload-popup' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
516 |
546 |
517 /** This action is documented in wp-admin/admin-header.php */ |
547 /** This action is documented in wp-admin/admin-header.php */ |
518 do_action( 'admin_print_styles' ); |
548 do_action( 'admin_print_styles' ); |
519 |
549 |
520 /** |
550 /** |
521 * Fires when admin scripts enqueued for the legacy (pre-3.5.0) media upload popup are printed. |
551 * Fires when admin scripts enqueued for the legacy (pre-3.5.0) media upload popup are printed. |
522 * |
552 * |
523 * @since 2.9.0 |
553 * @since 2.9.0 |
524 */ |
554 */ |
525 do_action( 'admin_print_scripts-media-upload-popup' ); |
555 do_action( 'admin_print_scripts-media-upload-popup' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
526 |
556 |
527 /** This action is documented in wp-admin/admin-header.php */ |
557 /** This action is documented in wp-admin/admin-header.php */ |
528 do_action( 'admin_print_scripts' ); |
558 do_action( 'admin_print_scripts' ); |
529 |
559 |
530 /** |
560 /** |
531 * Fires when scripts enqueued for the admin header for the legacy (pre-3.5.0) |
561 * Fires when scripts enqueued for the admin header for the legacy (pre-3.5.0) |
532 * media upload popup are printed. |
562 * media upload popup are printed. |
533 * |
563 * |
534 * @since 2.9.0 |
564 * @since 2.9.0 |
535 */ |
565 */ |
536 do_action( 'admin_head-media-upload-popup' ); |
566 do_action( 'admin_head-media-upload-popup' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
537 |
567 |
538 /** This action is documented in wp-admin/admin-header.php */ |
568 /** This action is documented in wp-admin/admin-header.php */ |
539 do_action( 'admin_head' ); |
569 do_action( 'admin_head' ); |
540 |
570 |
541 if ( is_string( $content_func ) ) { |
571 if ( is_string( $content_func ) ) { |
552 */ |
582 */ |
553 do_action( "admin_head_{$content_func}" ); |
583 do_action( "admin_head_{$content_func}" ); |
554 } |
584 } |
555 |
585 |
556 $body_id_attr = ''; |
586 $body_id_attr = ''; |
|
587 |
557 if ( isset( $GLOBALS['body_id'] ) ) { |
588 if ( isset( $GLOBALS['body_id'] ) ) { |
558 $body_id_attr = ' id="' . $GLOBALS['body_id'] . '"'; |
589 $body_id_attr = ' id="' . $GLOBALS['body_id'] . '"'; |
559 } |
590 } |
|
591 |
560 ?> |
592 ?> |
561 </head> |
593 </head> |
562 <body<?php echo $body_id_attr; ?> class="wp-core-ui no-js"> |
594 <body<?php echo $body_id_attr; ?> class="wp-core-ui no-js"> |
563 <script type="text/javascript"> |
595 <script type="text/javascript"> |
564 document.body.className = document.body.className.replace('no-js', 'js'); |
596 document.body.className = document.body.className.replace('no-js', 'js'); |
565 </script> |
597 </script> |
566 <?php |
598 <?php |
567 $args = func_get_args(); |
599 |
568 $args = array_slice( $args, 1 ); |
|
569 call_user_func_array( $content_func, $args ); |
600 call_user_func_array( $content_func, $args ); |
570 |
601 |
571 /** This action is documented in wp-admin/admin-footer.php */ |
602 /** This action is documented in wp-admin/admin-footer.php */ |
572 do_action( 'admin_print_footer_scripts' ); |
603 do_action( 'admin_print_footer_scripts' ); |
|
604 |
573 ?> |
605 ?> |
574 <script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script> |
606 <script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script> |
575 </body> |
607 </body> |
576 </html> |
608 </html> |
577 <?php |
609 <?php |
578 } |
610 } |
579 |
611 |
580 /** |
612 /** |
581 * Adds the media button to the editor |
613 * Adds the media button to the editor |
582 * |
614 * |
583 * @since 2.5.0 |
615 * @since 2.5.0 |
584 * |
616 * |
585 * @global int $post_ID |
617 * @global int $post_ID |
586 * |
|
587 * @staticvar int $instance |
|
588 * |
618 * |
589 * @param string $editor_id |
619 * @param string $editor_id |
590 */ |
620 */ |
591 function media_buttons( $editor_id = 'content' ) { |
621 function media_buttons( $editor_id = 'content' ) { |
592 static $instance = 0; |
622 static $instance = 0; |
593 $instance++; |
623 $instance++; |
594 |
624 |
595 $post = get_post(); |
625 $post = get_post(); |
|
626 |
596 if ( ! $post && ! empty( $GLOBALS['post_ID'] ) ) { |
627 if ( ! $post && ! empty( $GLOBALS['post_ID'] ) ) { |
597 $post = $GLOBALS['post_ID']; |
628 $post = $GLOBALS['post_ID']; |
598 } |
629 } |
599 |
630 |
600 wp_enqueue_media( |
631 wp_enqueue_media( array( 'post' => $post ) ); |
601 array( |
|
602 'post' => $post, |
|
603 ) |
|
604 ); |
|
605 |
632 |
606 $img = '<span class="wp-media-buttons-icon"></span> '; |
633 $img = '<span class="wp-media-buttons-icon"></span> '; |
607 |
634 |
608 $id_attribute = $instance === 1 ? ' id="insert-media-button"' : ''; |
635 $id_attribute = 1 === $instance ? ' id="insert-media-button"' : ''; |
|
636 |
609 printf( |
637 printf( |
610 '<button type="button"%s class="button insert-media add_media" data-editor="%s">%s</button>', |
638 '<button type="button"%s class="button insert-media add_media" data-editor="%s">%s</button>', |
611 $id_attribute, |
639 $id_attribute, |
612 esc_attr( $editor_id ), |
640 esc_attr( $editor_id ), |
613 $img . __( 'Add Media' ) |
641 $img . __( 'Add Media' ) |
614 ); |
642 ); |
|
643 |
615 /** |
644 /** |
616 * Filters the legacy (pre-3.5.0) media buttons. |
645 * Filters the legacy (pre-3.5.0) media buttons. |
617 * |
646 * |
618 * Use {@see 'media_buttons'} action instead. |
647 * Use {@see 'media_buttons'} action instead. |
619 * |
648 * |
620 * @since 2.5.0 |
649 * @since 2.5.0 |
621 * @deprecated 3.5.0 Use {@see 'media_buttons'} action instead. |
650 * @deprecated 3.5.0 Use {@see 'media_buttons'} action instead. |
622 * |
651 * |
623 * @param string $string Media buttons context. Default empty. |
652 * @param string $string Media buttons context. Default empty. |
624 */ |
653 */ |
625 $legacy_filter = apply_filters( 'media_buttons_context', '' ); |
654 $legacy_filter = apply_filters_deprecated( 'media_buttons_context', array( '' ), '3.5.0', 'media_buttons' ); |
626 |
655 |
627 if ( $legacy_filter ) { |
656 if ( $legacy_filter ) { |
628 // #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag. |
657 // #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag. |
629 if ( 0 === stripos( trim( $legacy_filter ), '</a>' ) ) { |
658 if ( 0 === stripos( trim( $legacy_filter ), '</a>' ) ) { |
630 $legacy_filter .= '</a>'; |
659 $legacy_filter .= '</a>'; |
806 $errors = array(); |
844 $errors = array(); |
807 $id = 0; |
845 $id = 0; |
808 |
846 |
809 if ( isset( $_POST['html-upload'] ) && ! empty( $_FILES ) ) { |
847 if ( isset( $_POST['html-upload'] ) && ! empty( $_FILES ) ) { |
810 check_admin_referer( 'media-form' ); |
848 check_admin_referer( 'media-form' ); |
811 // Upload File button was clicked |
849 // Upload File button was clicked. |
812 $id = media_handle_upload( 'async-upload', $_REQUEST['post_id'] ); |
850 $id = media_handle_upload( 'async-upload', $_REQUEST['post_id'] ); |
813 unset( $_FILES ); |
851 unset( $_FILES ); |
|
852 |
814 if ( is_wp_error( $id ) ) { |
853 if ( is_wp_error( $id ) ) { |
815 $errors['upload_error'] = $id; |
854 $errors['upload_error'] = $id; |
816 $id = false; |
855 $id = false; |
817 } |
856 } |
818 } |
857 } |
819 |
858 |
820 if ( ! empty( $_POST['insertonlybutton'] ) ) { |
859 if ( ! empty( $_POST['insertonlybutton'] ) ) { |
821 $src = $_POST['src']; |
860 $src = $_POST['src']; |
|
861 |
822 if ( ! empty( $src ) && ! strpos( $src, '://' ) ) { |
862 if ( ! empty( $src ) && ! strpos( $src, '://' ) ) { |
823 $src = "http://$src"; |
863 $src = "http://$src"; |
824 } |
864 } |
825 |
865 |
826 if ( isset( $_POST['media_type'] ) && 'image' != $_POST['media_type'] ) { |
866 if ( isset( $_POST['media_type'] ) && 'image' !== $_POST['media_type'] ) { |
827 $title = esc_html( wp_unslash( $_POST['title'] ) ); |
867 $title = esc_html( wp_unslash( $_POST['title'] ) ); |
828 if ( empty( $title ) ) { |
868 if ( empty( $title ) ) { |
829 $title = esc_html( wp_basename( $src ) ); |
869 $title = esc_html( wp_basename( $src ) ); |
830 } |
870 } |
831 |
871 |
832 if ( $title && $src ) { |
872 if ( $title && $src ) { |
833 $html = "<a href='" . esc_url( $src ) . "'>$title</a>"; |
873 $html = "<a href='" . esc_url( $src ) . "'>$title</a>"; |
834 } |
874 } |
835 |
875 |
836 $type = 'file'; |
876 $type = 'file'; |
837 if ( ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) ) && ( $ext_type = wp_ext2type( $ext ) ) |
877 $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ); |
838 && ( 'audio' == $ext_type || 'video' == $ext_type ) ) { |
878 |
|
879 if ( $ext ) { |
|
880 $ext_type = wp_ext2type( $ext ); |
|
881 if ( 'audio' === $ext_type || 'video' === $ext_type ) { |
839 $type = $ext_type; |
882 $type = $ext_type; |
|
883 } |
840 } |
884 } |
841 |
885 |
842 /** |
886 /** |
843 * Filters the URL sent to the editor for a specific media type. |
887 * Filters the URL sent to the editor for a specific media type. |
844 * |
888 * |
911 * Downloads an image from the specified URL and attaches it to a post. |
961 * Downloads an image from the specified URL and attaches it to a post. |
912 * |
962 * |
913 * @since 2.6.0 |
963 * @since 2.6.0 |
914 * @since 4.2.0 Introduced the `$return` parameter. |
964 * @since 4.2.0 Introduced the `$return` parameter. |
915 * @since 4.8.0 Introduced the 'id' option within the `$return` parameter. |
965 * @since 4.8.0 Introduced the 'id' option within the `$return` parameter. |
|
966 * @since 5.3.0 The `$post_id` parameter was made optional. |
|
967 * @since 5.4.0 The original URL of the attachment is stored in the `_source_url` |
|
968 * post meta value. |
916 * |
969 * |
917 * @param string $file The URL of the image to download. |
970 * @param string $file The URL of the image to download. |
918 * @param int $post_id The post ID the media is to be associated with. |
971 * @param int $post_id Optional. The post ID the media is to be associated with. |
919 * @param string $desc Optional. Description of the image. |
972 * @param string $desc Optional. Description of the image. |
920 * @param string $return Optional. Accepts 'html' (image tag html) or 'src' (URL), or 'id' (attachment ID). Default 'html'. |
973 * @param string $return Optional. Accepts 'html' (image tag html) or 'src' (URL), |
|
974 * or 'id' (attachment ID). Default 'html'. |
921 * @return string|WP_Error Populated HTML img tag on success, WP_Error object otherwise. |
975 * @return string|WP_Error Populated HTML img tag on success, WP_Error object otherwise. |
922 */ |
976 */ |
923 function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) { |
977 function media_sideload_image( $file, $post_id = 0, $desc = null, $return = 'html' ) { |
924 if ( ! empty( $file ) ) { |
978 if ( ! empty( $file ) ) { |
925 |
979 |
926 // Set variables for storage, fix file filename for query strings. |
980 // Set variables for storage, fix file filename for query strings. |
927 preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches ); |
981 preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches ); |
|
982 |
928 if ( ! $matches ) { |
983 if ( ! $matches ) { |
929 return new WP_Error( 'image_sideload_failed', __( 'Invalid image URL' ) ); |
984 return new WP_Error( 'image_sideload_failed', __( 'Invalid image URL.' ) ); |
930 } |
985 } |
931 |
986 |
932 $file_array = array(); |
987 $file_array = array(); |
933 $file_array['name'] = wp_basename( $matches[0] ); |
988 $file_array['name'] = wp_basename( $matches[0] ); |
934 |
989 |
1036 'none' => __( 'None' ), |
1099 'none' => __( 'None' ), |
1037 'left' => __( 'Left' ), |
1100 'left' => __( 'Left' ), |
1038 'center' => __( 'Center' ), |
1101 'center' => __( 'Center' ), |
1039 'right' => __( 'Right' ), |
1102 'right' => __( 'Right' ), |
1040 ); |
1103 ); |
|
1104 |
1041 if ( ! array_key_exists( (string) $checked, $alignments ) ) { |
1105 if ( ! array_key_exists( (string) $checked, $alignments ) ) { |
1042 $checked = 'none'; |
1106 $checked = 'none'; |
1043 } |
1107 } |
1044 |
1108 |
1045 $out = array(); |
1109 $out = array(); |
|
1110 |
1046 foreach ( $alignments as $name => $label ) { |
1111 foreach ( $alignments as $name => $label ) { |
1047 $name = esc_attr( $name ); |
1112 $name = esc_attr( $name ); |
1048 $out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'" . |
1113 $out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'" . |
1049 ( $checked == $name ? " checked='checked'" : '' ) . |
1114 ( $checked == $name ? " checked='checked'" : '' ) . |
1050 " /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>$label</label>"; |
1115 " /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>$label</label>"; |
1051 } |
1116 } |
|
1117 |
1052 return join( "\n", $out ); |
1118 return join( "\n", $out ); |
1053 } |
1119 } |
1054 |
1120 |
1055 /** |
1121 /** |
1056 * Retrieve HTML for the size radio buttons with the specified one checked. |
1122 * Retrieve HTML for the size radio buttons with the specified one checked. |
1057 * |
1123 * |
1058 * @since 2.7.0 |
1124 * @since 2.7.0 |
1059 * |
1125 * |
1060 * @param WP_Post $post |
1126 * @param WP_Post $post |
1061 * @param bool|string $check |
1127 * @param bool|string $check |
1062 * @return array |
1128 * @return array |
1063 */ |
1129 */ |
1064 function image_size_input_fields( $post, $check = '' ) { |
1130 function image_size_input_fields( $post, $check = '' ) { |
1065 /** |
1131 /** |
1066 * Filters the names and labels of the default image sizes. |
1132 * Filters the names and labels of the default image sizes. |
1067 * |
1133 * |
1068 * @since 3.3.0 |
1134 * @since 3.3.0 |
1069 * |
1135 * |
1070 * @param array $size_names Array of image sizes and their names. Default values |
1136 * @param string[] $size_names Array of image size labels keyed by their name. Default values |
1071 * include 'Thumbnail', 'Medium', 'Large', 'Full Size'. |
1137 * include 'Thumbnail', 'Medium', 'Large', and 'Full Size'. |
1072 */ |
1138 */ |
1073 $size_names = apply_filters( |
1139 $size_names = apply_filters( |
1074 'image_size_names_choose', |
1140 'image_size_names_choose', |
1075 array( |
1141 array( |
1076 'thumbnail' => __( 'Thumbnail' ), |
1142 'thumbnail' => __( 'Thumbnail' ), |
1324 ), |
1394 ), |
1325 ); |
1395 ); |
1326 |
1396 |
1327 foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) { |
1397 foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) { |
1328 $t = (array) get_taxonomy( $taxonomy ); |
1398 $t = (array) get_taxonomy( $taxonomy ); |
|
1399 |
1329 if ( ! $t['public'] || ! $t['show_ui'] ) { |
1400 if ( ! $t['public'] || ! $t['show_ui'] ) { |
1330 continue; |
1401 continue; |
1331 } |
1402 } |
|
1403 |
1332 if ( empty( $t['label'] ) ) { |
1404 if ( empty( $t['label'] ) ) { |
1333 $t['label'] = $taxonomy; |
1405 $t['label'] = $taxonomy; |
1334 } |
1406 } |
|
1407 |
1335 if ( empty( $t['args'] ) ) { |
1408 if ( empty( $t['args'] ) ) { |
1336 $t['args'] = array(); |
1409 $t['args'] = array(); |
1337 } |
1410 } |
1338 |
1411 |
1339 $terms = get_object_term_cache( $post->ID, $taxonomy ); |
1412 $terms = get_object_term_cache( $post->ID, $taxonomy ); |
|
1413 |
1340 if ( false === $terms ) { |
1414 if ( false === $terms ) { |
1341 $terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] ); |
1415 $terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] ); |
1342 } |
1416 } |
1343 |
1417 |
1344 $values = array(); |
1418 $values = array(); |
1345 |
1419 |
1346 foreach ( $terms as $term ) { |
1420 foreach ( $terms as $term ) { |
1347 $values[] = $term->slug; |
1421 $values[] = $term->slug; |
1348 } |
1422 } |
|
1423 |
1349 $t['value'] = join( ', ', $values ); |
1424 $t['value'] = join( ', ', $values ); |
1350 |
1425 |
1351 $form_fields[ $taxonomy ] = $t; |
1426 $form_fields[ $taxonomy ] = $t; |
1352 } |
1427 } |
1353 |
1428 |
1354 // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default |
1429 /* |
1355 // The recursive merge is easily traversed with array casting: foreach ( (array) $things as $thing ) |
1430 * Merge default fields with their errors, so any key passed with the error |
|
1431 * (e.g. 'error', 'helps', 'value') will replace the default. |
|
1432 * The recursive merge is easily traversed with array casting: |
|
1433 * foreach ( (array) $things as $thing ) |
|
1434 */ |
1356 $form_fields = array_merge_recursive( $form_fields, (array) $errors ); |
1435 $form_fields = array_merge_recursive( $form_fields, (array) $errors ); |
1357 |
1436 |
1358 // This was formerly in image_attachment_fields_to_edit(). |
1437 // This was formerly in image_attachment_fields_to_edit(). |
1359 if ( substr( $post->post_mime_type, 0, 5 ) == 'image' ) { |
1438 if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) { |
1360 $alt = get_post_meta( $post->ID, '_wp_attachment_image_alt', true ); |
1439 $alt = get_post_meta( $post->ID, '_wp_attachment_image_alt', true ); |
|
1440 |
1361 if ( empty( $alt ) ) { |
1441 if ( empty( $alt ) ) { |
1362 $alt = ''; |
1442 $alt = ''; |
1363 } |
1443 } |
1364 |
1444 |
1365 $form_fields['post_title']['required'] = true; |
1445 $form_fields['post_title']['required'] = true; |
1500 $post_mime_types = get_post_mime_types(); |
1591 $post_mime_types = get_post_mime_types(); |
1501 $keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) ); |
1592 $keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) ); |
1502 $type = reset( $keys ); |
1593 $type = reset( $keys ); |
1503 $type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />"; |
1594 $type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />"; |
1504 |
1595 |
1505 $form_fields = get_attachment_fields_to_edit( $post, $r['errors'] ); |
1596 $form_fields = get_attachment_fields_to_edit( $post, $parsed_args['errors'] ); |
1506 |
1597 |
1507 if ( $r['toggle'] ) { |
1598 if ( $parsed_args['toggle'] ) { |
1508 $class = empty( $r['errors'] ) ? 'startclosed' : 'startopen'; |
1599 $class = empty( $parsed_args['errors'] ) ? 'startclosed' : 'startopen'; |
1509 $toggle_links = " |
1600 $toggle_links = " |
1510 <a class='toggle describe-toggle-on' href='#'>$toggle_on</a> |
1601 <a class='toggle describe-toggle-on' href='#'>$toggle_on</a> |
1511 <a class='toggle describe-toggle-off' href='#'>$toggle_off</a>"; |
1602 <a class='toggle describe-toggle-off' href='#'>$toggle_off</a>"; |
1512 } else { |
1603 } else { |
1513 $class = ''; |
1604 $class = ''; |
1514 $toggle_links = ''; |
1605 $toggle_links = ''; |
1515 } |
1606 } |
1516 |
1607 |
1517 $display_title = ( ! empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case |
1608 $display_title = ( ! empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case. |
1518 $display_title = $r['show_title'] ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60, '…' ) . '</span></div>' : ''; |
1609 $display_title = $parsed_args['show_title'] ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60, '…' ) . '</span></div>' : ''; |
1519 |
1610 |
1520 $gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' == $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' == $redir_tab ) ); |
1611 $gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' === $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' === $redir_tab ) ); |
1521 $order = ''; |
1612 $order = ''; |
1522 |
1613 |
1523 foreach ( $form_fields as $key => $val ) { |
1614 foreach ( $form_fields as $key => $val ) { |
1524 if ( 'menu_order' == $key ) { |
1615 if ( 'menu_order' === $key ) { |
1525 if ( $gallery ) { |
1616 if ( $gallery ) { |
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>"; |
1617 $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>"; |
1527 } else { |
1618 } else { |
1528 $order = "<input type='hidden' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' />"; |
1619 $order = "<input type='hidden' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' />"; |
1529 } |
1620 } |
1548 * @param WP_Post $post The WP_Post attachment object. |
1640 * @param WP_Post $post The WP_Post attachment object. |
1549 */ |
1641 */ |
1550 $media_dims = apply_filters( 'media_meta', $media_dims, $post ); |
1642 $media_dims = apply_filters( 'media_meta', $media_dims, $post ); |
1551 |
1643 |
1552 $image_edit_button = ''; |
1644 $image_edit_button = ''; |
|
1645 |
1553 if ( wp_attachment_is_image( $post->ID ) && wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { |
1646 if ( wp_attachment_is_image( $post->ID ) && wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { |
1554 $nonce = wp_create_nonce( "image_editor-$post->ID" ); |
1647 $nonce = wp_create_nonce( "image_editor-$post->ID" ); |
1555 $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>"; |
1648 $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>"; |
1556 } |
1649 } |
1557 |
1650 |
1558 $attachment_url = get_permalink( $attachment_id ); |
1651 $attachment_url = get_permalink( $attachment_id ); |
1559 |
1652 |
1560 $item = " |
1653 $item = " |
1561 $type_html |
1654 $type_html |
1562 $toggle_links |
1655 $toggle_links |
1563 $order |
1656 $order |
1564 $display_title |
1657 $display_title |
1565 <table class='slidetoggle describe $class'> |
1658 <table class='slidetoggle describe $class'> |
1566 <thead class='media-item-info' id='media-head-$post->ID'> |
1659 <thead class='media-item-info' id='media-head-$post->ID'> |
1567 <tr> |
1660 <tr> |
1568 <td class='A1B1' id='thumbnail-head-$post->ID'> |
1661 <td class='A1B1' id='thumbnail-head-$post->ID'> |
1569 <p><a href='$attachment_url' target='_blank'><img class='thumbnail' src='$thumb_url' alt='' /></a></p> |
1662 <p><a href='$attachment_url' target='_blank'><img class='thumbnail' src='$thumb_url' alt='' /></a></p> |
1570 <p>$image_edit_button</p> |
1663 <p>$image_edit_button</p> |
1571 </td> |
1664 </td> |
1572 <td> |
1665 <td> |
1573 <p><strong>" . __( 'File name:' ) . "</strong> $filename</p> |
1666 <p><strong>" . __( 'File name:' ) . "</strong> $filename</p> |
1574 <p><strong>" . __( 'File type:' ) . "</strong> $post->post_mime_type</p> |
1667 <p><strong>" . __( 'File type:' ) . "</strong> $post->post_mime_type</p> |
1575 <p><strong>" . __( 'Upload date:' ) . '</strong> ' . mysql2date( __( 'F j, Y' ), $post->post_date ) . '</p>'; |
1668 <p><strong>" . __( 'Upload date:' ) . '</strong> ' . mysql2date( __( 'F j, Y' ), $post->post_date ) . '</p>'; |
|
1669 |
1576 if ( ! empty( $media_dims ) ) { |
1670 if ( ! empty( $media_dims ) ) { |
1577 $item .= '<p><strong>' . __( 'Dimensions:' ) . "</strong> $media_dims</p>\n"; |
1671 $item .= '<p><strong>' . __( 'Dimensions:' ) . "</strong> $media_dims</p>\n"; |
1578 } |
1672 } |
1579 |
1673 |
1580 $item .= "</td></tr>\n"; |
1674 $item .= "</td></tr>\n"; |
1581 |
1675 |
1582 $item .= " |
1676 $item .= " |
1583 </thead> |
1677 </thead> |
1584 <tbody> |
1678 <tbody> |
1585 <tr><td colspan='2' class='imgedit-response' id='imgedit-response-$post->ID'></td></tr>\n |
1679 <tr><td colspan='2' class='imgedit-response' id='imgedit-response-$post->ID'></td></tr>\n |
1586 <tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-$post->ID'></td></tr>\n |
1680 <tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-$post->ID'></td></tr>\n |
1587 <tr><td colspan='2'><p class='media-types media-types-required-info'>" . sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) . "</p></td></tr>\n"; |
1681 <tr><td colspan='2'><p class='media-types media-types-required-info'>" . |
|
1682 /* translators: %s: Asterisk symbol (*). */ |
|
1683 sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) . |
|
1684 "</p></td></tr>\n"; |
1588 |
1685 |
1589 $defaults = array( |
1686 $defaults = array( |
1590 'input' => 'text', |
1687 'input' => 'text', |
1591 'required' => false, |
1688 'required' => false, |
1592 'value' => '', |
1689 'value' => '', |
1593 'extra_rows' => array(), |
1690 'extra_rows' => array(), |
1594 ); |
1691 ); |
1595 |
1692 |
1596 if ( $r['send'] ) { |
1693 if ( $parsed_args['send'] ) { |
1597 $r['send'] = get_submit_button( __( 'Insert into Post' ), '', "send[$attachment_id]", false ); |
1694 $parsed_args['send'] = get_submit_button( __( 'Insert into Post' ), '', "send[$attachment_id]", false ); |
1598 } |
1695 } |
1599 |
1696 |
1600 $delete = empty( $r['delete'] ) ? '' : $r['delete']; |
1697 $delete = empty( $parsed_args['delete'] ) ? '' : $parsed_args['delete']; |
1601 if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) { |
1698 if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) { |
1602 if ( ! EMPTY_TRASH_DAYS ) { |
1699 if ( ! EMPTY_TRASH_DAYS ) { |
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>'; |
1700 $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>'; |
1604 } elseif ( ! MEDIA_TRASH ) { |
1701 } elseif ( ! MEDIA_TRASH ) { |
1605 $delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete' ) . "</a> |
1702 $delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete' ) . "</a> |
1606 <div id='del_attachment_$attachment_id' class='del-attachment' style='display:none;'>" . |
1703 <div id='del_attachment_$attachment_id' class='del-attachment' style='display:none;'>" . |
1607 /* translators: %s: file name */ |
1704 /* translators: %s: File name. */ |
1608 '<p>' . sprintf( __( 'You are about to delete %s.' ), '<strong>' . $filename . '</strong>' ) . "</p> |
1705 '<p>' . sprintf( __( 'You are about to delete %s.' ), '<strong>' . $filename . '</strong>' ) . "</p> |
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> |
1706 <a href='" . wp_nonce_url( "post.php?action=delete&post=$attachment_id", 'delete-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='button'>" . __( 'Continue' ) . "</a> |
1610 <a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __( 'Cancel' ) . '</a> |
1707 <a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __( 'Cancel' ) . '</a> |
1611 </div>'; |
1708 </div>'; |
1612 } else { |
1709 } else { |
1617 $delete = ''; |
1714 $delete = ''; |
1618 } |
1715 } |
1619 |
1716 |
1620 $thumbnail = ''; |
1717 $thumbnail = ''; |
1621 $calling_post_id = 0; |
1718 $calling_post_id = 0; |
|
1719 |
1622 if ( isset( $_GET['post_id'] ) ) { |
1720 if ( isset( $_GET['post_id'] ) ) { |
1623 $calling_post_id = absint( $_GET['post_id'] ); |
1721 $calling_post_id = absint( $_GET['post_id'] ); |
1624 } elseif ( isset( $_POST ) && count( $_POST ) ) {// Like for async-upload where $_GET['post_id'] isn't set |
1722 } elseif ( isset( $_POST ) && count( $_POST ) ) {// Like for async-upload where $_GET['post_id'] isn't set. |
1625 $calling_post_id = $post->post_parent; |
1723 $calling_post_id = $post->post_parent; |
1626 } |
1724 } |
1627 if ( 'image' == $type && $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) ) |
1725 |
1628 && post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id ) { |
1726 if ( 'image' === $type && $calling_post_id |
|
1727 && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) ) |
|
1728 && post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' ) |
|
1729 && get_post_thumbnail_id( $calling_post_id ) != $attachment_id |
|
1730 ) { |
1629 |
1731 |
1630 $calling_post = get_post( $calling_post_id ); |
1732 $calling_post = get_post( $calling_post_id ); |
1631 $calling_post_type_object = get_post_type_object( $calling_post->post_type ); |
1733 $calling_post_type_object = get_post_type_object( $calling_post->post_type ); |
1632 |
1734 |
1633 $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" ); |
1735 $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" ); |
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>'; |
1736 $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>'; |
1635 } |
1737 } |
1636 |
1738 |
1637 if ( ( $r['send'] || $thumbnail || $delete ) && ! isset( $form_fields['buttons'] ) ) { |
1739 if ( ( $parsed_args['send'] || $thumbnail || $delete ) && ! isset( $form_fields['buttons'] ) ) { |
1638 $form_fields['buttons'] = array( 'tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>" . $r['send'] . " $thumbnail $delete</td></tr>\n" ); |
1740 $form_fields['buttons'] = array( 'tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>" . $parsed_args['send'] . " $thumbnail $delete</td></tr>\n" ); |
1639 } |
1741 } |
|
1742 |
1640 $hidden_fields = array(); |
1743 $hidden_fields = array(); |
1641 |
1744 |
1642 foreach ( $form_fields as $id => $field ) { |
1745 foreach ( $form_fields as $id => $field ) { |
1643 if ( $id[0] == '_' ) { |
1746 if ( '_' === $id[0] ) { |
1644 continue; |
1747 continue; |
1645 } |
1748 } |
1646 |
1749 |
1647 if ( ! empty( $field['tr'] ) ) { |
1750 if ( ! empty( $field['tr'] ) ) { |
1648 $item .= $field['tr']; |
1751 $item .= $field['tr']; |
1650 } |
1753 } |
1651 |
1754 |
1652 $field = array_merge( $defaults, $field ); |
1755 $field = array_merge( $defaults, $field ); |
1653 $name = "attachments[$attachment_id][$id]"; |
1756 $name = "attachments[$attachment_id][$id]"; |
1654 |
1757 |
1655 if ( $field['input'] == 'hidden' ) { |
1758 if ( 'hidden' === $field['input'] ) { |
1656 $hidden_fields[ $name ] = $field['value']; |
1759 $hidden_fields[ $name ] = $field['value']; |
1657 continue; |
1760 continue; |
1658 } |
1761 } |
1659 |
1762 |
1660 $required = $field['required'] ? '<span class="required">*</span>' : ''; |
1763 $required = $field['required'] ? '<span class="required">*</span>' : ''; |
1661 $required_attr = $field['required'] ? ' required' : ''; |
1764 $required_attr = $field['required'] ? ' required' : ''; |
1662 $class = $id; |
1765 $class = $id; |
1663 $class .= $field['required'] ? ' form-required' : ''; |
1766 $class .= $field['required'] ? ' form-required' : ''; |
1664 |
1767 |
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'>"; |
1768 $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'>"; |
|
1769 |
1666 if ( ! empty( $field[ $field['input'] ] ) ) { |
1770 if ( ! empty( $field[ $field['input'] ] ) ) { |
1667 $item .= $field[ $field['input'] ]; |
1771 $item .= $field[ $field['input'] ]; |
1668 } elseif ( $field['input'] == 'textarea' ) { |
1772 } elseif ( 'textarea' === $field['input'] ) { |
1669 if ( 'post_content' == $id && user_can_richedit() ) { |
1773 if ( 'post_content' === $id && user_can_richedit() ) { |
1670 // Sanitize_post() skips the post_content when user_can_richedit. |
1774 // Sanitize_post() skips the post_content when user_can_richedit. |
1671 $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES ); |
1775 $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES ); |
1672 } |
1776 } |
1673 // Post_excerpt is already escaped by sanitize_post() in get_attachment_fields_to_edit(). |
1777 // Post_excerpt is already escaped by sanitize_post() in get_attachment_fields_to_edit(). |
1674 $item .= "<textarea id='$name' name='$name'{$required_attr}>" . $field['value'] . '</textarea>'; |
1778 $item .= "<textarea id='$name' name='$name'{$required_attr}>" . $field['value'] . '</textarea>'; |
1675 } else { |
1779 } else { |
1676 $item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "'{$required_attr} />"; |
1780 $item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "'{$required_attr} />"; |
1677 } |
1781 } |
|
1782 |
1678 if ( ! empty( $field['helps'] ) ) { |
1783 if ( ! empty( $field['helps'] ) ) { |
1679 $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>'; |
1784 $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>'; |
1680 } |
1785 } |
1681 $item .= "</td>\n\t\t</tr>\n"; |
1786 $item .= "</td>\n\t\t</tr>\n"; |
1682 |
1787 |
1747 $form_fields = array(); |
1853 $form_fields = array(); |
1748 |
1854 |
1749 if ( $args['in_modal'] ) { |
1855 if ( $args['in_modal'] ) { |
1750 foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) { |
1856 foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) { |
1751 $t = (array) get_taxonomy( $taxonomy ); |
1857 $t = (array) get_taxonomy( $taxonomy ); |
|
1858 |
1752 if ( ! $t['public'] || ! $t['show_ui'] ) { |
1859 if ( ! $t['public'] || ! $t['show_ui'] ) { |
1753 continue; |
1860 continue; |
1754 } |
1861 } |
|
1862 |
1755 if ( empty( $t['label'] ) ) { |
1863 if ( empty( $t['label'] ) ) { |
1756 $t['label'] = $taxonomy; |
1864 $t['label'] = $taxonomy; |
1757 } |
1865 } |
|
1866 |
1758 if ( empty( $t['args'] ) ) { |
1867 if ( empty( $t['args'] ) ) { |
1759 $t['args'] = array(); |
1868 $t['args'] = array(); |
1760 } |
1869 } |
1761 |
1870 |
1762 $terms = get_object_term_cache( $post->ID, $taxonomy ); |
1871 $terms = get_object_term_cache( $post->ID, $taxonomy ); |
|
1872 |
1763 if ( false === $terms ) { |
1873 if ( false === $terms ) { |
1764 $terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] ); |
1874 $terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] ); |
1765 } |
1875 } |
1766 |
1876 |
1767 $values = array(); |
1877 $values = array(); |
1768 |
1878 |
1769 foreach ( $terms as $term ) { |
1879 foreach ( $terms as $term ) { |
1770 $values[] = $term->slug; |
1880 $values[] = $term->slug; |
1771 } |
1881 } |
|
1882 |
1772 $t['value'] = join( ', ', $values ); |
1883 $t['value'] = join( ', ', $values ); |
1773 $t['taxonomy'] = true; |
1884 $t['taxonomy'] = true; |
1774 |
1885 |
1775 $form_fields[ $taxonomy ] = $t; |
1886 $form_fields[ $taxonomy ] = $t; |
1776 } |
1887 } |
1777 } |
1888 } |
1778 |
1889 |
1779 // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default |
1890 /* |
1780 // The recursive merge is easily traversed with array casting: foreach ( (array) $things as $thing ) |
1891 * Merge default fields with their errors, so any key passed with the error |
|
1892 * (e.g. 'error', 'helps', 'value') will replace the default. |
|
1893 * The recursive merge is easily traversed with array casting: |
|
1894 * foreach ( (array) $things as $thing ) |
|
1895 */ |
1781 $form_fields = array_merge_recursive( $form_fields, (array) $args['errors'] ); |
1896 $form_fields = array_merge_recursive( $form_fields, (array) $args['errors'] ); |
1782 |
1897 |
1783 /** This filter is documented in wp-admin/includes/media.php */ |
1898 /** This filter is documented in wp-admin/includes/media.php */ |
1784 $form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post ); |
1899 $form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post ); |
1785 |
1900 |
2040 * @param array $plupload_init An array of default settings used by Plupload. |
2169 * @param array $plupload_init An array of default settings used by Plupload. |
2041 */ |
2170 */ |
2042 $plupload_init = apply_filters( 'plupload_init', $plupload_init ); |
2171 $plupload_init = apply_filters( 'plupload_init', $plupload_init ); |
2043 |
2172 |
2044 ?> |
2173 ?> |
2045 |
2174 <script type="text/javascript"> |
2046 <script type="text/javascript"> |
|
2047 <?php |
2175 <?php |
2048 // Verify size is an int. If not return default value. |
2176 // Verify size is an int. If not return default value. |
2049 $large_size_h = absint( get_option( 'large_size_h' ) ); |
2177 $large_size_h = absint( get_option( 'large_size_h' ) ); |
|
2178 |
2050 if ( ! $large_size_h ) { |
2179 if ( ! $large_size_h ) { |
2051 $large_size_h = 1024; |
2180 $large_size_h = 1024; |
2052 } |
2181 } |
|
2182 |
2053 $large_size_w = absint( get_option( 'large_size_w' ) ); |
2183 $large_size_w = absint( get_option( 'large_size_w' ) ); |
|
2184 |
2054 if ( ! $large_size_w ) { |
2185 if ( ! $large_size_w ) { |
2055 $large_size_w = 1024; |
2186 $large_size_w = 1024; |
2056 } |
2187 } |
|
2188 |
2057 ?> |
2189 ?> |
2058 var resize_height = <?php echo $large_size_h; ?>, resize_width = <?php echo $large_size_w; ?>, |
2190 var resize_height = <?php echo $large_size_h; ?>, resize_width = <?php echo $large_size_w; ?>, |
2059 wpUploaderInit = <?php echo wp_json_encode( $plupload_init ); ?>; |
2191 wpUploaderInit = <?php echo wp_json_encode( $plupload_init ); ?>; |
2060 </script> |
2192 </script> |
2061 |
2193 |
2062 <div id="plupload-upload-ui" class="hide-if-no-js"> |
2194 <div id="plupload-upload-ui" class="hide-if-no-js"> |
2063 <?php |
2195 <?php |
2064 /** |
2196 /** |
2065 * Fires before the upload interface loads. |
2197 * Fires before the upload interface loads. |
2066 * |
2198 * |
2067 * @since 2.6.0 As 'pre-flash-upload-ui' |
2199 * @since 2.6.0 As 'pre-flash-upload-ui' |
2068 * @since 3.3.0 |
2200 * @since 3.3.0 |
2069 */ |
2201 */ |
2070 do_action( 'pre-plupload-upload-ui' ); |
2202 do_action( 'pre-plupload-upload-ui' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
2203 |
2071 ?> |
2204 ?> |
2072 <div id="drag-drop-area"> |
2205 <div id="drag-drop-area"> |
2073 <div class="drag-drop-inside"> |
2206 <div class="drag-drop-inside"> |
2074 <p class="drag-drop-info"><?php _e( 'Drop files here' ); ?></p> |
2207 <p class="drag-drop-info"><?php _e( 'Drop files to upload' ); ?></p> |
2075 <p><?php _ex( 'or', 'Uploader: Drop files here - or - Select Files' ); ?></p> |
2208 <p><?php _ex( 'or', 'Uploader: Drop files here - or - Select Files' ); ?></p> |
2076 <p class="drag-drop-buttons"><input id="plupload-browse-button" type="button" value="<?php esc_attr_e( 'Select Files' ); ?>" class="button" /></p> |
2209 <p class="drag-drop-buttons"><input id="plupload-browse-button" type="button" value="<?php esc_attr_e( 'Select Files' ); ?>" class="button" /></p> |
|
2210 </div> |
2077 </div> |
2211 </div> |
2078 </div> |
|
2079 <?php |
2212 <?php |
2080 /** |
2213 /** |
2081 * Fires after the upload interface loads. |
2214 * Fires after the upload interface loads. |
2082 * |
2215 * |
2083 * @since 2.6.0 As 'post-flash-upload-ui' |
2216 * @since 2.6.0 As 'post-flash-upload-ui' |
2084 * @since 3.3.0 |
2217 * @since 3.3.0 |
2085 */ |
2218 */ |
2086 do_action( 'post-plupload-upload-ui' ); |
2219 do_action( 'post-plupload-upload-ui' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
2087 ?> |
2220 ?> |
2088 </div> |
2221 </div> |
2089 |
2222 |
2090 <div id="html-upload-ui" class="hide-if-js"> |
2223 <div id="html-upload-ui" class="hide-if-js"> |
2091 <?php |
2224 <?php |
2092 /** |
2225 /** |
2093 * Fires before the upload button in the media upload interface. |
2226 * Fires before the upload button in the media upload interface. |
2094 * |
2227 * |
2095 * @since 2.6.0 |
2228 * @since 2.6.0 |
2096 */ |
2229 */ |
2097 do_action( 'pre-html-upload-ui' ); |
2230 do_action( 'pre-html-upload-ui' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
2231 |
2098 ?> |
2232 ?> |
2099 <p id="async-upload-wrap"> |
2233 <p id="async-upload-wrap"> |
2100 <label class="screen-reader-text" for="async-upload"><?php _e( 'Upload' ); ?></label> |
2234 <label class="screen-reader-text" for="async-upload"><?php _e( 'Upload' ); ?></label> |
2101 <input type="file" name="async-upload" id="async-upload" /> |
2235 <input type="file" name="async-upload" id="async-upload" /> |
2102 <?php submit_button( __( 'Upload' ), 'primary', 'html-upload', false ); ?> |
2236 <?php submit_button( __( 'Upload' ), 'primary', 'html-upload', false ); ?> |
2155 $form_class = 'media-upload-form type-form validate'; |
2295 $form_class = 'media-upload-form type-form validate'; |
2156 |
2296 |
2157 if ( get_user_setting( 'uploader' ) ) { |
2297 if ( get_user_setting( 'uploader' ) ) { |
2158 $form_class .= ' html-uploader'; |
2298 $form_class .= ' html-uploader'; |
2159 } |
2299 } |
|
2300 |
2160 ?> |
2301 ?> |
2161 |
2302 <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"> |
2303 <?php submit_button( '', 'hidden', 'save', false ); ?> |
2163 <?php submit_button( '', 'hidden', 'save', false ); ?> |
2304 <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; ?>" /> |
2305 <?php wp_nonce_field( 'media-form' ); ?> |
2165 <?php wp_nonce_field( 'media-form' ); ?> |
2306 |
2166 |
2307 <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> |
|
2168 |
2308 |
2169 <?php media_upload_form( $errors ); ?> |
2309 <?php media_upload_form( $errors ); ?> |
2170 |
2310 |
2171 <script type="text/javascript"> |
2311 <script type="text/javascript"> |
2172 jQuery(function($){ |
2312 jQuery(function($){ |
2173 var preloaded = $(".media-item.preloaded"); |
2313 var preloaded = $(".media-item.preloaded"); |
2174 if ( preloaded.length > 0 ) { |
2314 if ( preloaded.length > 0 ) { |
2175 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); |
2315 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); |
2176 } |
2316 } |
2177 updateMediaForm(); |
2317 updateMediaForm(); |
2178 }); |
2318 }); |
2179 </script> |
2319 </script> |
2180 <div id="media-items"> |
2320 <div id="media-items"> |
2181 <?php |
2321 <?php |
2182 |
2322 |
2183 if ( $id ) { |
2323 if ( $id ) { |
2184 if ( ! is_wp_error( $id ) ) { |
2324 if ( ! is_wp_error( $id ) ) { |
2185 add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 ); |
2325 add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 ); |
2223 $form_class = 'media-upload-form type-form validate'; |
2364 $form_class = 'media-upload-form type-form validate'; |
2224 |
2365 |
2225 if ( get_user_setting( 'uploader' ) ) { |
2366 if ( get_user_setting( 'uploader' ) ) { |
2226 $form_class .= ' html-uploader'; |
2367 $form_class .= ' html-uploader'; |
2227 } |
2368 } |
|
2369 |
2228 ?> |
2370 ?> |
2229 |
2371 <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"> |
2230 <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"> |
2372 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
2231 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
2373 <?php wp_nonce_field( 'media-form' ); ?> |
2232 <?php wp_nonce_field( 'media-form' ); ?> |
2374 |
2233 |
2375 <h3 class="media-title"><?php _e( 'Insert media from another website' ); ?></h3> |
2234 <h3 class="media-title"><?php _e( 'Insert media from another website' ); ?></h3> |
2376 |
2235 |
2377 <script type="text/javascript"> |
2236 <script type="text/javascript"> |
2378 var addExtImage = { |
2237 var addExtImage = { |
|
2238 |
2379 |
2239 width : '', |
2380 width : '', |
2240 height : '', |
2381 height : '', |
2241 align : 'alignnone', |
2382 align : 'alignnone', |
2242 |
2383 |
2243 insert : function() { |
2384 insert : function() { |
2244 var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = ''; |
2385 var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = ''; |
2245 |
2386 |
2246 if ( '' == f.src.value || '' == t.width ) |
2387 if ( '' === f.src.value || '' === t.width ) |
2247 return false; |
2388 return false; |
2248 |
2389 |
2249 if ( f.alt.value ) |
2390 if ( f.alt.value ) |
2250 alt = f.alt.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>'); |
2391 alt = f.alt.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>'); |
2251 |
2392 |
2252 <?php |
2393 <?php |
2253 /** This filter is documented in wp-admin/includes/media.php */ |
2394 /** This filter is documented in wp-admin/includes/media.php */ |
2254 if ( ! apply_filters( 'disable_captions', '' ) ) { |
2395 if ( ! apply_filters( 'disable_captions', '' ) ) { |
|
2396 ?> |
|
2397 if ( f.caption.value ) { |
|
2398 caption = f.caption.value.replace(/\r\n|\r/g, '\n'); |
|
2399 caption = caption.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){ |
|
2400 return a.replace(/[\r\n\t]+/, ' '); |
|
2401 }); |
|
2402 |
|
2403 caption = caption.replace(/\s*\n\s*/g, '<br />'); |
|
2404 } |
|
2405 <?php |
|
2406 } |
|
2407 |
2255 ?> |
2408 ?> |
2256 if ( f.caption.value ) { |
|
2257 caption = f.caption.value.replace(/\r\n|\r/g, '\n'); |
|
2258 caption = caption.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){ |
|
2259 return a.replace(/[\r\n\t]+/, ' '); |
|
2260 }); |
|
2261 |
|
2262 caption = caption.replace(/\s*\n\s*/g, '<br />'); |
|
2263 } |
|
2264 <?php } ?> |
|
2265 |
|
2266 cls = caption ? '' : ' class="'+t.align+'"'; |
2409 cls = caption ? '' : ' class="'+t.align+'"'; |
2267 |
2410 |
2268 html = '<img alt="'+alt+'" src="'+f.src.value+'"'+cls+' width="'+t.width+'" height="'+t.height+'" />'; |
2411 html = '<img alt="'+alt+'" src="'+f.src.value+'"'+cls+' width="'+t.width+'" height="'+t.height+'" />'; |
2269 |
2412 |
2270 if ( f.url.value ) { |
2413 if ( f.url.value ) { |
2367 $form_class = 'media-upload-form validate'; |
2511 $form_class = 'media-upload-form validate'; |
2368 |
2512 |
2369 if ( get_user_setting( 'uploader' ) ) { |
2513 if ( get_user_setting( 'uploader' ) ) { |
2370 $form_class .= ' html-uploader'; |
2514 $form_class .= ' html-uploader'; |
2371 } |
2515 } |
|
2516 |
2372 ?> |
2517 ?> |
2373 |
2518 <script type="text/javascript"> |
2374 <script type="text/javascript"> |
2519 jQuery(function($){ |
2375 jQuery(function($){ |
2520 var preloaded = $(".media-item.preloaded"); |
2376 var preloaded = $(".media-item.preloaded"); |
2521 if ( preloaded.length > 0 ) { |
2377 if ( preloaded.length > 0 ) { |
2522 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); |
2378 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); |
2523 updateMediaForm(); |
2379 updateMediaForm(); |
2524 } |
2380 } |
2525 }); |
2381 }); |
2526 </script> |
2382 </script> |
2527 <div id="sort-buttons" class="hide-if-no-js"> |
2383 <div id="sort-buttons" class="hide-if-no-js"> |
2528 <span> |
2384 <span> |
2529 <?php _e( 'All Tabs:' ); ?> |
2385 <?php _e( 'All Tabs:' ); ?> |
2530 <a href="#" id="showall"><?php _e( 'Show' ); ?></a> |
2386 <a href="#" id="showall"><?php _e( 'Show' ); ?></a> |
2531 <a href="#" id="hideall" style="display:none;"><?php _e( 'Hide' ); ?></a> |
2387 <a href="#" id="hideall" style="display:none;"><?php _e( 'Hide' ); ?></a> |
2532 </span> |
2388 </span> |
2533 <?php _e( 'Sort Order:' ); ?> |
2389 <?php _e( 'Sort Order:' ); ?> |
2534 <a href="#" id="asc"><?php _e( 'Ascending' ); ?></a> | |
2390 <a href="#" id="asc"><?php _e( 'Ascending' ); ?></a> | |
2535 <a href="#" id="desc"><?php _e( 'Descending' ); ?></a> | |
2391 <a href="#" id="desc"><?php _e( 'Descending' ); ?></a> | |
2536 <a href="#" id="clear"><?php _ex( 'Clear', 'verb' ); ?></a> |
2392 <a href="#" id="clear"><?php _ex( 'Clear', 'verb' ); ?></a> |
2537 </div> |
2393 </div> |
2538 <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"> |
2539 <?php wp_nonce_field( 'media-form' ); ?> |
2395 <?php wp_nonce_field( 'media-form' ); ?> |
2540 <?php // media_upload_form( $errors ); ?> |
2396 <?php //media_upload_form( $errors ); ?> |
2541 <table class="widefat"> |
2397 <table class="widefat"> |
2542 <thead><tr> |
2398 <thead><tr> |
2543 <th><?php _e( 'Media' ); ?></th> |
2399 <th><?php _e( 'Media' ); ?></th> |
2544 <th class="order-head"><?php _e( 'Order' ); ?></th> |
2400 <th class="order-head"><?php _e( 'Order' ); ?></th> |
2545 <th class="actions-head"><?php _e( 'Actions' ); ?></th> |
2401 <th class="actions-head"><?php _e( 'Actions' ); ?></th> |
2546 </tr></thead> |
2402 </tr></thead> |
2547 </table> |
2403 </table> |
2548 <div id="media-items"> |
2404 <div id="media-items"> |
2549 <?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 ); ?> |
2550 <?php echo get_media_items( $post_id, $errors ); ?> |
2406 <?php echo get_media_items( $post_id, $errors ); ?> |
2551 </div> |
2407 </div> |
2552 |
2408 |
2553 <p class="ml-submit"> |
2409 <p class="ml-submit"> |
2554 <?php |
|
2555 submit_button( |
|
2556 __( 'Save all changes' ), |
|
2557 'savebutton', |
|
2558 'save', |
|
2559 false, |
|
2560 array( |
|
2561 'id' => 'save-all', |
|
2562 'style' => 'display: none;', |
|
2563 ) |
|
2564 ); |
|
2565 ?> |
|
2566 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
|
2567 <input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" /> |
|
2568 <input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" /> |
|
2569 </p> |
|
2570 |
|
2571 <div id="gallery-settings" style="display:none;"> |
|
2572 <div class="title"><?php _e( 'Gallery Settings' ); ?></div> |
|
2573 <table id="basic" class="describe"><tbody> |
|
2574 <tr> |
|
2575 <th scope="row" class="label"> |
|
2576 <label> |
|
2577 <span class="alignleft"><?php _e( 'Link thumbnails to:' ); ?></span> |
|
2578 </label> |
|
2579 </th> |
|
2580 <td class="field"> |
|
2581 <input type="radio" name="linkto" id="linkto-file" value="file" /> |
|
2582 <label for="linkto-file" class="radio"><?php _e( 'Image File' ); ?></label> |
|
2583 |
|
2584 <input type="radio" checked="checked" name="linkto" id="linkto-post" value="post" /> |
|
2585 <label for="linkto-post" class="radio"><?php _e( 'Attachment Page' ); ?></label> |
|
2586 </td> |
|
2587 </tr> |
|
2588 |
|
2589 <tr> |
|
2590 <th scope="row" class="label"> |
|
2591 <label> |
|
2592 <span class="alignleft"><?php _e( 'Order images by:' ); ?></span> |
|
2593 </label> |
|
2594 </th> |
|
2595 <td class="field"> |
|
2596 <select id="orderby" name="orderby"> |
|
2597 <option value="menu_order" selected="selected"><?php _e( 'Menu order' ); ?></option> |
|
2598 <option value="title"><?php _e( 'Title' ); ?></option> |
|
2599 <option value="post_date"><?php _e( 'Date/Time' ); ?></option> |
|
2600 <option value="rand"><?php _e( 'Random' ); ?></option> |
|
2601 </select> |
|
2602 </td> |
|
2603 </tr> |
|
2604 |
|
2605 <tr> |
|
2606 <th scope="row" class="label"> |
|
2607 <label> |
|
2608 <span class="alignleft"><?php _e( 'Order:' ); ?></span> |
|
2609 </label> |
|
2610 </th> |
|
2611 <td class="field"> |
|
2612 <input type="radio" checked="checked" name="order" id="order-asc" value="asc" /> |
|
2613 <label for="order-asc" class="radio"><?php _e( 'Ascending' ); ?></label> |
|
2614 |
|
2615 <input type="radio" name="order" id="order-desc" value="desc" /> |
|
2616 <label for="order-desc" class="radio"><?php _e( 'Descending' ); ?></label> |
|
2617 </td> |
|
2618 </tr> |
|
2619 |
|
2620 <tr> |
|
2621 <th scope="row" class="label"> |
|
2622 <label> |
|
2623 <span class="alignleft"><?php _e( 'Gallery columns:' ); ?></span> |
|
2624 </label> |
|
2625 </th> |
|
2626 <td class="field"> |
|
2627 <select id="columns" name="columns"> |
|
2628 <option value="1">1</option> |
|
2629 <option value="2">2</option> |
|
2630 <option value="3" selected="selected">3</option> |
|
2631 <option value="4">4</option> |
|
2632 <option value="5">5</option> |
|
2633 <option value="6">6</option> |
|
2634 <option value="7">7</option> |
|
2635 <option value="8">8</option> |
|
2636 <option value="9">9</option> |
|
2637 </select> |
|
2638 </td> |
|
2639 </tr> |
|
2640 </tbody></table> |
|
2641 |
|
2642 <p class="ml-submit"> |
|
2643 <input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="insert-gallery" id="insert-gallery" value="<?php esc_attr_e( 'Insert gallery' ); ?>" /> |
|
2644 <input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="update-gallery" id="update-gallery" value="<?php esc_attr_e( 'Update gallery settings' ); ?>" /> |
|
2645 </p> |
|
2646 </div> |
|
2647 </form> |
2410 <?php |
2648 <?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 ?> |
|
2422 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
|
2423 <input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" /> |
|
2424 <input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" /> |
|
2425 </p> |
|
2426 |
|
2427 <div id="gallery-settings" style="display:none;"> |
|
2428 <div class="title"><?php _e( 'Gallery Settings' ); ?></div> |
|
2429 <table id="basic" class="describe"><tbody> |
|
2430 <tr> |
|
2431 <th scope="row" class="label"> |
|
2432 <label> |
|
2433 <span class="alignleft"><?php _e( 'Link thumbnails to:' ); ?></span> |
|
2434 </label> |
|
2435 </th> |
|
2436 <td class="field"> |
|
2437 <input type="radio" name="linkto" id="linkto-file" value="file" /> |
|
2438 <label for="linkto-file" class="radio"><?php _e( 'Image File' ); ?></label> |
|
2439 |
|
2440 <input type="radio" checked="checked" name="linkto" id="linkto-post" value="post" /> |
|
2441 <label for="linkto-post" class="radio"><?php _e( 'Attachment Page' ); ?></label> |
|
2442 </td> |
|
2443 </tr> |
|
2444 |
|
2445 <tr> |
|
2446 <th scope="row" class="label"> |
|
2447 <label> |
|
2448 <span class="alignleft"><?php _e( 'Order images by:' ); ?></span> |
|
2449 </label> |
|
2450 </th> |
|
2451 <td class="field"> |
|
2452 <select id="orderby" name="orderby"> |
|
2453 <option value="menu_order" selected="selected"><?php _e( 'Menu order' ); ?></option> |
|
2454 <option value="title"><?php _e( 'Title' ); ?></option> |
|
2455 <option value="post_date"><?php _e( 'Date/Time' ); ?></option> |
|
2456 <option value="rand"><?php _e( 'Random' ); ?></option> |
|
2457 </select> |
|
2458 </td> |
|
2459 </tr> |
|
2460 |
|
2461 <tr> |
|
2462 <th scope="row" class="label"> |
|
2463 <label> |
|
2464 <span class="alignleft"><?php _e( 'Order:' ); ?></span> |
|
2465 </label> |
|
2466 </th> |
|
2467 <td class="field"> |
|
2468 <input type="radio" checked="checked" name="order" id="order-asc" value="asc" /> |
|
2469 <label for="order-asc" class="radio"><?php _e( 'Ascending' ); ?></label> |
|
2470 |
|
2471 <input type="radio" name="order" id="order-desc" value="desc" /> |
|
2472 <label for="order-desc" class="radio"><?php _e( 'Descending' ); ?></label> |
|
2473 </td> |
|
2474 </tr> |
|
2475 |
|
2476 <tr> |
|
2477 <th scope="row" class="label"> |
|
2478 <label> |
|
2479 <span class="alignleft"><?php _e( 'Gallery columns:' ); ?></span> |
|
2480 </label> |
|
2481 </th> |
|
2482 <td class="field"> |
|
2483 <select id="columns" name="columns"> |
|
2484 <option value="1">1</option> |
|
2485 <option value="2">2</option> |
|
2486 <option value="3" selected="selected">3</option> |
|
2487 <option value="4">4</option> |
|
2488 <option value="5">5</option> |
|
2489 <option value="6">6</option> |
|
2490 <option value="7">7</option> |
|
2491 <option value="8">8</option> |
|
2492 <option value="9">9</option> |
|
2493 </select> |
|
2494 </td> |
|
2495 </tr> |
|
2496 </tbody></table> |
|
2497 |
|
2498 <p class="ml-submit"> |
|
2499 <input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="insert-gallery" id="insert-gallery" value="<?php esc_attr_e( 'Insert gallery' ); ?>" /> |
|
2500 <input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="update-gallery" id="update-gallery" value="<?php esc_attr_e( 'Update gallery settings' ); ?>" /> |
|
2501 </p> |
|
2502 </div> |
|
2503 </form> |
|
2504 <?php |
|
2505 } |
2649 } |
2506 |
2650 |
2507 /** |
2651 /** |
2508 * Outputs the legacy media upload form for the media library. |
2652 * Outputs the legacy media upload form for the media library. |
2509 * |
2653 * |
2510 * @since 2.5.0 |
2654 * @since 2.5.0 |
2511 * |
2655 * |
2512 * @global wpdb $wpdb |
2656 * @global wpdb $wpdb WordPress database abstraction object. |
2513 * @global WP_Query $wp_query |
2657 * @global WP_Query $wp_query WordPress Query object. |
2514 * @global WP_Locale $wp_locale |
2658 * @global WP_Locale $wp_locale WordPress date and time locale object. |
2515 * @global string $type |
2659 * @global string $type |
2516 * @global string $tab |
2660 * @global string $tab |
2517 * @global array $post_mime_types |
2661 * @global array $post_mime_types |
2518 * |
2662 * |
2519 * @param array $errors |
2663 * @param array $errors |
2546 } |
2690 } |
2547 |
2691 |
2548 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query( $q ); |
2692 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query( $q ); |
2549 |
2693 |
2550 ?> |
2694 ?> |
2551 |
2695 <form id="filter" method="get"> |
2552 <form id="filter" method="get"> |
2696 <input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" /> |
2553 <input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" /> |
2697 <input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" /> |
2554 <input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" /> |
2698 <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; ?>" /> |
2699 <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'] ) : ''; ?>" /> |
2700 <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'] ) : ''; ?>" /> |
2701 |
2558 |
2702 <p id="media-search" class="search-box"> |
2559 <p id="media-search" class="search-box"> |
2703 <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> |
2704 <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(); ?>" /> |
2705 <?php submit_button( __( 'Search Media' ), '', '', false ); ?> |
2562 <?php submit_button( __( 'Search Media' ), '', '', false ); ?> |
2706 </p> |
2563 </p> |
2707 |
2564 |
2708 <ul class="subsubsub"> |
2565 <ul class="subsubsub"> |
2709 <?php |
2566 <?php |
2710 $type_links = array(); |
2567 $type_links = array(); |
2711 $_num_posts = (array) wp_count_attachments(); |
2568 $_num_posts = (array) wp_count_attachments(); |
2712 $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 ) ); |
2713 foreach ( $matches as $_type => $reals ) { |
2570 foreach ( $matches as $_type => $reals ) { |
2714 foreach ( $reals as $real ) { |
2571 foreach ( $reals as $real ) { |
2715 if ( isset( $num_posts[ $_type ] ) ) { |
2572 if ( isset( $num_posts[ $_type ] ) ) { |
2716 $num_posts[ $_type ] += $_num_posts[ $real ]; |
2573 $num_posts[ $_type ] += $_num_posts[ $real ]; |
2717 } else { |
2574 } else { |
2718 $num_posts[ $_type ] = $_num_posts[ $real ]; |
2575 $num_posts[ $_type ] = $_num_posts[ $real ]; |
2719 } |
2576 } |
2720 } |
2577 } |
2721 } |
2578 } |
2722 // If available type specified by media button clicked, filter by that type. |
2579 // If available type specified by media button clicked, filter by that type |
2723 if ( empty( $_GET['post_mime_type'] ) && ! empty( $num_posts[ $type ] ) ) { |
2580 if ( empty( $_GET['post_mime_type'] ) && ! empty( $num_posts[ $type ] ) ) { |
2724 $_GET['post_mime_type'] = $type; |
2581 $_GET['post_mime_type'] = $type; |
2725 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); |
2582 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); |
2726 } |
2583 } |
2727 if ( empty( $_GET['post_mime_type'] ) || 'all' === $_GET['post_mime_type'] ) { |
2584 if ( empty( $_GET['post_mime_type'] ) || $_GET['post_mime_type'] == 'all' ) { |
|
2585 $class = ' class="current"'; |
|
2586 } else { |
|
2587 $class = ''; |
|
2588 } |
|
2589 $type_links[] = '<li><a href="' . esc_url( |
|
2590 add_query_arg( |
|
2591 array( |
|
2592 'post_mime_type' => 'all', |
|
2593 'paged' => false, |
|
2594 'm' => false, |
|
2595 ) |
|
2596 ) |
|
2597 ) . '"' . $class . '>' . __( 'All Types' ) . '</a>'; |
|
2598 foreach ( $post_mime_types as $mime_type => $label ) { |
|
2599 $class = ''; |
|
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"'; |
2728 $class = ' class="current"'; |
2607 } |
2729 } else { |
2608 |
2730 $class = ''; |
|
2731 } |
2609 $type_links[] = '<li><a href="' . esc_url( |
2732 $type_links[] = '<li><a href="' . esc_url( |
2610 add_query_arg( |
2733 add_query_arg( |
2611 array( |
2734 array( |
2612 'post_mime_type' => $mime_type, |
2735 'post_mime_type' => 'all', |
2613 'paged' => false, |
2736 'paged' => false, |
|
2737 'm' => false, |
2614 ) |
2738 ) |
2615 ) |
2739 ) |
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>'; |
2740 ) . '"' . $class . '>' . __( 'All Types' ) . '</a>'; |
2617 } |
2741 foreach ( $post_mime_types as $mime_type => $label ) { |
2618 /** |
2742 $class = ''; |
2619 * Filters the media upload mime type list items. |
2743 |
2620 * |
2744 if ( ! wp_match_mime_types( $mime_type, $avail_post_mime_types ) ) { |
2621 * Returned values should begin with an `<li>` tag. |
2745 continue; |
2622 * |
2746 } |
2623 * @since 3.1.0 |
2747 |
2624 * |
2748 if ( isset( $_GET['post_mime_type'] ) && wp_match_mime_types( $mime_type, $_GET['post_mime_type'] ) ) { |
2625 * @param string[] $type_links An array of list items containing mime type link HTML. |
2749 $class = ' class="current"'; |
2626 */ |
2750 } |
2627 echo implode( ' | </li>', apply_filters( 'media_upload_mime_type_links', $type_links ) ) . '</li>'; |
2751 |
2628 unset( $type_links ); |
2752 $type_links[] = '<li><a href="' . esc_url( |
2629 ?> |
2753 add_query_arg( |
2630 </ul> |
2754 array( |
2631 |
2755 'post_mime_type' => $mime_type, |
2632 <div class="tablenav"> |
2756 'paged' => false, |
2633 |
2757 ) |
2634 <?php |
2758 ) |
2635 $page_links = paginate_links( |
2759 ) . '"' . $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>'; |
2636 array( |
2760 } |
2637 'base' => add_query_arg( 'paged', '%#%' ), |
2761 /** |
2638 'format' => '', |
2762 * Filters the media upload mime type list items. |
2639 'prev_text' => __( '«' ), |
2763 * |
2640 'next_text' => __( '»' ), |
2764 * Returned values should begin with an `<li>` tag. |
2641 'total' => ceil( $wp_query->found_posts / 10 ), |
2765 * |
2642 'current' => $q['paged'], |
2766 * @since 3.1.0 |
2643 ) |
2767 * |
2644 ); |
2768 * @param string[] $type_links An array of list items containing mime type link HTML. |
2645 |
2769 */ |
2646 if ( $page_links ) { |
2770 echo implode( ' | </li>', apply_filters( 'media_upload_mime_type_links', $type_links ) ) . '</li>'; |
2647 echo "<div class='tablenav-pages'>$page_links</div>"; |
2771 unset( $type_links ); |
2648 } |
|
2649 ?> |
|
2650 |
|
2651 <div class="alignleft actions"> |
|
2652 <?php |
|
2653 |
|
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"; |
|
2655 |
|
2656 $arc_result = $wpdb->get_results( $arc_query ); |
|
2657 |
|
2658 $month_count = count( $arc_result ); |
|
2659 $selected_month = isset( $_GET['m'] ) ? $_GET['m'] : 0; |
|
2660 |
|
2661 if ( $month_count && ! ( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { |
|
2662 ?> |
2772 ?> |
2663 <select name='m'> |
2773 </ul> |
2664 <option<?php selected( $selected_month, 0 ); ?> value='0'><?php _e( 'All dates' ); ?></option> |
2774 |
|
2775 <div class="tablenav"> |
|
2776 |
2665 <?php |
2777 <?php |
2666 foreach ( $arc_result as $arc_row ) { |
2778 $page_links = paginate_links( |
2667 if ( $arc_row->yyear == 0 ) { |
2779 array( |
2668 continue; |
2780 'base' => add_query_arg( 'paged', '%#%' ), |
2669 } |
2781 'format' => '', |
2670 $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 ); |
2782 'prev_text' => __( '«' ), |
2671 |
2783 'next_text' => __( '»' ), |
2672 if ( $arc_row->yyear . $arc_row->mmonth == $selected_month ) { |
2784 'total' => ceil( $wp_query->found_posts / 10 ), |
2673 $default = ' selected="selected"'; |
2785 'current' => $q['paged'], |
2674 } else { |
2786 ) |
2675 $default = ''; |
2787 ); |
2676 } |
2788 |
2677 |
2789 if ( $page_links ) { |
2678 echo "<option$default value='" . esc_attr( $arc_row->yyear . $arc_row->mmonth ) . "'>"; |
2790 echo "<div class='tablenav-pages'>$page_links</div>"; |
2679 echo esc_html( $wp_locale->get_month( $arc_row->mmonth ) . " $arc_row->yyear" ); |
|
2680 echo "</option>\n"; |
|
2681 } |
2791 } |
2682 ?> |
2792 ?> |
2683 </select> |
2793 |
2684 <?php } ?> |
2794 <div class="alignleft actions"> |
2685 |
2795 <?php |
2686 <?php submit_button( __( 'Filter »' ), '', 'post-query-submit', false ); ?> |
2796 |
2687 |
2797 $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"; |
2688 </div> |
2798 |
2689 |
2799 $arc_result = $wpdb->get_results( $arc_query ); |
2690 <br class="clear" /> |
2800 |
2691 </div> |
2801 $month_count = count( $arc_result ); |
2692 </form> |
2802 $selected_month = isset( $_GET['m'] ) ? $_GET['m'] : 0; |
2693 |
2803 |
2694 <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="library-form"> |
2804 if ( $month_count && ! ( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { |
2695 |
2805 ?> |
|
2806 <select name='m'> |
|
2807 <option<?php selected( $selected_month, 0 ); ?> value='0'><?php _e( 'All dates' ); ?></option> |
|
2808 <?php |
|
2809 |
|
2810 foreach ( $arc_result as $arc_row ) { |
|
2811 if ( 0 == $arc_row->yyear ) { |
|
2812 continue; |
|
2813 } |
|
2814 |
|
2815 $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 ); |
|
2816 |
|
2817 if ( $arc_row->yyear . $arc_row->mmonth == $selected_month ) { |
|
2818 $default = ' selected="selected"'; |
|
2819 } else { |
|
2820 $default = ''; |
|
2821 } |
|
2822 |
|
2823 echo "<option$default value='" . esc_attr( $arc_row->yyear . $arc_row->mmonth ) . "'>"; |
|
2824 echo esc_html( $wp_locale->get_month( $arc_row->mmonth ) . " $arc_row->yyear" ); |
|
2825 echo "</option>\n"; |
|
2826 } |
|
2827 |
|
2828 ?> |
|
2829 </select> |
|
2830 <?php } ?> |
|
2831 |
|
2832 <?php submit_button( __( 'Filter »' ), '', 'post-query-submit', false ); ?> |
|
2833 |
|
2834 </div> |
|
2835 |
|
2836 <br class="clear" /> |
|
2837 </div> |
|
2838 </form> |
|
2839 |
|
2840 <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="library-form"> |
2696 <?php wp_nonce_field( 'media-form' ); ?> |
2841 <?php wp_nonce_field( 'media-form' ); ?> |
2697 <?php //media_upload_form( $errors ); ?> |
2842 <?php // media_upload_form( $errors ); ?> |
2698 |
2843 |
2699 <script type="text/javascript"> |
2844 <script type="text/javascript"> |
2700 <!-- |
2845 jQuery(function($){ |
2701 jQuery(function($){ |
2846 var preloaded = $(".media-item.preloaded"); |
2702 var preloaded = $(".media-item.preloaded"); |
2847 if ( preloaded.length > 0 ) { |
2703 if ( preloaded.length > 0 ) { |
2848 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); |
2704 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); |
2849 updateMediaForm(); |
2705 updateMediaForm(); |
2850 } |
2706 } |
2851 }); |
2707 }); |
2852 </script> |
2708 --> |
2853 |
2709 </script> |
2854 <div id="media-items"> |
2710 |
2855 <?php add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 ); ?> |
2711 <div id="media-items"> |
2856 <?php echo get_media_items( null, $errors ); ?> |
2712 <?php add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 ); ?> |
2857 </div> |
2713 <?php echo get_media_items( null, $errors ); ?> |
2858 <p class="ml-submit"> |
2714 </div> |
2859 <?php submit_button( __( 'Save all changes' ), 'savebutton', 'save', false ); ?> |
2715 <p class="ml-submit"> |
2860 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
2716 <?php submit_button( __( 'Save all changes' ), 'savebutton', 'save', false ); ?> |
2861 </p> |
2717 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
2862 </form> |
2718 </p> |
|
2719 </form> |
|
2720 <?php |
2863 <?php |
2721 } |
2864 } |
2722 |
2865 |
2723 /** |
2866 /** |
2724 * Creates the form for external url |
2867 * Creates the form for external url |
2735 <tr class="image-only"> |
2878 <tr class="image-only"> |
2736 <th scope="row" class="label"> |
2879 <th scope="row" class="label"> |
2737 <label for="caption"><span class="alignleft">' . __( 'Image Caption' ) . '</span></label> |
2880 <label for="caption"><span class="alignleft">' . __( 'Image Caption' ) . '</span></label> |
2738 </th> |
2881 </th> |
2739 <td class="field"><textarea id="caption" name="caption"></textarea></td> |
2882 <td class="field"><textarea id="caption" name="caption"></textarea></td> |
2740 </tr> |
2883 </tr>'; |
2741 '; |
|
2742 } else { |
2884 } else { |
2743 $caption = ''; |
2885 $caption = ''; |
2744 } |
2886 } |
2745 |
2887 |
2746 $default_align = get_option( 'image_default_align' ); |
2888 $default_align = get_option( 'image_default_align' ); |
|
2889 |
2747 if ( empty( $default_align ) ) { |
2890 if ( empty( $default_align ) ) { |
2748 $default_align = 'none'; |
2891 $default_align = 'none'; |
2749 } |
2892 } |
2750 |
2893 |
2751 if ( 'image' == $default_view ) { |
2894 if ( 'image' === $default_view ) { |
2752 $view = 'image-only'; |
2895 $view = 'image-only'; |
2753 $table_class = ''; |
2896 $table_class = ''; |
2754 } else { |
2897 } else { |
2755 $view = $table_class = 'not-image'; |
2898 $view = 'not-image'; |
|
2899 $table_class = $view; |
2756 } |
2900 } |
2757 |
2901 |
2758 return ' |
2902 return ' |
2759 <p class="media-types"><label><input type="radio" name="media_type" value="image" id="image-only"' . checked( 'image-only', $view, false ) . ' /> ' . __( 'Image' ) . '</label> <label><input type="radio" name="media_type" value="generic" id="not-image"' . checked( 'not-image', $view, false ) . ' /> ' . __( 'Audio, Video, or Other File' ) . '</label></p> |
2903 <p class="media-types"><label><input type="radio" name="media_type" value="image" id="image-only"' . checked( 'image-only', $view, false ) . ' /> ' . __( 'Image' ) . '</label> <label><input type="radio" name="media_type" value="generic" id="not-image"' . checked( 'not-image', $view, false ) . ' /> ' . __( 'Audio, Video, or Other File' ) . '</label></p> |
2760 <p class="media-types media-types-required-info">' . sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) . '</p> |
2904 <p class="media-types media-types-required-info">' . |
|
2905 /* translators: %s: Asterisk symbol (*). */ |
|
2906 sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) . |
|
2907 '</p> |
2761 <table class="describe ' . $table_class . '"><tbody> |
2908 <table class="describe ' . $table_class . '"><tbody> |
2762 <tr> |
2909 <tr> |
2763 <th scope="row" class="label" style="width:130px;"> |
2910 <th scope="row" class="label" style="width:130px;"> |
2764 <label for="src"><span class="alignleft">' . __( 'URL' ) . '</span> <span class="required">*</span></label> |
2911 <label for="src"><span class="alignleft">' . __( 'URL' ) . '</span> <span class="required">*</span></label> |
2765 <span class="alignright" id="status_img"></span> |
2912 <span class="alignright" id="status_img"></span> |
2873 * |
3026 * |
2874 * @since 3.3.0 |
3027 * @since 3.3.0 |
2875 */ |
3028 */ |
2876 function media_upload_max_image_resize() { |
3029 function media_upload_max_image_resize() { |
2877 $checked = get_user_setting( 'upload_resize' ) ? ' checked="true"' : ''; |
3030 $checked = get_user_setting( 'upload_resize' ) ? ' checked="true"' : ''; |
2878 $a = $end = ''; |
3031 $a = ''; |
|
3032 $end = ''; |
2879 |
3033 |
2880 if ( current_user_can( 'manage_options' ) ) { |
3034 if ( current_user_can( 'manage_options' ) ) { |
2881 $a = '<a href="' . esc_url( admin_url( 'options-media.php' ) ) . '" target="_blank">'; |
3035 $a = '<a href="' . esc_url( admin_url( 'options-media.php' ) ) . '" target="_blank">'; |
2882 $end = '</a>'; |
3036 $end = '</a>'; |
2883 } |
3037 } |
|
3038 |
2884 ?> |
3039 ?> |
2885 <p class="hide-if-no-js"><label> |
3040 <p class="hide-if-no-js"><label> |
2886 <input name="image_resize" type="checkbox" id="image_resize" value="true"<?php echo $checked; ?> /> |
3041 <input name="image_resize" type="checkbox" id="image_resize" value="true"<?php echo $checked; ?> /> |
2887 <?php |
3042 <?php |
2888 /* translators: 1: link start tag, 2: link end tag, 3: width, 4: height */ |
3043 /* translators: 1: Link start tag, 2: Link end tag, 3: Width, 4: Height. */ |
2889 printf( __( 'Scale images to match the large size selected in %1$simage options%2$s (%3$d × %4$d).' ), $a, $end, (int) get_option( 'large_size_w', '1024' ), (int) get_option( 'large_size_h', '1024' ) ); |
3044 printf( __( 'Scale images to match the large size selected in %1$simage options%2$s (%3$d × %4$d).' ), $a, $end, (int) get_option( 'large_size_w', '1024' ), (int) get_option( 'large_size_h', '1024' ) ); |
|
3045 |
2890 ?> |
3046 ?> |
2891 </label></p> |
3047 </label></p> |
2892 <?php |
3048 <?php |
2893 } |
3049 } |
2894 |
3050 |
2895 /** |
3051 /** |
2896 * Displays the out of storage quota message in Multisite. |
3052 * Displays the out of storage quota message in Multisite. |
2897 * |
3053 * |
2898 * @since 3.5.0 |
3054 * @since 3.5.0 |
2899 */ |
3055 */ |
2900 function multisite_over_quota_message() { |
3056 function multisite_over_quota_message() { |
2901 echo '<p>' . sprintf( |
3057 echo '<p>' . sprintf( |
2902 /* translators: %s: allowed space allocation */ |
3058 /* translators: %s: Allowed space allocation. */ |
2903 __( 'Sorry, you have used your space allocation of %s. Please delete some files to upload more files.' ), |
3059 __( 'Sorry, you have used your space allocation of %s. Please delete some files to upload more files.' ), |
2904 size_format( get_space_allowed() * MB_IN_BYTES ) |
3060 size_format( get_space_allowed() * MB_IN_BYTES ) |
2905 ) . '</p>'; |
3061 ) . '</p>'; |
2906 } |
3062 } |
2907 |
3063 |
2912 * |
3068 * |
2913 * @param WP_Post $post A post object. |
3069 * @param WP_Post $post A post object. |
2914 */ |
3070 */ |
2915 function edit_form_image_editor( $post ) { |
3071 function edit_form_image_editor( $post ) { |
2916 $open = isset( $_GET['image-editor'] ); |
3072 $open = isset( $_GET['image-editor'] ); |
|
3073 |
2917 if ( $open ) { |
3074 if ( $open ) { |
2918 require_once ABSPATH . 'wp-admin/includes/image-edit.php'; |
3075 require_once ABSPATH . 'wp-admin/includes/image-edit.php'; |
2919 } |
3076 } |
2920 |
3077 |
2921 $thumb_url = false; |
3078 $thumb_url = false; |
2922 if ( $attachment_id = intval( $post->ID ) ) { |
3079 $attachment_id = intval( $post->ID ); |
|
3080 |
|
3081 if ( $attachment_id ) { |
2923 $thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 450 ), true ); |
3082 $thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 450 ), true ); |
2924 } |
3083 } |
2925 |
3084 |
2926 $alt_text = get_post_meta( $post->ID, '_wp_attachment_image_alt', true ); |
3085 $alt_text = get_post_meta( $post->ID, '_wp_attachment_image_alt', true ); |
2927 |
3086 |
2928 $att_url = wp_get_attachment_url( $post->ID ); |
3087 $att_url = wp_get_attachment_url( $post->ID ); |
2929 ?> |
3088 ?> |
2930 <div class="wp_attachment_holder wp-clearfix"> |
3089 <div class="wp_attachment_holder wp-clearfix"> |
2931 <?php |
3090 <?php |
|
3091 |
2932 if ( wp_attachment_is_image( $post->ID ) ) : |
3092 if ( wp_attachment_is_image( $post->ID ) ) : |
2933 $image_edit_button = ''; |
3093 $image_edit_button = ''; |
2934 if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { |
3094 if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { |
2935 $nonce = wp_create_nonce( "image_editor-$post->ID" ); |
3095 $nonce = wp_create_nonce( "image_editor-$post->ID" ); |
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>"; |
3096 $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>"; |
2937 } |
3097 } |
2938 |
3098 |
2939 $open_style = $not_open_style = ''; |
3099 $open_style = ''; |
|
3100 $not_open_style = ''; |
|
3101 |
2940 if ( $open ) { |
3102 if ( $open ) { |
2941 $open_style = ' style="display:none"'; |
3103 $open_style = ' style="display:none"'; |
2942 } else { |
3104 } else { |
2943 $not_open_style = ' style="display:none"'; |
3105 $not_open_style = ' style="display:none"'; |
2944 } |
3106 } |
|
3107 |
2945 ?> |
3108 ?> |
2946 |
|
2947 <div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div> |
3109 <div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div> |
2948 |
3110 |
2949 <div<?php echo $open_style; ?> class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>"> |
3111 <div<?php echo $open_style; ?> class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>"> |
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> |
3112 <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> |
2951 <p><?php echo $image_edit_button; ?></p> |
3113 <p><?php echo $image_edit_button; ?></p> |
2952 </div> |
3114 </div> |
2953 <div<?php echo $not_open_style; ?> class="image-editor" id="image-editor-<?php echo $attachment_id; ?>"> |
3115 <div<?php echo $not_open_style; ?> class="image-editor" id="image-editor-<?php echo $attachment_id; ?>"> |
2954 <?php |
3116 <?php |
2955 if ( $open ) { |
3117 |
2956 wp_image_editor( $attachment_id );} |
3118 if ( $open ) { |
2957 ?> |
3119 wp_image_editor( $attachment_id ); |
|
3120 } |
|
3121 |
|
3122 ?> |
2958 </div> |
3123 </div> |
2959 <?php |
3124 <?php |
2960 elseif ( $attachment_id && wp_attachment_is( 'audio', $post ) ) : |
3125 elseif ( $attachment_id && wp_attachment_is( 'audio', $post ) ) : |
2961 |
3126 |
2962 wp_maybe_generate_attachment_metadata( $post ); |
3127 wp_maybe_generate_attachment_metadata( $post ); |
3007 * @param WP_Post $post A post object. |
3174 * @param WP_Post $post A post object. |
3008 */ |
3175 */ |
3009 do_action( 'wp_edit_form_attachment_display', $post ); |
3176 do_action( 'wp_edit_form_attachment_display', $post ); |
3010 |
3177 |
3011 endif; |
3178 endif; |
|
3179 |
3012 ?> |
3180 ?> |
3013 </div> |
3181 </div> |
3014 <div class="wp_attachment_details edit-form-section"> |
3182 <div class="wp_attachment_details edit-form-section"> |
3015 <?php if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) : ?> |
3183 <?php if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) : ?> |
3016 <p class="attachment-alt-text"> |
3184 <p class="attachment-alt-text"> |
3017 <label for="attachment_alt"><strong><?php _e( 'Alternative Text' ); ?></strong></label><br /> |
3185 <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 ); ?>" /> |
3186 <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> |
3187 </p> |
3020 <p class="attachment-alt-text-description" id="alt-text-description"> |
3188 <p class="attachment-alt-text-description" id="alt-text-description"> |
3021 <?php |
3189 <?php |
3022 printf( |
3190 |
3023 /* translators: 1: link to tutorial, 2: additional link attributes, 3: accessibility text */ |
3191 printf( |
3024 __( '<a href="%1$s" %2$s>Describe the purpose of the image%3$s</a>. Leave empty if the image is purely decorative.' ), |
3192 /* translators: 1: Link to tutorial, 2: Additional link attributes, 3: Accessibility text. */ |
3025 esc_url( 'https://www.w3.org/WAI/tutorials/images/decision-tree' ), |
3193 __( '<a href="%1$s" %2$s>Describe the purpose of the image%3$s</a>. Leave empty if the image is purely decorative.' ), |
3026 'target="_blank" rel="noopener noreferrer"', |
3194 esc_url( 'https://www.w3.org/WAI/tutorials/images/decision-tree' ), |
3027 sprintf( |
3195 'target="_blank" rel="noopener noreferrer"', |
3028 '<span class="screen-reader-text"> %s</span>', |
3196 sprintf( |
3029 /* translators: accessibility text */ |
3197 '<span class="screen-reader-text"> %s</span>', |
3030 __( '(opens in a new tab)' ) |
3198 /* translators: Accessibility text. */ |
3031 ) |
3199 __( '(opens in a new tab)' ) |
3032 ); |
3200 ) |
3033 ?> |
3201 ); |
|
3202 |
|
3203 ?> |
3034 </p> |
3204 </p> |
3035 <?php endif; ?> |
3205 <?php endif; ?> |
3036 |
3206 |
3037 <p> |
3207 <p> |
3038 <label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br /> |
3208 <label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br /> |
3039 <textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea> |
3209 <textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea> |
3040 </p> |
3210 </p> |
3041 |
3211 |
3042 <?php |
3212 <?php |
3043 $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' ); |
3213 |
3044 $editor_args = array( |
3214 $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' ); |
3045 'textarea_name' => 'content', |
3215 $editor_args = array( |
3046 'textarea_rows' => 5, |
3216 'textarea_name' => 'content', |
3047 'media_buttons' => false, |
3217 'textarea_rows' => 5, |
3048 'tinymce' => false, |
3218 'media_buttons' => false, |
3049 'quicktags' => $quicktags_settings, |
3219 'tinymce' => false, |
3050 ); |
3220 'quicktags' => $quicktags_settings, |
|
3221 ); |
|
3222 |
3051 ?> |
3223 ?> |
3052 |
3224 |
3053 <label for="attachment_content"><strong><?php _e( 'Description' ); ?></strong> |
3225 <label for="attachment_content" class="attachment-content-description"><strong><?php _e( 'Description' ); ?></strong> |
3054 <?php |
3226 <?php |
3055 if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) { |
3227 |
3056 echo ': ' . __( 'Displayed on attachment pages.' ); |
3228 if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) { |
3057 } |
3229 echo ': ' . __( 'Displayed on attachment pages.' ); |
3058 ?> |
3230 } |
|
3231 |
|
3232 ?> |
3059 </label> |
3233 </label> |
3060 <?php wp_editor( $post->post_content, 'attachment_content', $editor_args ); ?> |
3234 <?php wp_editor( format_to_edit( $post->post_content ), 'attachment_content', $editor_args ); ?> |
3061 |
3235 |
3062 </div> |
3236 </div> |
3063 <?php |
3237 <?php |
|
3238 |
3064 $extras = get_compat_media_markup( $post->ID ); |
3239 $extras = get_compat_media_markup( $post->ID ); |
3065 echo $extras['item']; |
3240 echo $extras['item']; |
3066 echo '<input type="hidden" id="image-edit-context" value="edit-attachment" />' . "\n"; |
3241 echo '<input type="hidden" id="image-edit-context" value="edit-attachment" />' . "\n"; |
3067 } |
3242 } |
3068 |
3243 |
3070 * Displays non-editable attachment metadata in the publish meta box. |
3245 * Displays non-editable attachment metadata in the publish meta box. |
3071 * |
3246 * |
3072 * @since 3.5.0 |
3247 * @since 3.5.0 |
3073 */ |
3248 */ |
3074 function attachment_submitbox_metadata() { |
3249 function attachment_submitbox_metadata() { |
3075 $post = get_post(); |
3250 $post = get_post(); |
3076 |
3251 $attachment_id = $post->ID; |
3077 $file = get_attached_file( $post->ID ); |
3252 |
|
3253 $file = get_attached_file( $attachment_id ); |
3078 $filename = esc_html( wp_basename( $file ) ); |
3254 $filename = esc_html( wp_basename( $file ) ); |
3079 |
3255 |
3080 $media_dims = ''; |
3256 $media_dims = ''; |
3081 $meta = wp_get_attachment_metadata( $post->ID ); |
3257 $meta = wp_get_attachment_metadata( $attachment_id ); |
|
3258 |
3082 if ( isset( $meta['width'], $meta['height'] ) ) { |
3259 if ( isset( $meta['width'], $meta['height'] ) ) { |
3083 $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']} × {$meta['height']}</span> "; |
3260 $media_dims .= "<span id='media-dims-$attachment_id'>{$meta['width']} × {$meta['height']}</span> "; |
3084 } |
3261 } |
3085 /** This filter is documented in wp-admin/includes/media.php */ |
3262 /** This filter is documented in wp-admin/includes/media.php */ |
3086 $media_dims = apply_filters( 'media_meta', $media_dims, $post ); |
3263 $media_dims = apply_filters( 'media_meta', $media_dims, $post ); |
3087 |
3264 |
3088 $att_url = wp_get_attachment_url( $post->ID ); |
3265 $att_url = wp_get_attachment_url( $attachment_id ); |
|
3266 |
3089 ?> |
3267 ?> |
3090 <div class="misc-pub-section misc-pub-attachment"> |
3268 <div class="misc-pub-section misc-pub-attachment"> |
3091 <label for="attachment_url"><?php _e( 'File URL:' ); ?></label> |
3269 <label for="attachment_url"><?php _e( 'File URL:' ); ?></label> |
3092 <input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" id="attachment_url" value="<?php echo esc_attr( $att_url ); ?>" /> |
3270 <input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" id="attachment_url" value="<?php echo esc_attr( $att_url ); ?>" /> |
|
3271 <span class="copy-to-clipboard-container"> |
|
3272 <button type="button" class="button copy-attachment-url edit-media" data-clipboard-target="#attachment_url"><?php _e( 'Copy URL' ); ?></button> |
|
3273 <span class="success hidden" aria-hidden="true"><?php _e( 'Copied!' ); ?></span> |
|
3274 </span> |
3093 </div> |
3275 </div> |
3094 <div class="misc-pub-section misc-pub-filename"> |
3276 <div class="misc-pub-section misc-pub-filename"> |
3095 <?php _e( 'File name:' ); ?> <strong><?php echo $filename; ?></strong> |
3277 <?php _e( 'File name:' ); ?> <strong><?php echo $filename; ?></strong> |
3096 </div> |
3278 </div> |
3097 <div class="misc-pub-section misc-pub-filetype"> |
3279 <div class="misc-pub-section misc-pub-filetype"> |
3098 <?php _e( 'File type:' ); ?> <strong> |
3280 <?php _e( 'File type:' ); ?> |
3099 <?php |
3281 <strong> |
3100 if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) ) { |
3282 <?php |
3101 echo esc_html( strtoupper( $matches[1] ) ); |
3283 |
3102 list( $mime_type ) = explode( '/', $post->post_mime_type ); |
3284 if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) ) { |
3103 if ( $mime_type !== 'image' && ! empty( $meta['mime_type'] ) ) { |
3285 echo esc_html( strtoupper( $matches[1] ) ); |
3104 if ( $meta['mime_type'] !== "$mime_type/" . strtolower( $matches[1] ) ) { |
3286 list( $mime_type ) = explode( '/', $post->post_mime_type ); |
3105 echo ' (' . $meta['mime_type'] . ')'; |
3287 if ( 'image' !== $mime_type && ! empty( $meta['mime_type'] ) ) { |
3106 } |
3288 if ( "$mime_type/" . strtolower( $matches[1] ) !== $meta['mime_type'] ) { |
3107 } |
3289 echo ' (' . $meta['mime_type'] . ')'; |
3108 } else { |
3290 } |
3109 echo strtoupper( str_replace( 'image/', '', $post->post_mime_type ) ); |
3291 } |
3110 } |
3292 } else { |
3111 ?> |
3293 echo strtoupper( str_replace( 'image/', '', $post->post_mime_type ) ); |
|
3294 } |
|
3295 |
|
3296 ?> |
3112 </strong> |
3297 </strong> |
3113 </div> |
3298 </div> |
3114 |
3299 |
3115 <?php |
3300 <?php |
3116 $file_size = false; |
3301 |
|
3302 $file_size = false; |
3117 |
3303 |
3118 if ( isset( $meta['filesize'] ) ) { |
3304 if ( isset( $meta['filesize'] ) ) { |
3119 $file_size = $meta['filesize']; |
3305 $file_size = $meta['filesize']; |
3120 } elseif ( file_exists( $file ) ) { |
3306 } elseif ( file_exists( $file ) ) { |
3121 $file_size = filesize( $file ); |
3307 $file_size = filesize( $file ); |
3122 } |
3308 } |
3123 |
3309 |
3124 if ( ! empty( $file_size ) ) : |
3310 if ( ! empty( $file_size ) ) { |
3125 ?> |
3311 ?> |
3126 <div class="misc-pub-section misc-pub-filesize"> |
3312 <div class="misc-pub-section misc-pub-filesize"> |
3127 <?php _e( 'File size:' ); ?> <strong><?php echo size_format( $file_size ); ?></strong> |
3313 <?php _e( 'File size:' ); ?> <strong><?php echo size_format( $file_size ); ?></strong> |
3128 </div> |
3314 </div> |
3129 <?php |
3315 <?php |
3130 endif; |
3316 } |
3131 |
3317 |
3132 if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) { |
3318 if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) { |
3133 $fields = array( |
3319 $fields = array( |
3134 'length_formatted' => __( 'Length:' ), |
3320 'length_formatted' => __( 'Length:' ), |
3135 'bitrate' => __( 'Bitrate:' ), |
3321 'bitrate' => __( 'Bitrate:' ), |
3277 if ( ! defined( 'GETID3_TEMP_DIR' ) ) { |
3479 if ( ! defined( 'GETID3_TEMP_DIR' ) ) { |
3278 define( 'GETID3_TEMP_DIR', get_temp_dir() ); |
3480 define( 'GETID3_TEMP_DIR', get_temp_dir() ); |
3279 } |
3481 } |
3280 |
3482 |
3281 if ( ! class_exists( 'getID3', false ) ) { |
3483 if ( ! class_exists( 'getID3', false ) ) { |
3282 require( ABSPATH . WPINC . '/ID3/getid3.php' ); |
3484 require ABSPATH . WPINC . '/ID3/getid3.php'; |
3283 } |
3485 } |
|
3486 |
3284 $id3 = new getID3(); |
3487 $id3 = new getID3(); |
3285 $data = $id3->analyze( $file ); |
3488 $data = $id3->analyze( $file ); |
3286 |
3489 |
3287 if ( isset( $data['video']['lossless'] ) ) { |
3490 if ( isset( $data['video']['lossless'] ) ) { |
3288 $metadata['lossless'] = $data['video']['lossless']; |
3491 $metadata['lossless'] = $data['video']['lossless']; |
3289 } |
3492 } |
|
3493 |
3290 if ( ! empty( $data['video']['bitrate'] ) ) { |
3494 if ( ! empty( $data['video']['bitrate'] ) ) { |
3291 $metadata['bitrate'] = (int) $data['video']['bitrate']; |
3495 $metadata['bitrate'] = (int) $data['video']['bitrate']; |
3292 } |
3496 } |
|
3497 |
3293 if ( ! empty( $data['video']['bitrate_mode'] ) ) { |
3498 if ( ! empty( $data['video']['bitrate_mode'] ) ) { |
3294 $metadata['bitrate_mode'] = $data['video']['bitrate_mode']; |
3499 $metadata['bitrate_mode'] = $data['video']['bitrate_mode']; |
3295 } |
3500 } |
|
3501 |
3296 if ( ! empty( $data['filesize'] ) ) { |
3502 if ( ! empty( $data['filesize'] ) ) { |
3297 $metadata['filesize'] = (int) $data['filesize']; |
3503 $metadata['filesize'] = (int) $data['filesize']; |
3298 } |
3504 } |
|
3505 |
3299 if ( ! empty( $data['mime_type'] ) ) { |
3506 if ( ! empty( $data['mime_type'] ) ) { |
3300 $metadata['mime_type'] = $data['mime_type']; |
3507 $metadata['mime_type'] = $data['mime_type']; |
3301 } |
3508 } |
|
3509 |
3302 if ( ! empty( $data['playtime_seconds'] ) ) { |
3510 if ( ! empty( $data['playtime_seconds'] ) ) { |
3303 $metadata['length'] = (int) round( $data['playtime_seconds'] ); |
3511 $metadata['length'] = (int) round( $data['playtime_seconds'] ); |
3304 } |
3512 } |
|
3513 |
3305 if ( ! empty( $data['playtime_string'] ) ) { |
3514 if ( ! empty( $data['playtime_string'] ) ) { |
3306 $metadata['length_formatted'] = $data['playtime_string']; |
3515 $metadata['length_formatted'] = $data['playtime_string']; |
3307 } |
3516 } |
|
3517 |
3308 if ( ! empty( $data['video']['resolution_x'] ) ) { |
3518 if ( ! empty( $data['video']['resolution_x'] ) ) { |
3309 $metadata['width'] = (int) $data['video']['resolution_x']; |
3519 $metadata['width'] = (int) $data['video']['resolution_x']; |
3310 } |
3520 } |
|
3521 |
3311 if ( ! empty( $data['video']['resolution_y'] ) ) { |
3522 if ( ! empty( $data['video']['resolution_y'] ) ) { |
3312 $metadata['height'] = (int) $data['video']['resolution_y']; |
3523 $metadata['height'] = (int) $data['video']['resolution_y']; |
3313 } |
3524 } |
|
3525 |
3314 if ( ! empty( $data['fileformat'] ) ) { |
3526 if ( ! empty( $data['fileformat'] ) ) { |
3315 $metadata['fileformat'] = $data['fileformat']; |
3527 $metadata['fileformat'] = $data['fileformat']; |
3316 } |
3528 } |
|
3529 |
3317 if ( ! empty( $data['video']['dataformat'] ) ) { |
3530 if ( ! empty( $data['video']['dataformat'] ) ) { |
3318 $metadata['dataformat'] = $data['video']['dataformat']; |
3531 $metadata['dataformat'] = $data['video']['dataformat']; |
3319 } |
3532 } |
|
3533 |
3320 if ( ! empty( $data['video']['encoder'] ) ) { |
3534 if ( ! empty( $data['video']['encoder'] ) ) { |
3321 $metadata['encoder'] = $data['video']['encoder']; |
3535 $metadata['encoder'] = $data['video']['encoder']; |
3322 } |
3536 } |
|
3537 |
3323 if ( ! empty( $data['video']['codec'] ) ) { |
3538 if ( ! empty( $data['video']['codec'] ) ) { |
3324 $metadata['codec'] = $data['video']['codec']; |
3539 $metadata['codec'] = $data['video']['codec']; |
3325 } |
3540 } |
3326 |
3541 |
3327 if ( ! empty( $data['audio'] ) ) { |
3542 if ( ! empty( $data['audio'] ) ) { |
3482 } |
3703 } |
3483 |
3704 |
3484 if ( ! current_user_can( 'edit_post', $parent_id ) ) { |
3705 if ( ! current_user_can( 'edit_post', $parent_id ) ) { |
3485 wp_die( __( 'Sorry, you are not allowed to edit this post.' ) ); |
3706 wp_die( __( 'Sorry, you are not allowed to edit this post.' ) ); |
3486 } |
3707 } |
|
3708 |
3487 $ids = array(); |
3709 $ids = array(); |
3488 foreach ( (array) $_REQUEST['media'] as $att_id ) { |
3710 |
3489 $att_id = (int) $att_id; |
3711 foreach ( (array) $_REQUEST['media'] as $attachment_id ) { |
3490 |
3712 $attachment_id = (int) $attachment_id; |
3491 if ( ! current_user_can( 'edit_post', $att_id ) ) { |
3713 |
|
3714 if ( ! current_user_can( 'edit_post', $attachment_id ) ) { |
3492 continue; |
3715 continue; |
3493 } |
3716 } |
3494 |
3717 |
3495 $ids[] = $att_id; |
3718 $ids[] = $attachment_id; |
3496 } |
3719 } |
3497 |
3720 |
3498 if ( ! empty( $ids ) ) { |
3721 if ( ! empty( $ids ) ) { |
3499 $ids_string = implode( ',', $ids ); |
3722 $ids_string = implode( ',', $ids ); |
|
3723 |
3500 if ( 'attach' === $action ) { |
3724 if ( 'attach' === $action ) { |
3501 $result = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'attachment' AND ID IN ( $ids_string )", $parent_id ) ); |
3725 $result = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'attachment' AND ID IN ( $ids_string )", $parent_id ) ); |
3502 } else { |
3726 } else { |
3503 $result = $wpdb->query( "UPDATE $wpdb->posts SET post_parent = 0 WHERE post_type = 'attachment' AND ID IN ( $ids_string )" ); |
3727 $result = $wpdb->query( "UPDATE $wpdb->posts SET post_parent = 0 WHERE post_type = 'attachment' AND ID IN ( $ids_string )" ); |
3504 } |
3728 } |
3505 |
|
3506 foreach ( $ids as $att_id ) { |
|
3507 clean_attachment_cache( $att_id ); |
|
3508 } |
|
3509 } |
3729 } |
3510 |
3730 |
3511 if ( isset( $result ) ) { |
3731 if ( isset( $result ) ) { |
|
3732 foreach ( $ids as $attachment_id ) { |
|
3733 /** |
|
3734 * Fires when media is attached or detached from a post. |
|
3735 * |
|
3736 * @since 5.5.0 |
|
3737 * |
|
3738 * @param string $action Attach/detach action. Accepts 'attach' or 'detach'. |
|
3739 * @param int $attachment_id The attachment ID. |
|
3740 * @param int $parent_id Attachment parent ID. |
|
3741 */ |
|
3742 do_action( 'wp_media_attach_action', $action, $attachment_id, $parent_id ); |
|
3743 |
|
3744 clean_attachment_cache( $attachment_id ); |
|
3745 } |
|
3746 |
3512 $location = 'upload.php'; |
3747 $location = 'upload.php'; |
3513 if ( $referer = wp_get_referer() ) { |
3748 $referer = wp_get_referer(); |
|
3749 |
|
3750 if ( $referer ) { |
3514 if ( false !== strpos( $referer, 'upload.php' ) ) { |
3751 if ( false !== strpos( $referer, 'upload.php' ) ) { |
3515 $location = remove_query_arg( array( 'attached', 'detach' ), $referer ); |
3752 $location = remove_query_arg( array( 'attached', 'detach' ), $referer ); |
3516 } |
3753 } |
3517 } |
3754 } |
3518 |
3755 |
3519 $key = 'attach' === $action ? 'attached' : 'detach'; |
3756 $key = 'attach' === $action ? 'attached' : 'detach'; |
3520 $location = add_query_arg( array( $key => $result ), $location ); |
3757 $location = add_query_arg( array( $key => $result ), $location ); |
|
3758 |
3521 wp_redirect( $location ); |
3759 wp_redirect( $location ); |
3522 exit; |
3760 exit; |
3523 } |
3761 } |
3524 } |
3762 } |