Changeset 42343 for trunk/src/wp-includes/media.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/media.php (modified) (117 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r42228 r42343 60 60 $_wp_additional_image_sizes = wp_get_additional_image_sizes(); 61 61 62 if ( ! $context ) 62 if ( ! $context ) { 63 63 $context = is_admin() ? 'edit' : 'display'; 64 65 if ( is_array($size) ) { 66 $max_width = $size[0]; 64 } 65 66 if ( is_array( $size ) ) { 67 $max_width = $size[0]; 67 68 $max_height = $size[1]; 68 } 69 elseif ( $size == 'thumb' || $size == 'thumbnail' ) { 70 $max_width = intval(get_option('thumbnail_size_w')); 71 $max_height = intval(get_option('thumbnail_size_h')); 69 } elseif ( $size == 'thumb' || $size == 'thumbnail' ) { 70 $max_width = intval( get_option( 'thumbnail_size_w' ) ); 71 $max_height = intval( get_option( 'thumbnail_size_h' ) ); 72 72 // last chance thumbnail size defaults 73 if ( ! $max_width && !$max_height ) {74 $max_width = 128;73 if ( ! $max_width && ! $max_height ) { 74 $max_width = 128; 75 75 $max_height = 96; 76 76 } 77 } 78 elseif ( $size == 'medium' ) { 79 $max_width = intval(get_option('medium_size_w')); 80 $max_height = intval(get_option('medium_size_h')); 81 82 } 83 elseif ( $size == 'medium_large' ) { 84 $max_width = intval( get_option( 'medium_large_size_w' ) ); 77 } elseif ( $size == 'medium' ) { 78 $max_width = intval( get_option( 'medium_size_w' ) ); 79 $max_height = intval( get_option( 'medium_size_h' ) ); 80 81 } elseif ( $size == 'medium_large' ) { 82 $max_width = intval( get_option( 'medium_large_size_w' ) ); 85 83 $max_height = intval( get_option( 'medium_large_size_h' ) ); 86 84 … … 88 86 $max_width = min( intval( $content_width ), $max_width ); 89 87 } 90 } 91 elseif ( $size == 'large' ) { 88 } elseif ( $size == 'large' ) { 92 89 /* 93 90 * We're inserting a large size image into the editor. If it's a really … … 96 93 * can resize it in the editor if they wish. 97 94 */ 98 $max_width = intval(get_option('large_size_w'));99 $max_height = intval( get_option('large_size_h'));100 if ( intval( $content_width) > 0 ) {101 $max_width = min( intval( $content_width), $max_width );95 $max_width = intval( get_option( 'large_size_w' ) ); 96 $max_height = intval( get_option( 'large_size_h' ) ); 97 if ( intval( $content_width ) > 0 ) { 98 $max_width = min( intval( $content_width ), $max_width ); 102 99 } 103 100 } elseif ( ! empty( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) ) ) { 104 $max_width = intval( $_wp_additional_image_sizes[$size]['width'] );105 $max_height = intval( $_wp_additional_image_sizes[ $size]['height'] );101 $max_width = intval( $_wp_additional_image_sizes[ $size ]['width'] ); 102 $max_height = intval( $_wp_additional_image_sizes[ $size ]['height'] ); 106 103 // Only in admin. Assume that theme authors know what they're doing. 107 104 if ( intval( $content_width ) > 0 && 'edit' === $context ) { 108 105 $max_width = min( intval( $content_width ), $max_width ); 109 106 } 110 } 111 // $size == 'full' has no constraint 107 } // $size == 'full' has no constraint 112 108 else { 113 $max_width = $width;109 $max_width = $width; 114 110 $max_height = $height; 115 111 } … … 151 147 function image_hwstring( $width, $height ) { 152 148 $out = ''; 153 if ($width) 154 $out .= 'width="'.intval($width).'" '; 155 if ($height) 156 $out .= 'height="'.intval($height).'" '; 149 if ( $width ) { 150 $out .= 'width="' . intval( $width ) . '" '; 151 } 152 if ( $height ) { 153 $out .= 'height="' . intval( $height ) . '" '; 154 } 157 155 return $out; 158 156 } … … 203 201 } 204 202 205 $img_url = wp_get_attachment_url($id);206 $meta = wp_get_attachment_metadata($id);207 $width = $height = 0;208 $is_intermediate = false;209 $img_url_basename = wp_basename( $img_url);203 $img_url = wp_get_attachment_url( $id ); 204 $meta = wp_get_attachment_metadata( $id ); 205 $width = $height = 0; 206 $is_intermediate = false; 207 $img_url_basename = wp_basename( $img_url ); 210 208 211 209 // If the file isn't an image, attempt to replace its URL with a rendered image from its meta. … … 213 211 if ( ! $is_image ) { 214 212 if ( ! empty( $meta['sizes'] ) ) { 215 $img_url = str_replace( $img_url_basename, $meta['sizes']['full']['file'], $img_url );213 $img_url = str_replace( $img_url_basename, $meta['sizes']['full']['file'], $img_url ); 216 214 $img_url_basename = $meta['sizes']['full']['file']; 217 $width = $meta['sizes']['full']['width'];218 $height = $meta['sizes']['full']['height'];215 $width = $meta['sizes']['full']['width']; 216 $height = $meta['sizes']['full']['height']; 219 217 } else { 220 218 return false; … … 223 221 224 222 // try for a new style intermediate size 225 if ( $intermediate = image_get_intermediate_size( $id, $size) ) {226 $img_url = str_replace($img_url_basename, $intermediate['file'], $img_url);227 $width = $intermediate['width'];228 $height = $intermediate['height'];223 if ( $intermediate = image_get_intermediate_size( $id, $size ) ) { 224 $img_url = str_replace( $img_url_basename, $intermediate['file'], $img_url ); 225 $width = $intermediate['width']; 226 $height = $intermediate['height']; 229 227 $is_intermediate = true; 230 } 231 elseif ( $size == 'thumbnail' ) { 228 } elseif ( $size == 'thumbnail' ) { 232 229 // fall back to the old thumbnail 233 if ( ( $thumb_file = wp_get_attachment_thumb_file($id)) && $info = getimagesize($thumb_file) ) {234 $img_url = str_replace($img_url_basename, wp_basename($thumb_file), $img_url);235 $width = $info[0];236 $height = $info[1];230 if ( ( $thumb_file = wp_get_attachment_thumb_file( $id ) ) && $info = getimagesize( $thumb_file ) ) { 231 $img_url = str_replace( $img_url_basename, wp_basename( $thumb_file ), $img_url ); 232 $width = $info[0]; 233 $height = $info[1]; 237 234 $is_intermediate = true; 238 235 } 239 236 } 240 if ( ! $width && !$height && isset( $meta['width'], $meta['height'] ) ) {237 if ( ! $width && ! $height && isset( $meta['width'], $meta['height'] ) ) { 241 238 // any other type: use the real image 242 $width = $meta['width'];239 $width = $meta['width']; 243 240 $height = $meta['height']; 244 241 } 245 242 246 if ( $img_url ) {243 if ( $img_url ) { 247 244 // we have the actual image size, but might need to further constrain it if content_width is narrower 248 245 list( $width, $height ) = image_constrain_size_for_editor( $width, $height, $size ); … … 360 357 function get_image_tag( $id, $alt, $title, $align, $size = 'medium' ) { 361 358 362 list( $img_src, $width, $height ) = image_downsize( $id, $size);363 $hwstring = image_hwstring($width, $height);359 list( $img_src, $width, $height ) = image_downsize( $id, $size ); 360 $hwstring = image_hwstring( $width, $height ); 364 361 365 362 $title = $title ? 'title="' . esc_attr( $title ) . '" ' : ''; 366 363 367 $class = 'align' . esc_attr( $align) .' size-' . esc_attr($size) . ' wp-image-' . $id;364 $class = 'align' . esc_attr( $align ) . ' size-' . esc_attr( $size ) . ' wp-image-' . $id; 368 365 369 366 /** … … 380 377 $class = apply_filters( 'get_image_tag_class', $class, $id, $align, $size ); 381 378 382 $html = '<img src="' . esc_attr( $img_src) . '" alt="' . esc_attr($alt) . '" ' . $title . $hwstring . 'class="' . $class . '" />';379 $html = '<img src="' . esc_attr( $img_src ) . '" alt="' . esc_attr( $alt ) . '" ' . $title . $hwstring . 'class="' . $class . '" />'; 383 380 384 381 /** … … 413 410 */ 414 411 function wp_constrain_dimensions( $current_width, $current_height, $max_width = 0, $max_height = 0 ) { 415 if ( ! $max_width && !$max_height )412 if ( ! $max_width && ! $max_height ) { 416 413 return array( $current_width, $current_height ); 414 } 417 415 418 416 $width_ratio = $height_ratio = 1.0; 419 $did_width = $did_height = false;417 $did_width = $did_height = false; 420 418 421 419 if ( $max_width > 0 && $current_width > 0 && $current_width > $max_width ) { 422 420 $width_ratio = $max_width / $current_width; 423 $did_width = true;421 $did_width = true; 424 422 } 425 423 426 424 if ( $max_height > 0 && $current_height > 0 && $current_height > $max_height ) { 427 425 $height_ratio = $max_height / $current_height; 428 $did_height = true;426 $did_height = true; 429 427 } 430 428 … … 434 432 435 433 if ( (int) round( $current_width * $larger_ratio ) > $max_width || (int) round( $current_height * $larger_ratio ) > $max_height ) { 436 // The larger ratio is too big. It would result in an overflow.434 // The larger ratio is too big. It would result in an overflow. 437 435 $ratio = $smaller_ratio; 438 436 } else { … … 442 440 443 441 // Very small dimensions may result in 0, 1 should be the minimum. 444 $w = max ( 1, (int) round( $current_width* $ratio ) );445 $h = max ( 1, (int) round( $current_height * $ratio ) );442 $w = max( 1, (int) round( $current_width * $ratio ) ); 443 $h = max( 1, (int) round( $current_height * $ratio ) ); 446 444 447 445 // Sometimes, due to rounding, we'll end up with a result like this: 465x700 in a 177x177 box is 117x176... a pixel short … … 465 463 * 466 464 * @param array $dimensions The image width and height. 467 * @param int $current_width The current width of the image.468 * @param int $current_height The current height of the image.469 * @param int $max_width The maximum width permitted.470 * @param int $max_height The maximum height permitted.465 * @param int $current_width The current width of the image. 466 * @param int $current_height The current height of the image. 467 * @param int $max_width The maximum width permitted. 468 * @param int $max_height The maximum height permitted. 471 469 */ 472 470 return apply_filters( 'wp_constrain_dimensions', array( $w, $h ), $current_width, $current_height, $max_width, $max_height ); … … 499 497 function image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, $crop = false ) { 500 498 501 if ( $orig_w <= 0 || $orig_h <= 0)499 if ( $orig_w <= 0 || $orig_h <= 0 ) { 502 500 return false; 501 } 503 502 // at least one of dest_w or dest_h must be specific 504 if ( $dest_w <= 0 && $dest_h <= 0)503 if ( $dest_w <= 0 && $dest_h <= 0 ) { 505 504 return false; 505 } 506 506 507 507 /** … … 522 522 */ 523 523 $output = apply_filters( 'image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop ); 524 if ( null !== $output ) 524 if ( null !== $output ) { 525 525 return $output; 526 } 526 527 527 528 if ( $crop ) { 528 529 // crop the largest possible portion of the original image that we can size to $dest_w x $dest_h 529 530 $aspect_ratio = $orig_w / $orig_h; 530 $new_w = min($dest_w, $orig_w);531 $new_h = min($dest_h, $orig_h);531 $new_w = min( $dest_w, $orig_w ); 532 $new_h = min( $dest_h, $orig_h ); 532 533 533 534 if ( ! $new_w ) { … … 539 540 } 540 541 541 $size_ratio = max( $new_w / $orig_w, $new_h / $orig_h);542 543 $crop_w = round( $new_w / $size_ratio);544 $crop_h = round( $new_h / $size_ratio);542 $size_ratio = max( $new_w / $orig_w, $new_h / $orig_h ); 543 544 $crop_w = round( $new_w / $size_ratio ); 545 $crop_h = round( $new_h / $size_ratio ); 545 546 546 547 if ( ! is_array( $crop ) || count( $crop ) !== 2 ) { … … 607 608 $editor = wp_get_image_editor( $file ); 608 609 609 if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) 610 if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) { 610 611 return false; 612 } 611 613 612 614 $resized_file = $editor->save(); … … 638 640 if ( $source_width > $target_width ) { 639 641 $constrained_size = wp_constrain_dimensions( $source_width, $source_height, $target_width ); 640 $expected_size = array( $target_width, $target_height );642 $expected_size = array( $target_width, $target_height ); 641 643 } else { 642 644 $constrained_size = wp_constrain_dimensions( $target_width, $target_height, $source_width ); 643 $expected_size = array( $source_width, $source_height );645 $expected_size = array( $source_width, $source_height ); 644 646 } 645 647 … … 687 689 */ 688 690 function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { 689 if ( ! $size || ! is_array( $imagedata = wp_get_attachment_metadata( $post_id ) ) || empty( $imagedata['sizes'] ) ) {691 if ( ! $size || ! is_array( $imagedata = wp_get_attachment_metadata( $post_id ) ) || empty( $imagedata['sizes'] ) ) { 690 692 return false; 691 693 } … … 731 733 732 734 $data = array_shift( $candidates ); 733 /*734 * When the size requested is smaller than the thumbnail dimensions, we735 * fall back to the thumbnail size to maintain backwards compatibility with736 * pre 4.6 versions of WordPress.737 */735 /* 736 * When the size requested is smaller than the thumbnail dimensions, we 737 * fall back to the thumbnail size to maintain backwards compatibility with 738 * pre 4.6 versions of WordPress. 739 */ 738 740 } elseif ( ! empty( $imagedata['sizes']['thumbnail'] ) && $imagedata['sizes']['thumbnail']['width'] >= $size[0] && $imagedata['sizes']['thumbnail']['width'] >= $size[1] ) { 739 741 $data = $imagedata['sizes']['thumbnail']; … … 756 758 // include the full filesystem path of the intermediate file 757 759 if ( empty( $data['path'] ) && ! empty( $data['file'] ) && ! empty( $imagedata['file'] ) ) { 758 $file_url = wp_get_attachment_url($post_id);759 $data['path'] = path_join( dirname( $imagedata['file']), $data['file'] );760 $data['url'] = path_join( dirname($file_url), $data['file'] );760 $file_url = wp_get_attachment_url( $post_id ); 761 $data['path'] = path_join( dirname( $imagedata['file'] ), $data['file'] ); 762 $data['url'] = path_join( dirname( $file_url ), $data['file'] ); 761 763 } 762 764 … … 786 788 function get_intermediate_image_sizes() { 787 789 $_wp_additional_image_sizes = wp_get_additional_image_sizes(); 788 $image_sizes = array('thumbnail', 'medium', 'medium_large', 'large'); // Standard sizes790 $image_sizes = array( 'thumbnail', 'medium', 'medium_large', 'large' ); // Standard sizes 789 791 if ( ! empty( $_wp_additional_image_sizes ) ) { 790 792 $image_sizes = array_merge( $image_sizes, array_keys( $_wp_additional_image_sizes ) ); … … 830 832 $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' ); 831 833 832 $src_file = $icon_dir . '/' . wp_basename( $src );834 $src_file = $icon_dir . '/' . wp_basename( $src ); 833 835 @list( $width, $height ) = getimagesize( $src_file ); 834 836 } … … 869 871 * @return string HTML img element or empty string on failure. 870 872 */ 871 function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = false, $attr = '') {872 $html = '';873 $image = wp_get_attachment_image_src( $attachment_id, $size, $icon);873 function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = false, $attr = '' ) { 874 $html = ''; 875 $image = wp_get_attachment_image_src( $attachment_id, $size, $icon ); 874 876 if ( $image ) { 875 877 list($src, $width, $height) = $image; 876 $hwstring = image_hwstring($width, $height);877 $size_class = $size;878 $hwstring = image_hwstring( $width, $height ); 879 $size_class = $size; 878 880 if ( is_array( $size_class ) ) { 879 881 $size_class = join( 'x', $size_class ); 880 882 } 881 $attachment = get_post($attachment_id);883 $attachment = get_post( $attachment_id ); 882 884 $default_attr = array( 883 'src' => $src,884 'class' => "attachment-$size_class size-$size_class",885 'alt' => trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ),885 'src' => $src, 886 'class' => "attachment-$size_class size-$size_class", 887 'alt' => trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ), 886 888 ); 887 889 … … 894 896 if ( is_array( $image_meta ) ) { 895 897 $size_array = array( absint( $width ), absint( $height ) ); 896 $srcset = wp_calculate_image_srcset( $size_array, $src, $image_meta, $attachment_id );897 $sizes = wp_calculate_image_sizes( $size_array, $src, $image_meta, $attachment_id );898 $srcset = wp_calculate_image_srcset( $size_array, $src, $image_meta, $attachment_id ); 899 $sizes = wp_calculate_image_sizes( $size_array, $src, $image_meta, $attachment_id ); 898 900 899 901 if ( $srcset && ( $sizes || ! empty( $attr['sizes'] ) ) ) { … … 919 921 $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $size ); 920 922 $attr = array_map( 'esc_attr', $attr ); 921 $html = rtrim( "<img $hwstring");923 $html = rtrim( "<img $hwstring" ); 922 924 foreach ( $attr as $name => $value ) { 923 925 $html .= " $name=" . '"' . $value . '"'; … … 989 991 absint( $image_meta['height'] ), 990 992 ); 991 } elseif ( ! empty( $image_meta['sizes'][ $size_name] ) ) {993 } elseif ( ! empty( $image_meta['sizes'][ $size_name ] ) ) { 992 994 return array( 993 absint( $image_meta['sizes'][ $size_name]['width'] ),994 absint( $image_meta['sizes'][ $size_name]['height'] ),995 absint( $image_meta['sizes'][ $size_name ]['width'] ), 996 absint( $image_meta['sizes'][ $size_name ]['height'] ), 995 997 ); 996 998 } … … 1022 1024 } 1023 1025 1024 $image_src = $image[0];1026 $image_src = $image[0]; 1025 1027 $size_array = array( 1026 1028 absint( $image[1] ), 1027 absint( $image[2] ) 1029 absint( $image[2] ), 1028 1030 ); 1029 1031 … … 1062 1064 1063 1065 // Get the width and height of the image. 1064 $image_width = (int) $size_array[0];1066 $image_width = (int) $size_array[0]; 1065 1067 $image_height = (int) $size_array[1]; 1066 1068 … … 1094 1096 } 1095 1097 1096 $upload_dir = wp_get_upload_dir();1098 $upload_dir = wp_get_upload_dir(); 1097 1099 $image_baseurl = trailingslashit( $upload_dir['baseurl'] ) . $dirname; 1098 1100 … … 1240 1242 } 1241 1243 1242 $image_src = $image[0];1244 $image_src = $image[0]; 1243 1245 $size_array = array( 1244 1246 absint( $image[1] ), 1245 absint( $image[2] ) 1247 absint( $image[2] ), 1246 1248 ); 1247 1249 … … 1320 1322 $selected_images = $attachment_ids = array(); 1321 1323 1322 foreach ( $matches[0] as $image ) {1324 foreach ( $matches[0] as $image ) { 1323 1325 if ( false === strpos( $image, ' srcset=' ) && preg_match( '/wp-image-([0-9]+)/i', $image, $class_id ) && 1324 1326 ( $attachment_id = absint( $class_id[1] ) ) ) { … … 1344 1346 foreach ( $selected_images as $image => $attachment_id ) { 1345 1347 $image_meta = wp_get_attachment_metadata( $attachment_id ); 1346 $content = str_replace( $image, wp_image_add_srcset_and_sizes( $image, $image_meta, $attachment_id ), $content );1348 $content = str_replace( $image, wp_image_add_srcset_and_sizes( $image, $image_meta, $attachment_id ), $content ); 1347 1349 } 1348 1350 … … 1369 1371 } 1370 1372 1371 $image_src = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : '';1373 $image_src = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : ''; 1372 1374 list( $image_src ) = explode( '?', $image_src ); 1373 1375 … … 1384 1386 } 1385 1387 1386 $width = preg_match( '/ width="([0-9]+)"/', $image, $match_width ) ? (int) $match_width[1]: 0;1388 $width = preg_match( '/ width="([0-9]+)"/', $image, $match_width ) ? (int) $match_width[1] : 0; 1387 1389 $height = preg_match( '/ height="([0-9]+)"/', $image, $match_height ) ? (int) $match_height[1] : 0; 1388 1390 … … 1395 1397 1396 1398 if ( $image_filename === wp_basename( $image_meta['file'] ) ) { 1397 $width = (int) $image_meta['width'];1399 $width = (int) $image_meta['width']; 1398 1400 $height = (int) $image_meta['height']; 1399 1401 } else { 1400 foreach ( $image_meta['sizes'] as $image_size_data ) {1402 foreach ( $image_meta['sizes'] as $image_size_data ) { 1401 1403 if ( $image_filename === $image_size_data['file'] ) { 1402 $width = (int) $image_size_data['width'];1404 $width = (int) $image_size_data['width']; 1403 1405 $height = (int) $image_size_data['height']; 1404 1406 break; … … 1413 1415 1414 1416 $size_array = array( $width, $height ); 1415 $srcset = wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id );1417 $srcset = wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id ); 1416 1418 1417 1419 if ( $srcset ) { … … 1482 1484 } 1483 1485 1484 add_shortcode( 'wp_caption', 'img_caption_shortcode');1485 add_shortcode( 'caption', 'img_caption_shortcode');1486 add_shortcode( 'wp_caption', 'img_caption_shortcode' ); 1487 add_shortcode( 'caption', 'img_caption_shortcode' ); 1486 1488 1487 1489 /** … … 1514 1516 if ( ! isset( $attr['caption'] ) ) { 1515 1517 if ( preg_match( '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches ) ) { 1516 $content = $matches[1];1518 $content = $matches[1]; 1517 1519 $attr['caption'] = trim( $matches[2] ); 1518 1520 } … … 1536 1538 */ 1537 1539 $output = apply_filters( 'img_caption_shortcode', '', $attr, $content ); 1538 if ( $output != '' ) 1540 if ( $output != '' ) { 1539 1541 return $output; 1540 1541 $atts = shortcode_atts( array( 1542 'id' => '', 1543 'align' => 'alignnone', 1544 'width' => '', 1545 'caption' => '', 1546 'class' => '', 1547 ), $attr, 'caption' ); 1542 } 1543 1544 $atts = shortcode_atts( 1545 array( 1546 'id' => '', 1547 'align' => 'alignnone', 1548 'width' => '', 1549 'caption' => '', 1550 'class' => '', 1551 ), $attr, 'caption' 1552 ); 1548 1553 1549 1554 $atts['width'] = (int) $atts['width']; 1550 if ( $atts['width'] < 1 || empty( $atts['caption'] ) ) 1555 if ( $atts['width'] < 1 || empty( $atts['caption'] ) ) { 1551 1556 return $content; 1552 1553 if ( ! empty( $atts['id'] ) ) 1557 } 1558 1559 if ( ! empty( $atts['id'] ) ) { 1554 1560 $atts['id'] = 'id="' . esc_attr( sanitize_html_class( $atts['id'] ) ) . '" '; 1561 } 1555 1562 1556 1563 $class = trim( 'wp-caption ' . $atts['align'] . ' ' . $atts['class'] ); … … 1593 1600 } 1594 1601 1595 add_shortcode( 'gallery', 'gallery_shortcode');1602 add_shortcode( 'gallery', 'gallery_shortcode' ); 1596 1603 1597 1604 /** … … 1664 1671 1665 1672 $html5 = current_theme_supports( 'html5', 'gallery' ); 1666 $atts = shortcode_atts( array( 1667 'order' => 'ASC', 1668 'orderby' => 'menu_order ID', 1669 'id' => $post ? $post->ID : 0, 1670 'itemtag' => $html5 ? 'figure' : 'dl', 1671 'icontag' => $html5 ? 'div' : 'dt', 1672 'captiontag' => $html5 ? 'figcaption' : 'dd', 1673 'columns' => 3, 1674 'size' => 'thumbnail', 1675 'include' => '', 1676 'exclude' => '', 1677 'link' => '' 1678 ), $attr, 'gallery' ); 1673 $atts = shortcode_atts( 1674 array( 1675 'order' => 'ASC', 1676 'orderby' => 'menu_order ID', 1677 'id' => $post ? $post->ID : 0, 1678 'itemtag' => $html5 ? 'figure' : 'dl', 1679 'icontag' => $html5 ? 'div' : 'dt', 1680 'captiontag' => $html5 ? 'figcaption' : 'dd', 1681 'columns' => 3, 1682 'size' => 'thumbnail', 1683 'include' => '', 1684 'exclude' => '', 1685 'link' => '', 1686 ), $attr, 'gallery' 1687 ); 1679 1688 1680 1689 $id = intval( $atts['id'] ); 1681 1690 1682 1691 if ( ! empty( $atts['include'] ) ) { 1683 $_attachments = get_posts( array( 'include' => $atts['include'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) ); 1692 $_attachments = get_posts( 1693 array( 1694 'include' => $atts['include'], 1695 'post_status' => 'inherit', 1696 'post_type' => 'attachment', 1697 'post_mime_type' => 'image', 1698 'order' => $atts['order'], 1699 'orderby' => $atts['orderby'], 1700 ) 1701 ); 1684 1702 1685 1703 $attachments = array(); 1686 1704 foreach ( $_attachments as $key => $val ) { 1687 $attachments[ $val->ID] = $_attachments[$key];1705 $attachments[ $val->ID ] = $_attachments[ $key ]; 1688 1706 } 1689 1707 } elseif ( ! empty( $atts['exclude'] ) ) { 1690 $attachments = get_children( array( 'post_parent' => $id, 'exclude' => $atts['exclude'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) ); 1708 $attachments = get_children( 1709 array( 1710 'post_parent' => $id, 1711 'exclude' => $atts['exclude'], 1712 'post_status' => 'inherit', 1713 'post_type' => 'attachment', 1714 'post_mime_type' => 'image', 1715 'order' => $atts['order'], 1716 'orderby' => $atts['orderby'], 1717 ) 1718 ); 1691 1719 } else { 1692 $attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) ); 1720 $attachments = get_children( 1721 array( 1722 'post_parent' => $id, 1723 'post_status' => 'inherit', 1724 'post_type' => 'attachment', 1725 'post_mime_type' => 'image', 1726 'order' => $atts['order'], 1727 'orderby' => $atts['orderby'], 1728 ) 1729 ); 1693 1730 } 1694 1731 … … 1705 1742 } 1706 1743 1707 $itemtag = tag_escape( $atts['itemtag'] );1744 $itemtag = tag_escape( $atts['itemtag'] ); 1708 1745 $captiontag = tag_escape( $atts['captiontag'] ); 1709 $icontag = tag_escape( $atts['icontag'] );1746 $icontag = tag_escape( $atts['icontag'] ); 1710 1747 $valid_tags = wp_kses_allowed_html( 'post' ); 1711 1748 if ( ! isset( $valid_tags[ $itemtag ] ) ) { … … 1719 1756 } 1720 1757 1721 $columns = intval( $atts['columns'] );1722 $itemwidth = $columns > 0 ? floor( 100/$columns) : 100;1723 $float = is_rtl() ? 'right' : 'left';1758 $columns = intval( $atts['columns'] ); 1759 $itemwidth = $columns > 0 ? floor( 100 / $columns ) : 100; 1760 $float = is_rtl() ? 'right' : 'left'; 1724 1761 1725 1762 $selector = "gallery-{$instance}"; … … 1758 1795 } 1759 1796 1760 $size_class = sanitize_html_class( $atts['size'] );1797 $size_class = sanitize_html_class( $atts['size'] ); 1761 1798 $gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>"; 1762 1799 … … 1782 1819 $image_output = wp_get_attachment_link( $id, $atts['size'], true, false, false, $attr ); 1783 1820 } 1784 $image_meta = wp_get_attachment_metadata( $id );1821 $image_meta = wp_get_attachment_metadata( $id ); 1785 1822 1786 1823 $orientation = ''; … … 1793 1830 $image_output 1794 1831 </{$icontag}>"; 1795 if ( $captiontag && trim( $attachment->post_excerpt) ) {1832 if ( $captiontag && trim( $attachment->post_excerpt ) ) { 1796 1833 $output .= " 1797 1834 <{$captiontag} class='wp-caption-text gallery-caption' id='$selector-$id'> 1798 " . wptexturize( $attachment->post_excerpt) . "1835 " . wptexturize( $attachment->post_excerpt ) . " 1799 1836 </{$captiontag}>"; 1800 1837 } … … 1828 1865 <# } #> 1829 1866 <div class="wp-playlist-caption"> 1830 <span class="wp-playlist-item-meta wp-playlist-item-title"><?php 1867 <span class="wp-playlist-item-meta wp-playlist-item-title"> 1868 <?php 1831 1869 /* translators: playlist item title */ 1832 1870 printf( _x( '“%s”', 'playlist item title' ), '{{ data.title }}' ); 1833 ?></span> 1871 ?> 1872 </span> 1834 1873 <# if ( data.meta.album ) { #><span class="wp-playlist-item-meta wp-playlist-item-album">{{ data.meta.album }}</span><# } #> 1835 1874 <# if ( data.meta.artist ) { #><span class="wp-playlist-item-meta wp-playlist-item-artist">{{ data.meta.artist }}</span><# } #> … … 1843 1882 {{ data.caption }} 1844 1883 <# } else { #> 1845 <span class="wp-playlist-item-title"><?php 1884 <span class="wp-playlist-item-title"> 1885 <?php 1846 1886 /* translators: playlist item title */ 1847 1887 printf( _x( '“%s”', 'playlist item title' ), '{{{ data.title }}}' ); 1848 ?></span> 1888 ?> 1889 </span> 1849 1890 <# if ( data.artists && data.meta.artist ) { #> 1850 1891 <span class="wp-playlist-item-artist"> — {{ data.meta.artist }}</span> … … 1871 1912 wp_enqueue_script( 'wp-playlist' ); 1872 1913 ?> 1873 <!--[if lt IE 9]><script>document.createElement('<?php echo esc_js( $type ) ?>');</script><![endif]-->1914 <!--[if lt IE 9]><script>document.createElement('<?php echo esc_js( $type ); ?>');</script><![endif]--> 1874 1915 <?php 1875 1916 add_action( 'wp_footer', 'wp_underscore_playlist_templates', 0 ); … … 1947 1988 } 1948 1989 1949 $atts = shortcode_atts( array( 1950 'type' => 'audio', 1951 'order' => 'ASC', 1952 'orderby' => 'menu_order ID', 1953 'id' => $post ? $post->ID : 0, 1954 'include' => '', 1955 'exclude' => '', 1956 'style' => 'light', 1957 'tracklist' => true, 1958 'tracknumbers' => true, 1959 'images' => true, 1960 'artists' => true 1961 ), $attr, 'playlist' ); 1990 $atts = shortcode_atts( 1991 array( 1992 'type' => 'audio', 1993 'order' => 'ASC', 1994 'orderby' => 'menu_order ID', 1995 'id' => $post ? $post->ID : 0, 1996 'include' => '', 1997 'exclude' => '', 1998 'style' => 'light', 1999 'tracklist' => true, 2000 'tracknumbers' => true, 2001 'images' => true, 2002 'artists' => true, 2003 ), $attr, 'playlist' 2004 ); 1962 2005 1963 2006 $id = intval( $atts['id'] ); … … 1968 2011 1969 2012 $args = array( 1970 'post_status' => 'inherit',1971 'post_type' => 'attachment',2013 'post_status' => 'inherit', 2014 'post_type' => 'attachment', 1972 2015 'post_mime_type' => $atts['type'], 1973 'order' => $atts['order'],1974 'orderby' => $atts['orderby']2016 'order' => $atts['order'], 2017 'orderby' => $atts['orderby'], 1975 2018 ); 1976 2019 1977 2020 if ( ! empty( $atts['include'] ) ) { 1978 2021 $args['include'] = $atts['include']; 1979 $_attachments = get_posts( $args );2022 $_attachments = get_posts( $args ); 1980 2023 1981 2024 $attachments = array(); 1982 2025 foreach ( $_attachments as $key => $val ) { 1983 $attachments[ $val->ID] = $_attachments[$key];2026 $attachments[ $val->ID ] = $_attachments[ $key ]; 1984 2027 } 1985 2028 } elseif ( ! empty( $atts['exclude'] ) ) { 1986 2029 $args['post_parent'] = $id; 1987 $args['exclude'] = $atts['exclude'];1988 $attachments = get_children( $args );2030 $args['exclude'] = $atts['exclude']; 2031 $attachments = get_children( $args ); 1989 2032 } else { 1990 2033 $args['post_parent'] = $id; 1991 $attachments = get_children( $args );2034 $attachments = get_children( $args ); 1992 2035 } 1993 2036 … … 2006 2049 $outer = 22; // default padding and border of wrapper 2007 2050 2008 $default_width = 640;2051 $default_width = 640; 2009 2052 $default_height = 360; 2010 2053 2011 $theme_width = empty( $content_width ) ? $default_width : ( $content_width - $outer );2054 $theme_width = empty( $content_width ) ? $default_width : ( $content_width - $outer ); 2012 2055 $theme_height = empty( $content_width ) ? $default_height : round( ( $default_height * $theme_width ) / $default_width ); 2013 2056 2014 2057 $data = array( 2015 'type' => $atts['type'],2058 'type' => $atts['type'], 2016 2059 // don't pass strings to JSON, will be truthy in JS 2017 'tracklist' => wp_validate_boolean( $atts['tracklist'] ),2060 'tracklist' => wp_validate_boolean( $atts['tracklist'] ), 2018 2061 'tracknumbers' => wp_validate_boolean( $atts['tracknumbers'] ), 2019 'images' => wp_validate_boolean( $atts['images'] ),2020 'artists' => wp_validate_boolean( $atts['artists'] ),2062 'images' => wp_validate_boolean( $atts['images'] ), 2063 'artists' => wp_validate_boolean( $atts['artists'] ), 2021 2064 ); 2022 2065 2023 2066 $tracks = array(); 2024 2067 foreach ( $attachments as $attachment ) { 2025 $url = wp_get_attachment_url( $attachment->ID );2068 $url = wp_get_attachment_url( $attachment->ID ); 2026 2069 $ftype = wp_check_filetype( $url, wp_get_mime_types() ); 2027 2070 $track = array( 2028 'src' => $url,2029 'type' => $ftype['type'],2030 'title' => $attachment->post_title,2031 'caption' => $attachment->post_excerpt,2032 'description' => $attachment->post_content 2071 'src' => $url, 2072 'type' => $ftype['type'], 2073 'title' => $attachment->post_title, 2074 'caption' => $attachment->post_excerpt, 2075 'description' => $attachment->post_content, 2033 2076 ); 2034 2077 2035 2078 $track['meta'] = array(); 2036 $meta = wp_get_attachment_metadata( $attachment->ID );2079 $meta = wp_get_attachment_metadata( $attachment->ID ); 2037 2080 if ( ! empty( $meta ) ) { 2038 2081 … … 2045 2088 if ( 'video' === $atts['type'] ) { 2046 2089 if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) { 2047 $width = $meta['width'];2048 $height = $meta['height'];2090 $width = $meta['width']; 2091 $height = $meta['height']; 2049 2092 $theme_height = round( ( $height * $theme_width ) / $width ); 2050 2093 } else { 2051 $width = $default_width;2094 $width = $default_width; 2052 2095 $height = $default_height; 2053 2096 } … … 2055 2098 $track['dimensions'] = array( 2056 2099 'original' => compact( 'width', 'height' ), 2057 'resized' => array(2058 'width' => $theme_width,2059 'height' => $theme_height 2060 ) 2100 'resized' => array( 2101 'width' => $theme_width, 2102 'height' => $theme_height, 2103 ), 2061 2104 ); 2062 2105 } … … 2067 2110 if ( ! empty( $thumb_id ) ) { 2068 2111 list( $src, $width, $height ) = wp_get_attachment_image_src( $thumb_id, 'full' ); 2069 $track['image'] = compact( 'src', 'width', 'height' );2112 $track['image'] = compact( 'src', 'width', 'height' ); 2070 2113 list( $src, $width, $height ) = wp_get_attachment_image_src( $thumb_id, 'thumbnail' ); 2071 $track['thumb'] = compact( 'src', 'width', 'height' );2114 $track['thumb'] = compact( 'src', 'width', 'height' ); 2072 2115 } else { 2073 $src = wp_mime_type_icon( $attachment->ID );2074 $width = 48;2075 $height = 64;2116 $src = wp_mime_type_icon( $attachment->ID ); 2117 $width = 48; 2118 $height = 64; 2076 2119 $track['image'] = compact( 'src', 'width', 'height' ); 2077 2120 $track['thumb'] = compact( 'src', 'width', 'height' ); … … 2083 2126 $data['tracks'] = $tracks; 2084 2127 2085 $safe_type = esc_attr( $atts['type'] );2128 $safe_type = esc_attr( $atts['type'] ); 2086 2129 $safe_style = esc_attr( $atts['style'] ); 2087 2130 … … 2098 2141 */ 2099 2142 do_action( 'wp_playlist_scripts', $atts['type'], $atts['style'] ); 2100 } ?> 2101 <div class="wp-playlist wp-<?php echo $safe_type ?>-playlist wp-playlist-<?php echo $safe_style ?>"> 2102 <?php if ( 'audio' === $atts['type'] ): ?> 2143 } 2144 ?> 2145 <div class="wp-playlist wp-<?php echo $safe_type; ?>-playlist wp-playlist-<?php echo $safe_style; ?>"> 2146 <?php if ( 'audio' === $atts['type'] ) : ?> 2103 2147 <div class="wp-playlist-current-item"></div> 2104 2148 <?php endif ?> 2105 <<?php echo $safe_type ?> controls="controls" preload="none" width="<?php 2106 echo (int) $theme_width; 2107 ?>"<?php if ( 'video' === $safe_type ): 2149 <<?php echo $safe_type; ?> controls="controls" preload="none" width=" 2150 <?php 2151 echo (int) $theme_width; 2152 ?> 2153 " 2154 <?php 2155 if ( 'video' === $safe_type ) : 2108 2156 echo ' height="', (int) $theme_height, '"'; 2109 endif; ?>></<?php echo $safe_type ?>> 2157 endif; 2158 ?> 2159 ></<?php echo $safe_type; ?>> 2110 2160 <div class="wp-playlist-next"></div> 2111 2161 <div class="wp-playlist-prev"></div> 2112 2162 <noscript> 2113 <ol><?php 2163 <ol> 2164 <?php 2114 2165 foreach ( $attachments as $att_id => $attachment ) { 2115 2166 printf( '<li>%s</li>', wp_get_attachment_link( $att_id ) ); 2116 2167 } 2117 ?></ol> 2168 ?> 2169 </ol> 2118 2170 </noscript> 2119 <script type="application/json" class="wp-playlist-script"><?php echo wp_json_encode( $data ) ?></script>2171 <script type="application/json" class="wp-playlist-script"><?php echo wp_json_encode( $data ); ?></script> 2120 2172 </div> 2121 2173 <?php … … 2175 2227 $fields = array( 2176 2228 'artist' => __( 'Artist' ), 2177 'album' => __( 'Album' ),2229 'album' => __( 'Album' ), 2178 2230 ); 2179 2231 … … 2183 2235 $fields['length_formatted'] = _x( 'Length', 'video or audio' ); 2184 2236 } elseif ( 'js' === $context ) { 2185 $fields['bitrate'] = __( 'Bitrate' );2186 $fields['bitrate_mode'] = __( 'Bitrate Mode' );2237 $fields['bitrate'] = __( 'Bitrate' ); 2238 $fields['bitrate_mode'] = __( 'Bitrate Mode' ); 2187 2239 } 2188 2240 … … 2253 2305 'preload' => 'none', 2254 2306 'class' => 'wp-audio-shortcode', 2255 'style' => 'width: 100%;' 2307 'style' => 'width: 100%;', 2256 2308 ); 2257 2309 foreach ( $default_types as $type ) { 2258 $defaults_atts[ $type] = '';2310 $defaults_atts[ $type ] = ''; 2259 2311 } 2260 2312 … … 2286 2338 } 2287 2339 2288 $audio = reset( $audios );2340 $audio = reset( $audios ); 2289 2341 $atts['src'] = wp_get_attachment_url( $audio->ID ); 2290 2342 if ( empty( $atts['src'] ) ) { … … 2330 2382 // These ones should just be omitted altogether if they are blank 2331 2383 foreach ( array( 'loop', 'autoplay', 'preload' ) as $a ) { 2332 if ( empty( $html_atts[ $a] ) ) {2333 unset( $html_atts[ $a] );2384 if ( empty( $html_atts[ $a ] ) ) { 2385 unset( $html_atts[ $a ] ); 2334 2386 } 2335 2387 } … … 2347 2399 2348 2400 $fileurl = ''; 2349 $source = '<source type="%s" src="%s" />';2401 $source = '<source type="%s" src="%s" />'; 2350 2402 foreach ( $default_types as $fallback ) { 2351 2403 if ( ! empty( $atts[ $fallback ] ) ) { … … 2353 2405 $fileurl = $atts[ $fallback ]; 2354 2406 } 2355 $type = wp_check_filetype( $atts[ $fallback ], wp_get_mime_types() );2356 $url = add_query_arg( '_', $instance, $atts[ $fallback ] );2407 $type = wp_check_filetype( $atts[ $fallback ], wp_get_mime_types() ); 2408 $url = add_query_arg( '_', $instance, $atts[ $fallback ] ); 2357 2409 $html .= sprintf( $source, $type['type'], esc_url( $url ) ); 2358 2410 } … … 2468 2520 2469 2521 foreach ( $default_types as $type ) { 2470 $defaults_atts[ $type] = '';2522 $defaults_atts[ $type ] = ''; 2471 2523 } 2472 2524 … … 2477 2529 if ( $atts['width'] > $defaults_atts['width'] ) { 2478 2530 $atts['height'] = round( ( $atts['height'] * $defaults_atts['width'] ) / $atts['width'] ); 2479 $atts['width'] = $defaults_atts['width'];2531 $atts['width'] = $defaults_atts['width']; 2480 2532 } 2481 2533 } else { … … 2483 2535 if ( ! empty( $content_width ) && $atts['width'] > $content_width ) { 2484 2536 $atts['height'] = round( ( $atts['height'] * $content_width ) / $atts['width'] ); 2485 $atts['width'] = $content_width;2486 } 2487 } 2488 2489 $is_vimeo = $is_youtube = false;2490 $yt_pattern = '#^https?://(?:www\.)?(?:youtube\.com/watch|youtu\.be/)#';2537 $atts['width'] = $content_width; 2538 } 2539 } 2540 2541 $is_vimeo = $is_youtube = false; 2542 $yt_pattern = '#^https?://(?:www\.)?(?:youtube\.com/watch|youtu\.be/)#'; 2491 2543 $vimeo_pattern = '#^https?://(.+\.)?vimeo\.com/.*#'; 2492 2544 2493 2545 $primary = false; 2494 2546 if ( ! empty( $atts['src'] ) ) { 2495 $is_vimeo = ( preg_match( $vimeo_pattern, $atts['src'] ) );2496 $is_youtube = ( preg_match( $yt_pattern, $atts['src'] ) );2547 $is_vimeo = ( preg_match( $vimeo_pattern, $atts['src'] ) ); 2548 $is_youtube = ( preg_match( $yt_pattern, $atts['src'] ) ); 2497 2549 if ( ! $is_youtube && ! $is_vimeo ) { 2498 2550 $type = wp_check_filetype( $atts['src'], wp_get_mime_types() ); … … 2503 2555 2504 2556 if ( $is_vimeo ) { 2505 wp_enqueue_script( 'mediaelement-vimeo' );2557 wp_enqueue_script( 'mediaelement-vimeo' ); 2506 2558 } 2507 2559 … … 2525 2577 } 2526 2578 2527 $video = reset( $videos );2579 $video = reset( $videos ); 2528 2580 $atts['src'] = wp_get_attachment_url( $video->ID ); 2529 2581 if ( empty( $atts['src'] ) ) { … … 2558 2610 // Remove all query arguments and force SSL - see #40866. 2559 2611 $parsed_vimeo_url = wp_parse_url( $atts['src'] ); 2560 $vimeo_src = 'https://' . $parsed_vimeo_url['host'] . $parsed_vimeo_url['path'];2612 $vimeo_src = 'https://' . $parsed_vimeo_url['host'] . $parsed_vimeo_url['path']; 2561 2613 2562 2614 // Add loop param for mejs bug - see #40977, not needed after #39686. 2563 $loop = $atts['loop'] ? '1' : '0';2615 $loop = $atts['loop'] ? '1' : '0'; 2564 2616 $atts['src'] = add_query_arg( 'loop', $loop, $vimeo_src ); 2565 2617 } … … 2590 2642 // These ones should just be omitted altogether if they are blank 2591 2643 foreach ( array( 'poster', 'loop', 'autoplay', 'preload' ) as $a ) { 2592 if ( empty( $html_atts[ $a] ) ) {2593 unset( $html_atts[ $a] );2644 if ( empty( $html_atts[ $a ] ) ) { 2645 unset( $html_atts[ $a ] ); 2594 2646 } 2595 2647 } … … 2607 2659 2608 2660 $fileurl = ''; 2609 $source = '<source type="%s" src="%s" />';2661 $source = '<source type="%s" src="%s" />'; 2610 2662 foreach ( $default_types as $fallback ) { 2611 2663 if ( ! empty( $atts[ $fallback ] ) ) { … … 2620 2672 $type = wp_check_filetype( $atts[ $fallback ], wp_get_mime_types() ); 2621 2673 } 2622 $url = add_query_arg( '_', $instance, $atts[ $fallback ] );2674 $url = add_query_arg( '_', $instance, $atts[ $fallback ] ); 2623 2675 $html .= sprintf( $source, $type['type'], esc_url( $url ) ); 2624 2676 } … … 2671 2723 */ 2672 2724 function previous_image_link( $size = 'thumbnail', $text = false ) { 2673 adjacent_image_link( true, $size, $text);2725 adjacent_image_link( true, $size, $text ); 2674 2726 } 2675 2727 … … 2687 2739 */ 2688 2740 function next_image_link( $size = 'thumbnail', $text = false ) { 2689 adjacent_image_link( false, $size, $text);2741 adjacent_image_link( false, $size, $text ); 2690 2742 } 2691 2743 … … 2703 2755 */ 2704 2756 function adjacent_image_link( $prev = true, $size = 'thumbnail', $text = false ) { 2705 $post = get_post(); 2706 $attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) ); 2757 $post = get_post(); 2758 $attachments = array_values( 2759 get_children( 2760 array( 2761 'post_parent' => $post->post_parent, 2762 'post_status' => 'inherit', 2763 'post_type' => 'attachment', 2764 'post_mime_type' => 'image', 2765 'order' => 'ASC', 2766 'orderby' => 'menu_order ID', 2767 ) 2768 ) 2769 ); 2707 2770 2708 2771 foreach ( $attachments as $k => $attachment ) { … … 2712 2775 } 2713 2776 2714 $output = '';2777 $output = ''; 2715 2778 $attachment_id = 0; 2716 2779 … … 2720 2783 if ( isset( $attachments[ $k ] ) ) { 2721 2784 $attachment_id = $attachments[ $k ]->ID; 2722 $output = wp_get_attachment_link( $attachment_id, $size, true, false, $text );2785 $output = wp_get_attachment_link( $attachment_id, $size, true, false, $text ); 2723 2786 } 2724 2787 } … … 2760 2823 $attachment = (object) $attachment; 2761 2824 } 2762 if ( ! is_object( $attachment) )2825 if ( ! is_object( $attachment ) ) { 2763 2826 return array(); 2764 2765 $file = get_attached_file( $attachment->ID ); 2827 } 2828 2829 $file = get_attached_file( $attachment->ID ); 2766 2830 $filename = basename( $file ); 2767 2831 2768 $objects = array('attachment'); 2769 2770 if ( false !== strpos($filename, '.') ) 2771 $objects[] = 'attachment:' . substr($filename, strrpos($filename, '.') + 1); 2772 if ( !empty($attachment->post_mime_type) ) { 2832 $objects = array( 'attachment' ); 2833 2834 if ( false !== strpos( $filename, '.' ) ) { 2835 $objects[] = 'attachment:' . substr( $filename, strrpos( $filename, '.' ) + 1 ); 2836 } 2837 if ( ! empty( $attachment->post_mime_type ) ) { 2773 2838 $objects[] = 'attachment:' . $attachment->post_mime_type; 2774 if ( false !== strpos( $attachment->post_mime_type, '/') )2775 foreach ( explode( '/', $attachment->post_mime_type) as $token )2776 if ( ! empty($token) )2839 if ( false !== strpos( $attachment->post_mime_type, '/' ) ) { 2840 foreach ( explode( '/', $attachment->post_mime_type ) as $token ) { 2841 if ( ! empty( $token ) ) { 2777 2842 $objects[] = "attachment:$token"; 2843 } 2844 } 2845 } 2778 2846 } 2779 2847 … … 2810 2878 foreach ( $taxonomy->object_type as $object_type ) { 2811 2879 if ( 'attachment' == $object_type || 0 === strpos( $object_type, 'attachment:' ) ) { 2812 if ( 'names' == $output ) 2880 if ( 'names' == $output ) { 2813 2881 $taxonomies[] = $taxonomy->name; 2814 else2882 } else { 2815 2883 $taxonomies[ $taxonomy->name ] = $taxonomy; 2884 } 2816 2885 break; 2817 2886 } … … 2833 2902 * @return resource The GD image resource. 2834 2903 */ 2835 function wp_imagecreatetruecolor( $width, $height) {2836 $img = imagecreatetruecolor( $width, $height);2837 if ( is_resource( $img) && function_exists('imagealphablending') && function_exists('imagesavealpha') ) {2838 imagealphablending( $img, false);2839 imagesavealpha( $img, true);2904 function wp_imagecreatetruecolor( $width, $height ) { 2905 $img = imagecreatetruecolor( $width, $height ); 2906 if ( is_resource( $img ) && function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' ) ) { 2907 imagealphablending( $img, false ); 2908 imagesavealpha( $img, true ); 2840 2909 } 2841 2910 return $img; … … 2906 2975 // If $file_info['type'] is false, then we let the editor attempt to 2907 2976 // figure out the file type, rather than forcing a failure based on extension. 2908 if ( isset( $file_info ) && $file_info['type'] ) 2977 if ( isset( $file_info ) && $file_info['type'] ) { 2909 2978 $args['mime_type'] = $file_info['type']; 2979 } 2910 2980 } 2911 2981 … … 2916 2986 $loaded = $editor->load(); 2917 2987 2918 if ( is_wp_error( $loaded ) ) 2988 if ( is_wp_error( $loaded ) ) { 2919 2989 return $loaded; 2990 } 2920 2991 2921 2992 return $editor; 2922 2993 } 2923 2994 2924 return new WP_Error( 'image_no_editor', __( 'No editor could be selected.') );2995 return new WP_Error( 'image_no_editor', __( 'No editor could be selected.' ) ); 2925 2996 } 2926 2997 … … 2963 3034 2964 3035 foreach ( $implementations as $implementation ) { 2965 if ( ! call_user_func( array( $implementation, 'test' ), $args ) ) 3036 if ( ! call_user_func( array( $implementation, 'test' ), $args ) ) { 2966 3037 continue; 3038 } 2967 3039 2968 3040 if ( isset( $args['mime_type'] ) && 2969 3041 ! call_user_func( 2970 3042 array( $implementation, 'supports_mime_type' ), 2971 $args['mime_type'] ) ) { 3043 $args['mime_type'] 3044 ) ) { 2972 3045 continue; 2973 3046 } … … 2994 3067 2995 3068 $data = $wp_scripts->get_data( 'wp-plupload', 'data' ); 2996 if ( $data && false !== strpos( $data, '_wpPluploadSettings' ) ) 3069 if ( $data && false !== strpos( $data, '_wpPluploadSettings' ) ) { 2997 3070 return; 2998 2999 $max_upload_size = wp_max_upload_size(); 3071 } 3072 3073 $max_upload_size = wp_max_upload_size(); 3000 3074 $allowed_extensions = array_keys( get_allowed_mime_types() ); 3001 $extensions = array();3075 $extensions = array(); 3002 3076 foreach ( $allowed_extensions as $extension ) { 3003 3077 $extensions = array_merge( $extensions, explode( '|', $extension ) ); … … 3009 3083 */ 3010 3084 $defaults = array( 3011 'file_data_name' => 'async-upload', // key passed to $_FILE.3012 'url' => admin_url( 'async-upload.php', 'relative' ),3013 'filters' => array(3014 'max_file_size' => $max_upload_size . 'b',3015 'mime_types' => array( array( 'extensions' => implode( ',', $extensions ) ) ),3085 'file_data_name' => 'async-upload', // key passed to $_FILE. 3086 'url' => admin_url( 'async-upload.php', 'relative' ), 3087 'filters' => array( 3088 'max_file_size' => $max_upload_size . 'b', 3089 'mime_types' => array( array( 'extensions' => implode( ',', $extensions ) ) ), 3016 3090 ), 3017 3091 ); … … 3045 3119 * @param array $params Default Plupload parameters array. 3046 3120 */ 3047 $params = apply_filters( 'plupload_default_params', $params );3048 $params['_wpnonce'] = wp_create_nonce( 'media-form' );3121 $params = apply_filters( 'plupload_default_params', $params ); 3122 $params['_wpnonce'] = wp_create_nonce( 'media-form' ); 3049 3123 $defaults['multipart_params'] = $params; 3050 3124 3051 3125 $settings = array( 3052 'defaults' => $defaults,3053 'browser' => array(3126 'defaults' => $defaults, 3127 'browser' => array( 3054 3128 'mobile' => wp_is_mobile(), 3055 3129 'supported' => _device_can_upload(), 3056 3130 ), 3057 'limitExceeded' => is_multisite() && ! is_upload_space_available() 3131 'limitExceeded' => is_multisite() && ! is_upload_space_available(), 3058 3132 ); 3059 3133 3060 3134 $script = 'var _wpPluploadSettings = ' . wp_json_encode( $settings ) . ';'; 3061 3135 3062 if ( $data ) 3136 if ( $data ) { 3063 3137 $script = "$data\n$script"; 3138 } 3064 3139 3065 3140 $wp_scripts->add_data( 'wp-plupload', 'data', $script ); … … 3076 3151 */ 3077 3152 function wp_prepare_attachment_for_js( $attachment ) { 3078 if ( ! $attachment = get_post( $attachment ) ) 3153 if ( ! $attachment = get_post( $attachment ) ) { 3079 3154 return; 3080 3081 if ( 'attachment' != $attachment->post_type ) 3155 } 3156 3157 if ( 'attachment' != $attachment->post_type ) { 3082 3158 return; 3159 } 3083 3160 3084 3161 $meta = wp_get_attachment_metadata( $attachment->ID ); 3085 if ( false !== strpos( $attachment->post_mime_type, '/' ) ) 3162 if ( false !== strpos( $attachment->post_mime_type, '/' ) ) { 3086 3163 list( $type, $subtype ) = explode( '/', $attachment->post_mime_type ); 3087 else3164 } else { 3088 3165 list( $type, $subtype ) = array( $attachment->post_mime_type, '' ); 3166 } 3089 3167 3090 3168 $attachment_url = wp_get_attachment_url( $attachment->ID ); 3091 $base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url );3169 $base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url ); 3092 3170 3093 3171 $response = array( 3094 'id' => $attachment->ID,3095 'title' => $attachment->post_title,3096 'filename' => wp_basename( get_attached_file( $attachment->ID ) ),3097 'url' => $attachment_url,3098 'link' => get_attachment_link( $attachment->ID ),3099 'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),3100 'author' => $attachment->post_author,3101 'description' => $attachment->post_content,3102 'caption' => $attachment->post_excerpt,3103 'name' => $attachment->post_name,3104 'status' => $attachment->post_status,3105 'uploadedTo' => $attachment->post_parent,3106 'date' => strtotime( $attachment->post_date_gmt ) * 1000,3107 'modified' => strtotime( $attachment->post_modified_gmt ) * 1000,3108 'menuOrder' => $attachment->menu_order,3109 'mime' => $attachment->post_mime_type,3110 'type' => $type,3111 'subtype' => $subtype,3112 'icon' => wp_mime_type_icon( $attachment->ID ),3172 'id' => $attachment->ID, 3173 'title' => $attachment->post_title, 3174 'filename' => wp_basename( get_attached_file( $attachment->ID ) ), 3175 'url' => $attachment_url, 3176 'link' => get_attachment_link( $attachment->ID ), 3177 'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ), 3178 'author' => $attachment->post_author, 3179 'description' => $attachment->post_content, 3180 'caption' => $attachment->post_excerpt, 3181 'name' => $attachment->post_name, 3182 'status' => $attachment->post_status, 3183 'uploadedTo' => $attachment->post_parent, 3184 'date' => strtotime( $attachment->post_date_gmt ) * 1000, 3185 'modified' => strtotime( $attachment->post_modified_gmt ) * 1000, 3186 'menuOrder' => $attachment->menu_order, 3187 'mime' => $attachment->post_mime_type, 3188 'type' => $type, 3189 'subtype' => $subtype, 3190 'icon' => wp_mime_type_icon( $attachment->ID ), 3113 3191 'dateFormatted' => mysql2date( __( 'F j, Y' ), $attachment->post_date ), 3114 'nonces' => array(3192 'nonces' => array( 3115 3193 'update' => false, 3116 3194 'delete' => false, 3117 'edit' => false 3195 'edit' => false, 3118 3196 ), 3119 'editLink' => false,3120 'meta' => false,3197 'editLink' => false, 3198 'meta' => false, 3121 3199 ); 3122 3200 … … 3157 3235 3158 3236 if ( $bytes ) { 3159 $response['filesizeInBytes'] = $bytes;3237 $response['filesizeInBytes'] = $bytes; 3160 3238 $response['filesizeHumanReadable'] = size_format( $bytes ); 3161 3239 } 3162 3240 3163 $context = get_post_meta( $attachment->ID, '_wp_attachment_context', true );3241 $context = get_post_meta( $attachment->ID, '_wp_attachment_context', true ); 3164 3242 $response['context'] = ( $context ) ? $context : ''; 3165 3243 3166 3244 if ( current_user_can( 'edit_post', $attachment->ID ) ) { 3167 3245 $response['nonces']['update'] = wp_create_nonce( 'update-post_' . $attachment->ID ); 3168 $response['nonces']['edit'] = wp_create_nonce( 'image_editor-' . $attachment->ID );3169 $response['editLink'] = get_edit_post_link( $attachment->ID, 'raw' );3170 } 3171 3172 if ( current_user_can( 'delete_post', $attachment->ID ) ) 3246 $response['nonces']['edit'] = wp_create_nonce( 'image_editor-' . $attachment->ID ); 3247 $response['editLink'] = get_edit_post_link( $attachment->ID, 'raw' ); 3248 } 3249 3250 if ( current_user_can( 'delete_post', $attachment->ID ) ) { 3173 3251 $response['nonces']['delete'] = wp_create_nonce( 'delete-post_' . $attachment->ID ); 3252 } 3174 3253 3175 3254 if ( $meta && ( 'image' === $type || ! empty( $meta['sizes'] ) ) ) { … … 3177 3256 3178 3257 /** This filter is documented in wp-admin/includes/media.php */ 3179 $possible_sizes = apply_filters( 'image_size_names_choose', array( 3180 'thumbnail' => __('Thumbnail'), 3181 'medium' => __('Medium'), 3182 'large' => __('Large'), 3183 'full' => __('Full Size'), 3184 ) ); 3258 $possible_sizes = apply_filters( 3259 'image_size_names_choose', array( 3260 'thumbnail' => __( 'Thumbnail' ), 3261 'medium' => __( 'Medium' ), 3262 'large' => __( 'Large' ), 3263 'full' => __( 'Full Size' ), 3264 ) 3265 ); 3185 3266 unset( $possible_sizes['full'] ); 3186 3267 … … 3224 3305 3225 3306 if ( isset( $meta['height'], $meta['width'] ) ) { 3226 $sizes['full']['height'] = $meta['height'];3227 $sizes['full']['width'] = $meta['width'];3307 $sizes['full']['height'] = $meta['height']; 3308 $sizes['full']['width'] = $meta['width']; 3228 3309 $sizes['full']['orientation'] = $meta['height'] > $meta['width'] ? 'portrait' : 'landscape'; 3229 3310 } … … 3235 3316 'height' => $meta['sizes']['full']['height'], 3236 3317 'width' => $meta['sizes']['full']['width'], 3237 'orientation' => $meta['sizes']['full']['height'] > $meta['sizes']['full']['width'] ? 'portrait' : 'landscape' 3318 'orientation' => $meta['sizes']['full']['height'] > $meta['sizes']['full']['width'] ? 'portrait' : 'landscape', 3238 3319 ); 3239 3320 } … … 3243 3324 3244 3325 if ( $meta && 'video' === $type ) { 3245 if ( isset( $meta['width'] ) ) 3326 if ( isset( $meta['width'] ) ) { 3246 3327 $response['width'] = (int) $meta['width']; 3247 if ( isset( $meta['height'] ) ) 3328 } 3329 if ( isset( $meta['height'] ) ) { 3248 3330 $response['height'] = (int) $meta['height']; 3331 } 3249 3332 } 3250 3333 3251 3334 if ( $meta && ( 'audio' === $type || 'video' === $type ) ) { 3252 if ( isset( $meta['length_formatted'] ) ) 3335 if ( isset( $meta['length_formatted'] ) ) { 3253 3336 $response['fileLength'] = $meta['length_formatted']; 3337 } 3254 3338 3255 3339 $response['meta'] = array(); … … 3265 3349 if ( ! empty( $id ) ) { 3266 3350 list( $src, $width, $height ) = wp_get_attachment_image_src( $id, 'full' ); 3267 $response['image'] = compact( 'src', 'width', 'height' );3351 $response['image'] = compact( 'src', 'width', 'height' ); 3268 3352 list( $src, $width, $height ) = wp_get_attachment_image_src( $id, 'thumbnail' ); 3269 $response['thumb'] = compact( 'src', 'width', 'height' );3353 $response['thumb'] = compact( 'src', 'width', 'height' ); 3270 3354 } else { 3271 $src = wp_mime_type_icon( $attachment->ID );3272 $width = 48;3273 $height = 64;3355 $src = wp_mime_type_icon( $attachment->ID ); 3356 $width = 48; 3357 $height = 64; 3274 3358 $response['image'] = compact( 'src', 'width', 'height' ); 3275 3359 $response['thumb'] = compact( 'src', 'width', 'height' ); … … 3277 3361 } 3278 3362 3279 if ( function_exists( 'get_compat_media_markup') )3363 if ( function_exists( 'get_compat_media_markup' ) ) { 3280 3364 $response['compat'] = get_compat_media_markup( $attachment->ID, array( 'in_modal' => true ) ); 3365 } 3281 3366 3282 3367 /** … … 3310 3395 function wp_enqueue_media( $args = array() ) { 3311 3396 // Enqueue me just once per page, please. 3312 if ( did_action( 'wp_enqueue_media' ) ) 3397 if ( did_action( 'wp_enqueue_media' ) ) { 3313 3398 return; 3399 } 3314 3400 3315 3401 global $content_width, $wpdb, $wp_locale; … … 3318 3404 'post' => null, 3319 3405 ); 3320 $args = wp_parse_args( $args, $defaults );3406 $args = wp_parse_args( $args, $defaults ); 3321 3407 3322 3408 // We're going to pass the old thickbox media tabs to `media_upload_tabs` … … 3340 3426 ); 3341 3427 3342 $exts = array_merge( wp_get_audio_extensions(), wp_get_video_extensions() );3343 $mimes = get_allowed_mime_types();3428 $exts = array_merge( wp_get_audio_extensions(), wp_get_video_extensions() ); 3429 $mimes = get_allowed_mime_types(); 3344 3430 $ext_mimes = array(); 3345 3431 foreach ( $exts as $ext ) { … … 3371 3457 $show_audio_playlist = apply_filters( 'media_library_show_audio_playlist', true ); 3372 3458 if ( null === $show_audio_playlist ) { 3373 $show_audio_playlist = $wpdb->get_var( " 3459 $show_audio_playlist = $wpdb->get_var( 3460 " 3374 3461 SELECT ID 3375 3462 FROM $wpdb->posts … … 3377 3464 AND post_mime_type LIKE 'audio%' 3378 3465 LIMIT 1 3379 " ); 3466 " 3467 ); 3380 3468 } 3381 3469 … … 3399 3487 $show_video_playlist = apply_filters( 'media_library_show_video_playlist', true ); 3400 3488 if ( null === $show_video_playlist ) { 3401 $show_video_playlist = $wpdb->get_var( " 3489 $show_video_playlist = $wpdb->get_var( 3490 " 3402 3491 SELECT ID 3403 3492 FROM $wpdb->posts … … 3405 3494 AND post_mime_type LIKE 'video%' 3406 3495 LIMIT 1 3407 " ); 3496 " 3497 ); 3408 3498 } 3409 3499 … … 3426 3516 $months = apply_filters( 'media_library_months_with_files', null ); 3427 3517 if ( ! is_array( $months ) ) { 3428 $months = $wpdb->get_results( $wpdb->prepare( " 3518 $months = $wpdb->get_results( 3519 $wpdb->prepare( 3520 " 3429 3521 SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month 3430 3522 FROM $wpdb->posts 3431 3523 WHERE post_type = %s 3432 3524 ORDER BY post_date DESC 3433 ", 'attachment' ) ); 3525 ", 'attachment' 3526 ) 3527 ); 3434 3528 } 3435 3529 foreach ( $months as $month_year ) { … … 3438 3532 3439 3533 $settings = array( 3440 'tabs' => $tabs,3441 'tabUrl' => add_query_arg( array( 'chromeless' => true ), admin_url('media-upload.php') ),3442 'mimeTypes' => wp_list_pluck( get_post_mime_types(), 0 ),3534 'tabs' => $tabs, 3535 'tabUrl' => add_query_arg( array( 'chromeless' => true ), admin_url( 'media-upload.php' ) ), 3536 'mimeTypes' => wp_list_pluck( get_post_mime_types(), 0 ), 3443 3537 /** This filter is documented in wp-admin/includes/media.php */ 3444 'captions' => ! apply_filters( 'disable_captions', '' ),3445 'nonce' => array(3538 'captions' => ! apply_filters( 'disable_captions', '' ), 3539 'nonce' => array( 3446 3540 'sendToEditor' => wp_create_nonce( 'media-send-to-editor' ), 3447 3541 ), 3448 'post' => array(3542 'post' => array( 3449 3543 'id' => 0, 3450 3544 ), 3451 'defaultProps' => $props,3545 'defaultProps' => $props, 3452 3546 'attachmentCounts' => array( 3453 3547 'audio' => ( $show_audio_playlist ) ? 1 : 0, 3454 3548 'video' => ( $show_video_playlist ) ? 1 : 0, 3455 3549 ), 3456 'oEmbedProxyUrl' => rest_url( 'oembed/1.0/proxy' ),3457 'embedExts' => $exts,3458 'embedMimes' => $ext_mimes,3459 'contentWidth' => $content_width,3460 'months' => $months,3461 'mediaTrash' => MEDIA_TRASH ? 1 : 0,3550 'oEmbedProxyUrl' => rest_url( 'oembed/1.0/proxy' ), 3551 'embedExts' => $exts, 3552 'embedMimes' => $ext_mimes, 3553 'contentWidth' => $content_width, 3554 'months' => $months, 3555 'mediaTrash' => MEDIA_TRASH ? 1 : 0, 3462 3556 ); 3463 3557 3464 3558 $post = null; 3465 3559 if ( isset( $args['post'] ) ) { 3466 $post = get_post( $args['post'] );3560 $post = get_post( $args['post'] ); 3467 3561 $settings['post'] = array( 3468 'id' => $post->ID,3562 'id' => $post->ID, 3469 3563 'nonce' => wp_create_nonce( 'update-post_' . $post->ID ), 3470 3564 ); … … 3480 3574 3481 3575 if ( $thumbnail_support ) { 3482 $featured_image_id = get_post_meta( $post->ID, '_thumbnail_id', true );3576 $featured_image_id = get_post_meta( $post->ID, '_thumbnail_id', true ); 3483 3577 $settings['post']['featuredImageId'] = $featured_image_id ? $featured_image_id : -1; 3484 3578 } … … 3493 3587 $strings = array( 3494 3588 // Generic 3495 'url' => __( 'URL' ),3496 'addMedia' => __( 'Add Media' ),3497 'search' => __( 'Search' ),3498 'select' => __( 'Select' ),3499 'cancel' => __( 'Cancel' ),3500 'update' => __( 'Update' ),3501 'replace' => __( 'Replace' ),3502 'remove' => __( 'Remove' ),3503 'back' => __( 'Back' ),3589 'url' => __( 'URL' ), 3590 'addMedia' => __( 'Add Media' ), 3591 'search' => __( 'Search' ), 3592 'select' => __( 'Select' ), 3593 'cancel' => __( 'Cancel' ), 3594 'update' => __( 'Update' ), 3595 'replace' => __( 'Replace' ), 3596 'remove' => __( 'Remove' ), 3597 'back' => __( 'Back' ), 3504 3598 /* 3505 3599 * translators: This is a would-be plural string used in the media manager. … … 3507 3601 * lack of plural support here, turn it into "selected: %d" then translate it. 3508 3602 */ 3509 'selected' => __( '%d selected' ),3510 'dragInfo' => __( 'Drag and drop to reorder media files.' ),3603 'selected' => __( '%d selected' ), 3604 'dragInfo' => __( 'Drag and drop to reorder media files.' ), 3511 3605 3512 3606 // Upload 3513 'uploadFilesTitle' => __( 'Upload Files' ),3514 'uploadImagesTitle' => __( 'Upload Images' ),3607 'uploadFilesTitle' => __( 'Upload Files' ), 3608 'uploadImagesTitle' => __( 'Upload Images' ), 3515 3609 3516 3610 // Library 3517 'mediaLibraryTitle' => __( 'Media Library' ),3518 'insertMediaTitle' => __( 'Add Media' ),3519 'createNewGallery' => __( 'Create a new gallery' ),3520 'createNewPlaylist' => __( 'Create a new playlist' ),3521 'createNewVideoPlaylist' => __( 'Create a new video playlist' ),3522 'returnToLibrary' => __( '← Return to library' ),3523 'allMediaItems' => __( 'All media items' ),3524 'allDates' => __( 'All dates' ),3525 'noItemsFound' => __( 'No items found.' ),3526 'insertIntoPost' => $post_type_object->labels->insert_into_item,3527 'unattached' => __( 'Unattached' ),3528 'trash' => _x( 'Trash', 'noun' ),3529 'uploadedToThisPost' => $post_type_object->labels->uploaded_to_this_item,3530 'warnDelete' => __( "You are about to permanently delete this item from your site.\nThis action cannot be undone.\n 'Cancel' to stop, 'OK' to delete." ),3531 'warnBulkDelete' => __( "You are about to permanently delete these items from your site.\nThis action cannot be undone.\n 'Cancel' to stop, 'OK' to delete." ),3532 'warnBulkTrash' => __( "You are about to trash these items.\n 'Cancel' to stop, 'OK' to delete." ),3533 'bulkSelect' => __( 'Bulk Select' ),3534 'cancelSelection' => __( 'Cancel Selection' ),3535 'trashSelected' => __( 'Trash Selected' ),3536 'untrashSelected' => __( 'Untrash Selected' ),3537 'deleteSelected' => __( 'Delete Selected' ),3538 'deletePermanently' => __( 'Delete Permanently' ),3539 'apply' => __( 'Apply' ),3540 'filterByDate' => __( 'Filter by date' ),3541 'filterByType' => __( 'Filter by type' ),3542 'searchMediaLabel' => __( 'Search Media' ),3543 'searchMediaPlaceholder' => __( 'Search media items...' ), // placeholder (no ellipsis)3544 'noMedia' => __( 'No media files found.' ),3611 'mediaLibraryTitle' => __( 'Media Library' ), 3612 'insertMediaTitle' => __( 'Add Media' ), 3613 'createNewGallery' => __( 'Create a new gallery' ), 3614 'createNewPlaylist' => __( 'Create a new playlist' ), 3615 'createNewVideoPlaylist' => __( 'Create a new video playlist' ), 3616 'returnToLibrary' => __( '← Return to library' ), 3617 'allMediaItems' => __( 'All media items' ), 3618 'allDates' => __( 'All dates' ), 3619 'noItemsFound' => __( 'No items found.' ), 3620 'insertIntoPost' => $post_type_object->labels->insert_into_item, 3621 'unattached' => __( 'Unattached' ), 3622 'trash' => _x( 'Trash', 'noun' ), 3623 'uploadedToThisPost' => $post_type_object->labels->uploaded_to_this_item, 3624 'warnDelete' => __( "You are about to permanently delete this item from your site.\nThis action cannot be undone.\n 'Cancel' to stop, 'OK' to delete." ), 3625 'warnBulkDelete' => __( "You are about to permanently delete these items from your site.\nThis action cannot be undone.\n 'Cancel' to stop, 'OK' to delete." ), 3626 'warnBulkTrash' => __( "You are about to trash these items.\n 'Cancel' to stop, 'OK' to delete." ), 3627 'bulkSelect' => __( 'Bulk Select' ), 3628 'cancelSelection' => __( 'Cancel Selection' ), 3629 'trashSelected' => __( 'Trash Selected' ), 3630 'untrashSelected' => __( 'Untrash Selected' ), 3631 'deleteSelected' => __( 'Delete Selected' ), 3632 'deletePermanently' => __( 'Delete Permanently' ), 3633 'apply' => __( 'Apply' ), 3634 'filterByDate' => __( 'Filter by date' ), 3635 'filterByType' => __( 'Filter by type' ), 3636 'searchMediaLabel' => __( 'Search Media' ), 3637 'searchMediaPlaceholder' => __( 'Search media items...' ), // placeholder (no ellipsis) 3638 'noMedia' => __( 'No media files found.' ), 3545 3639 3546 3640 // Library Details 3547 'attachmentDetails' => __( 'Attachment Details' ),3641 'attachmentDetails' => __( 'Attachment Details' ), 3548 3642 3549 3643 // From URL 3550 'insertFromUrlTitle' => __( 'Insert from URL' ),3644 'insertFromUrlTitle' => __( 'Insert from URL' ), 3551 3645 3552 3646 // Featured Images 3553 'setFeaturedImageTitle' => $post_type_object->labels->featured_image,3554 'setFeaturedImage' => $post_type_object->labels->set_featured_image,3647 'setFeaturedImageTitle' => $post_type_object->labels->featured_image, 3648 'setFeaturedImage' => $post_type_object->labels->set_featured_image, 3555 3649 3556 3650 // Gallery 3557 'createGalleryTitle' => __( 'Create Gallery' ),3558 'editGalleryTitle' => __( 'Edit Gallery' ),3559 'cancelGalleryTitle' => __( '← Cancel Gallery' ),3560 'insertGallery' => __( 'Insert gallery' ),3561 'updateGallery' => __( 'Update gallery' ),3562 'addToGallery' => __( 'Add to gallery' ),3563 'addToGalleryTitle' => __( 'Add to Gallery' ),3564 'reverseOrder' => __( 'Reverse order' ),3651 'createGalleryTitle' => __( 'Create Gallery' ), 3652 'editGalleryTitle' => __( 'Edit Gallery' ), 3653 'cancelGalleryTitle' => __( '← Cancel Gallery' ), 3654 'insertGallery' => __( 'Insert gallery' ), 3655 'updateGallery' => __( 'Update gallery' ), 3656 'addToGallery' => __( 'Add to gallery' ), 3657 'addToGalleryTitle' => __( 'Add to Gallery' ), 3658 'reverseOrder' => __( 'Reverse order' ), 3565 3659 3566 3660 // Edit Image 3567 'imageDetailsTitle' => __( 'Image Details' ),3568 'imageReplaceTitle' => __( 'Replace Image' ),3569 'imageDetailsCancel' => __( 'Cancel Edit' ),3570 'editImage' => __( 'Edit Image' ),3661 'imageDetailsTitle' => __( 'Image Details' ), 3662 'imageReplaceTitle' => __( 'Replace Image' ), 3663 'imageDetailsCancel' => __( 'Cancel Edit' ), 3664 'editImage' => __( 'Edit Image' ), 3571 3665 3572 3666 // Crop Image 3573 'chooseImage' => __( 'Choose Image' ),3574 'selectAndCrop' => __( 'Select and Crop' ),3575 'skipCropping' => __( 'Skip Cropping' ),3576 'cropImage' => __( 'Crop Image' ),3577 'cropYourImage' => __( 'Crop your image' ),3578 'cropping' => __( 'Cropping…' ),3667 'chooseImage' => __( 'Choose Image' ), 3668 'selectAndCrop' => __( 'Select and Crop' ), 3669 'skipCropping' => __( 'Skip Cropping' ), 3670 'cropImage' => __( 'Crop Image' ), 3671 'cropYourImage' => __( 'Crop your image' ), 3672 'cropping' => __( 'Cropping…' ), 3579 3673 /* translators: 1: suggested width number, 2: suggested height number. */ 3580 'suggestedDimensions' => __( 'Suggested image dimensions: %1$s by %2$s pixels.' ),3581 'cropError' => __( 'There has been an error cropping your image.' ),3674 'suggestedDimensions' => __( 'Suggested image dimensions: %1$s by %2$s pixels.' ), 3675 'cropError' => __( 'There has been an error cropping your image.' ), 3582 3676 3583 3677 // Edit Audio 3584 'audioDetailsTitle' => __( 'Audio Details' ),3585 'audioReplaceTitle' => __( 'Replace Audio' ),3586 'audioAddSourceTitle' => __( 'Add Audio Source' ),3587 'audioDetailsCancel' => __( 'Cancel Edit' ),3678 'audioDetailsTitle' => __( 'Audio Details' ), 3679 'audioReplaceTitle' => __( 'Replace Audio' ), 3680 'audioAddSourceTitle' => __( 'Add Audio Source' ), 3681 'audioDetailsCancel' => __( 'Cancel Edit' ), 3588 3682 3589 3683 // Edit Video 3590 'videoDetailsTitle' => __( 'Video Details' ),3591 'videoReplaceTitle' => __( 'Replace Video' ),3592 'videoAddSourceTitle' => __( 'Add Video Source' ),3593 'videoDetailsCancel' => __( 'Cancel Edit' ),3684 'videoDetailsTitle' => __( 'Video Details' ), 3685 'videoReplaceTitle' => __( 'Replace Video' ), 3686 'videoAddSourceTitle' => __( 'Add Video Source' ), 3687 'videoDetailsCancel' => __( 'Cancel Edit' ), 3594 3688 'videoSelectPosterImageTitle' => __( 'Select Poster Image' ), 3595 'videoAddTrackTitle' => __( 'Add Subtitles' ),3596 3597 // Playlist3598 'playlistDragInfo'=> __( 'Drag and drop to reorder tracks.' ),3599 'createPlaylistTitle'=> __( 'Create Audio Playlist' ),3600 'editPlaylistTitle'=> __( 'Edit Audio Playlist' ),3601 'cancelPlaylistTitle'=> __( '← Cancel Audio Playlist' ),3602 'insertPlaylist'=> __( 'Insert audio playlist' ),3603 'updatePlaylist'=> __( 'Update audio playlist' ),3604 'addToPlaylist'=> __( 'Add to audio playlist' ),3605 'addToPlaylistTitle'=> __( 'Add to Audio Playlist' ),3606 3607 // Video Playlist3608 'videoPlaylistDragInfo'=> __( 'Drag and drop to reorder videos.' ),3609 'createVideoPlaylistTitle'=> __( 'Create Video Playlist' ),3610 'editVideoPlaylistTitle'=> __( 'Edit Video Playlist' ),3611 'cancelVideoPlaylistTitle'=> __( '← Cancel Video Playlist' ),3612 'insertVideoPlaylist'=> __( 'Insert video playlist' ),3613 'updateVideoPlaylist'=> __( 'Update video playlist' ),3614 'addToVideoPlaylist'=> __( 'Add to video playlist' ),3615 'addToVideoPlaylistTitle'=> __( 'Add to Video Playlist' ),3689 'videoAddTrackTitle' => __( 'Add Subtitles' ), 3690 3691 // Playlist 3692 'playlistDragInfo' => __( 'Drag and drop to reorder tracks.' ), 3693 'createPlaylistTitle' => __( 'Create Audio Playlist' ), 3694 'editPlaylistTitle' => __( 'Edit Audio Playlist' ), 3695 'cancelPlaylistTitle' => __( '← Cancel Audio Playlist' ), 3696 'insertPlaylist' => __( 'Insert audio playlist' ), 3697 'updatePlaylist' => __( 'Update audio playlist' ), 3698 'addToPlaylist' => __( 'Add to audio playlist' ), 3699 'addToPlaylistTitle' => __( 'Add to Audio Playlist' ), 3700 3701 // Video Playlist 3702 'videoPlaylistDragInfo' => __( 'Drag and drop to reorder videos.' ), 3703 'createVideoPlaylistTitle' => __( 'Create Video Playlist' ), 3704 'editVideoPlaylistTitle' => __( 'Edit Video Playlist' ), 3705 'cancelVideoPlaylistTitle' => __( '← Cancel Video Playlist' ), 3706 'insertVideoPlaylist' => __( 'Insert video playlist' ), 3707 'updateVideoPlaylist' => __( 'Update video playlist' ), 3708 'addToVideoPlaylist' => __( 'Add to video playlist' ), 3709 'addToVideoPlaylistTitle' => __( 'Add to Video Playlist' ), 3616 3710 ); 3617 3711 … … 3634 3728 * @param WP_Post $post Post object. 3635 3729 */ 3636 $strings = apply_filters( 'media_view_strings', $strings, $post );3730 $strings = apply_filters( 'media_view_strings', $strings, $post ); 3637 3731 3638 3732 $strings['settings'] = $settings; … … 3675 3769 */ 3676 3770 function get_attached_media( $type, $post = 0 ) { 3677 if ( ! $post = get_post( $post ) ) 3771 if ( ! $post = get_post( $post ) ) { 3678 3772 return array(); 3773 } 3679 3774 3680 3775 $args = array( 3681 'post_parent' => $post->ID,3682 'post_type' => 'attachment',3776 'post_parent' => $post->ID, 3777 'post_type' => 'attachment', 3683 3778 'post_mime_type' => $type, 3684 3779 'posts_per_page' => -1, 3685 'orderby' => 'menu_order',3686 'order' => 'ASC',3780 'orderby' => 'menu_order', 3781 'order' => 'ASC', 3687 3782 ); 3688 3783 … … 3764 3859 */ 3765 3860 function get_post_galleries( $post, $html = true ) { 3766 if ( ! $post = get_post( $post ) ) 3861 if ( ! $post = get_post( $post ) ) { 3767 3862 return array(); 3768 3769 if ( ! has_shortcode( $post->post_content, 'gallery' ) ) 3863 } 3864 3865 if ( ! has_shortcode( $post->post_content, 'gallery' ) ) { 3770 3866 return array(); 3867 } 3771 3868 3772 3869 $galleries = array(); … … 3800 3897 $shortcode_attrs, 3801 3898 array( 3802 'src' => array_values( array_unique( $srcs ) ) 3899 'src' => array_values( array_unique( $srcs ) ), 3803 3900 ) 3804 3901 ); … … 3830 3927 function get_post_gallery( $post = 0, $html = true ) { 3831 3928 $galleries = get_post_galleries( $post, $html ); 3832 $gallery = reset( $galleries );3929 $gallery = reset( $galleries ); 3833 3930 3834 3931 /** … … 3890 3987 $meta = wp_get_attachment_metadata( $attachment_id ); 3891 3988 if ( empty( $meta ) && file_exists( $file ) ) { 3892 $_meta = get_post_meta( $attachment_id );3989 $_meta = get_post_meta( $attachment_id ); 3893 3990 $regeneration_lock = 'wp_generating_att_' . $attachment_id; 3894 3991 if ( ! array_key_exists( '_wp_attachment_metadata', $_meta ) && ! get_transient( $regeneration_lock ) ) { … … 3913 4010 global $wpdb; 3914 4011 3915 $dir = wp_get_upload_dir();4012 $dir = wp_get_upload_dir(); 3916 4013 $path = $url; 3917 4014 3918 $site_url = parse_url( $dir['url'] );4015 $site_url = parse_url( $dir['url'] ); 3919 4016 $image_path = parse_url( $path ); 3920 4017 … … 3928 4025 } 3929 4026 3930 $sql = $wpdb->prepare(4027 $sql = $wpdb->prepare( 3931 4028 "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = %s", 3932 4029 $path … … 3953 4050 */ 3954 4051 function wpview_media_sandbox_styles() { 3955 $version= 'ver=' . get_bloginfo( 'version' );3956 $mediaelement= includes_url( "js/mediaelement/mediaelementplayer-legacy.min.css?$version" );3957 $wpmediaelement = includes_url( "js/mediaelement/wp-mediaelement.css?$version" );4052 $version = 'ver=' . get_bloginfo( 'version' ); 4053 $mediaelement = includes_url( "js/mediaelement/mediaelementplayer-legacy.min.css?$version" ); 4054 $wpmediaelement = includes_url( "js/mediaelement/wp-mediaelement.css?$version" ); 3958 4055 3959 4056 return array( $mediaelement, $wpmediaelement );
Note: See TracChangeset
for help on using the changeset viewer.