Ticket #41675: #41675-v2.patch
| File #41675-v2.patch, 28.1 KB (added by , 7 years ago) |
|---|
-
src/js/media/views/attachments/browser.js
163 163 priority: -90 164 164 }).render() ); 165 165 166 // DateFilter is a <select>, screen reader text needs to be rendered before 167 this.toolbar.set( 'dateFilterLabel', new wp.media.view.Label({ 168 value: l10n.filterByDate, 169 attributes: { 170 'for': 'media-attachment-date-filters' 171 }, 172 priority: -75 173 }).render() ); 174 this.toolbar.set( 'dateFilter', new wp.media.view.DateFilter({ 175 controller: this.controller, 176 model: this.collection.props, 177 priority: -75 178 }).render() ); 166 if ( showMonths ) { 167 // DateFilter is a <select>, screen reader text needs to be rendered before 168 this.toolbar.set( 'dateFilterLabel', new wp.media.view.Label({ 169 value: l10n.filterByDate, 170 attributes: { 171 'for': 'media-attachment-date-filters' 172 }, 173 priority: -75 174 }).render() ); 175 this.toolbar.set( 'dateFilter', new wp.media.view.DateFilter({ 176 controller: this.controller, 177 model: this.collection.props, 178 priority: -75 179 }).render() ); 180 } 179 181 180 182 // BulkSelection is a <div> with subviews, including screen reader text 181 183 this.toolbar.set( 'selectModeToggleButton', new wp.media.view.SelectModeToggleButton({ … … 284 286 }).render() ); 285 287 } 286 288 287 } else if ( this.options.date ) {289 } else if ( showMonths && this.options.date ) { 288 290 // DateFilter is a <select>, screen reader text needs to be rendered before 289 291 this.toolbar.set( 'dateFilterLabel', new wp.media.view.Label({ 290 292 value: l10n.filterByDate, -
src/wp-includes/media.php
17 17 */ 18 18 function wp_get_additional_image_sizes() { 19 19 global $_wp_additional_image_sizes; 20 21 20 if ( ! $_wp_additional_image_sizes ) { 22 21 $_wp_additional_image_sizes = array(); 23 22 } 24 25 23 return $_wp_additional_image_sizes; 26 24 } 27 25 … … 68 66 if ( is_array( $size ) ) { 69 67 $max_width = $size[0]; 70 68 $max_height = $size[1]; 71 } elseif ( $size == = 'thumb' || $size === 'thumbnail' ) {69 } elseif ( $size == 'thumb' || $size == 'thumbnail' ) { 72 70 $max_width = intval( get_option( 'thumbnail_size_w' ) ); 73 71 $max_height = intval( get_option( 'thumbnail_size_h' ) ); 74 72 // last chance thumbnail size defaults … … 76 74 $max_width = 128; 77 75 $max_height = 96; 78 76 } 79 } elseif ( $size == ='medium' ) {77 } elseif ( $size == 'medium' ) { 80 78 $max_width = intval( get_option( 'medium_size_w' ) ); 81 79 $max_height = intval( get_option( 'medium_size_h' ) ); 82 80 83 } elseif ( $size == ='medium_large' ) {81 } elseif ( $size == 'medium_large' ) { 84 82 $max_width = intval( get_option( 'medium_large_size_w' ) ); 85 83 $max_height = intval( get_option( 'medium_large_size_h' ) ); 86 84 … … 87 85 if ( intval( $content_width ) > 0 ) { 88 86 $max_width = min( intval( $content_width ), $max_width ); 89 87 } 90 } elseif ( $size == ='large' ) {88 } elseif ( $size == 'large' ) { 91 89 /* 92 90 * We're inserting a large size image into the editor. If it's a really 93 91 * big image we'll scale it down to fit reasonably within the editor … … 96 94 */ 97 95 $max_width = intval( get_option( 'large_size_w' ) ); 98 96 $max_height = intval( get_option( 'large_size_h' ) ); 99 100 97 if ( intval( $content_width ) > 0 ) { 101 98 $max_width = min( intval( $content_width ), $max_width ); 102 99 } 103 } elseif ( ! empty( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) , true) ) {100 } elseif ( ! empty( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) ) ) { 104 101 $max_width = intval( $_wp_additional_image_sizes[ $size ]['width'] ); 105 102 $max_height = intval( $_wp_additional_image_sizes[ $size ]['height'] ); 106 103 // Only in admin. Assume that theme authors know what they're doing. … … 198 195 * @param array|string $size Size of image. Image size or array of width and height values (in that order). 199 196 * Default 'medium'. 200 197 */ 201 $out = apply_filters( 'image_downsize', false, $id, $size ); 202 203 if ( $out ) { 198 if ( $out = apply_filters( 'image_downsize', false, $id, $size ) ) { 204 199 return $out; 205 200 } 206 201 207 202 $img_url = wp_get_attachment_url( $id ); 208 203 $meta = wp_get_attachment_metadata( $id ); 209 $width = 0; 210 $height = 0; 204 $width = $height = 0; 211 205 $is_intermediate = false; 212 206 $img_url_basename = wp_basename( $img_url ); 213 207 … … 225 219 } 226 220 227 221 // try for a new style intermediate size 228 $intermediate = image_get_intermediate_size( $id, $size ); 229 230 if ( $intermediate ) { 222 if ( $intermediate = image_get_intermediate_size( $id, $size ) ) { 231 223 $img_url = str_replace( $img_url_basename, $intermediate['file'], $img_url ); 232 224 $width = $intermediate['width']; 233 225 $height = $intermediate['height']; 234 226 $is_intermediate = true; 235 } elseif ( $size == ='thumbnail' ) {227 } elseif ( $size == 'thumbnail' ) { 236 228 // fall back to the old thumbnail 237 $thumb_file = wp_get_attachment_thumb_file( $id ); 238 $info = null; 239 240 if ( $thumb_file ) { 241 $info = @getimagesize( $thumb_file ); 242 } 243 244 if ( $thumb_file && $info ) { 229 if ( ( $thumb_file = wp_get_attachment_thumb_file( $id ) ) && $info = getimagesize( $thumb_file ) ) { 245 230 $img_url = str_replace( $img_url_basename, wp_basename( $thumb_file ), $img_url ); 246 231 $width = $info[0]; 247 232 $height = $info[1]; … … 248 233 $is_intermediate = true; 249 234 } 250 235 } 251 252 236 if ( ! $width && ! $height && isset( $meta['width'], $meta['height'] ) ) { 253 237 // any other type: use the real image 254 238 $width = $meta['width']; … … 261 245 262 246 return array( $img_url, $width, $height, $is_intermediate ); 263 247 } 248 return false; 264 249 265 return false;266 250 } 267 251 268 252 /** … … 428 412 return array( $current_width, $current_height ); 429 413 } 430 414 431 $width_ratio = 1.0; 432 $height_ratio = 1.0; 433 $did_width = false; 434 $did_height = false; 415 $width_ratio = $height_ratio = 1.0; 416 $did_width = $did_height = false; 435 417 436 418 if ( $max_width > 0 && $current_width > 0 && $current_width > $max_width ) { 437 419 $width_ratio = $max_width / $current_width; … … 464 446 // Thus we look for dimensions that are one pixel shy of the max value and bump them up 465 447 466 448 // Note: $did_width means it is possible $smaller_ratio == $width_ratio. 467 if ( $did_width && $w == =$max_width - 1 ) {449 if ( $did_width && $w == $max_width - 1 ) { 468 450 $w = $max_width; // Round it up 469 451 } 470 452 471 453 // Note: $did_height means it is possible $smaller_ratio == $height_ratio. 472 if ( $did_height && $h == =$max_height - 1 ) {454 if ( $did_height && $h == $max_height - 1 ) { 473 455 $h = $max_height; // Round it up 474 456 } 475 457 … … 538 520 * An array can specify positioning of the crop area. Default false. 539 521 */ 540 522 $output = apply_filters( 'image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop ); 541 542 523 if ( null !== $output ) { 543 524 return $output; 544 525 } … … 595 576 } 596 577 597 578 // if the resulting image would be the same size or larger we don't want to resize it 598 if ( $new_w >= $orig_w && $new_h >= $orig_h && intval( $dest_w ) !== intval( $orig_w ) && intval( $dest_h ) !== intval( $orig_h )) {579 if ( $new_w >= $orig_w && $new_h >= $orig_h && $dest_w != $orig_w && $dest_h != $orig_h ) { 599 580 return false; 600 581 } 601 582 … … 706 687 * } 707 688 */ 708 689 function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { 709 $imagedata = wp_get_attachment_metadata( $post_id ); 710 711 if ( ! $size || ! is_array( $imagedata ) || empty( $imagedata['sizes'] ) ) { 690 if ( ! $size || ! is_array( $imagedata = wp_get_attachment_metadata( $post_id ) ) || empty( $imagedata['sizes'] ) ) { 712 691 return false; 713 692 } 714 693 … … 725 704 726 705 foreach ( $imagedata['sizes'] as $_size => $data ) { 727 706 // If there's an exact match to an existing image size, short circuit. 728 if ( intval( $data['width'] ) === intval( $size[0] ) && intval( $data['height'] ) === intval( $size[1] )) {707 if ( $data['width'] == $size[0] && $data['height'] == $size[1] ) { 729 708 $candidates[ $data['width'] * $data['height'] ] = $data; 730 709 break; 731 710 } … … 806 785 * @return array Returns a filtered array of image size strings. 807 786 */ 808 787 function get_intermediate_image_sizes() { 809 $default_sizes = array( 'thumbnail', 'medium', 'medium_large', 'large' ); 810 $additional_sizes = wp_get_additional_image_sizes(); 811 812 if ( ! empty( $additional_sizes ) ) { 813 $default_sizes = array_merge( $default_sizes, array_keys( $additional_sizes ) ); 788 $_wp_additional_image_sizes = wp_get_additional_image_sizes(); 789 $image_sizes = array( 'thumbnail', 'medium', 'medium_large', 'large' ); // Standard sizes 790 if ( ! empty( $_wp_additional_image_sizes ) ) { 791 $image_sizes = array_merge( $image_sizes, array_keys( $_wp_additional_image_sizes ) ); 814 792 } 815 793 816 794 /** … … 818 796 * 819 797 * @since 2.5.0 820 798 * 821 * @param array $ default_sizes An array of intermediate image sizes. Defaults822 * are 'thumbnail', 'medium', 'medium_large', 'large'.799 * @param array $image_sizes An array of intermediate image sizes. Defaults 800 * are 'thumbnail', 'medium', 'medium_large', 'large'. 823 801 */ 824 return apply_filters( 'intermediate_image_sizes', $ default_sizes );802 return apply_filters( 'intermediate_image_sizes', $image_sizes ); 825 803 } 826 804 827 805 /** 828 * Returns a normalized list of all currently registered image sub-sizes.829 *830 * @since 5.3.0831 * @uses wp_get_additional_image_sizes()832 * @uses get_intermediate_image_sizes()833 *834 * @return array Associative array of the registered image sub-sizes.835 */836 function wp_get_registered_image_subsizes() {837 $additional_sizes = wp_get_additional_image_sizes();838 $all_sizes = array();839 840 foreach ( get_intermediate_image_sizes() as $size_name ) {841 $size_data = array(842 'width' => 0,843 'height' => 0,844 'crop' => false,845 );846 847 if ( isset( $additional_sizes[ $size_name ]['width'] ) ) {848 // For sizes added by plugins and themes.849 $size_data['width'] = intval( $additional_sizes[ $size_name ]['width'] );850 } else {851 // For default sizes set in options.852 $size_data['width'] = intval( get_option( "{$size_name}_size_w" ) );853 }854 855 if ( isset( $additional_sizes[ $size_name ]['height'] ) ) {856 $size_data['height'] = intval( $additional_sizes[ $size_name ]['height'] );857 } else {858 $size_data['height'] = intval( get_option( "{$size_name}_size_h" ) );859 }860 861 if ( empty( $size_data['width'] ) && empty( $size_data['height'] ) ) {862 // This size isn't set.863 continue;864 }865 866 if ( isset( $additional_sizes[ $size_name ]['crop'] ) ) {867 $size_data['crop'] = $additional_sizes[ $size_name ]['crop'];868 } else {869 $size_data['crop'] = get_option( "{$size_name}_crop" );870 }871 872 if ( ! is_array( $size_data['crop'] ) || empty( $size_data['crop'] ) ) {873 $size_data['crop'] = (bool) $size_data['crop'];874 }875 876 $all_sizes[ $size_name ] = $size_data;877 }878 879 return $all_sizes;880 }881 882 /**883 806 * Retrieve an image to represent an attachment. 884 807 * 885 808 * A mime icon for files, thumbnail or intermediate size for images. … … 903 826 if ( ! $image ) { 904 827 $src = false; 905 828 906 if ( $icon ) { 907 $src = wp_mime_type_icon( $attachment_id ); 829 if ( $icon && $src = wp_mime_type_icon( $attachment_id ) ) { 830 /** This filter is documented in wp-includes/post.php */ 831 $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' ); 908 832 909 if ( $src ) { 910 /** This filter is documented in wp-includes/post.php */ 911 $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' ); 912 913 $src_file = $icon_dir . '/' . wp_basename( $src ); 914 list( $width, $height ) = @getimagesize( $src_file ); 915 } 833 $src_file = $icon_dir . '/' . wp_basename( $src ); 834 @list( $width, $height ) = getimagesize( $src_file ); 916 835 } 917 836 918 837 if ( $src && $width && $height ) { … … 1095 1014 * @return string|bool A 'srcset' value string or false. 1096 1015 */ 1097 1016 function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $image_meta = null ) { 1098 $image = wp_get_attachment_image_src( $attachment_id, $size ); 1099 1100 if ( ! $image ) { 1017 if ( ! $image = wp_get_attachment_image_src( $attachment_id, $size ) ) { 1101 1018 return false; 1102 1019 } 1103 1020 … … 1229 1146 1230 1147 // If the file name is part of the `src`, we've confirmed a match. 1231 1148 if ( ! $src_matched && false !== strpos( $image_src, $dirname . $image['file'] ) ) { 1232 $src_matched = true; 1233 $is_src = true; 1149 $src_matched = $is_src = true; 1234 1150 } 1235 1151 1236 1152 // Filter out images that are from previous edits. … … 1316 1232 * @return string|bool A valid source size value for use in a 'sizes' attribute or false. 1317 1233 */ 1318 1234 function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $image_meta = null ) { 1319 $image = wp_get_attachment_image_src( $attachment_id, $size ); 1320 1321 if ( ! $image ) { 1235 if ( ! $image = wp_get_attachment_image_src( $attachment_id, $size ) ) { 1322 1236 return false; 1323 1237 } 1324 1238 … … 1404 1318 return $content; 1405 1319 } 1406 1320 1407 $selected_images = array(); 1408 $attachment_ids = array(); 1321 $selected_images = $attachment_ids = array(); 1409 1322 1410 1323 foreach ( $matches[0] as $image ) { 1411 if ( false === strpos( $image, ' srcset=' ) && preg_match( '/wp-image-([0-9]+)/i', $image, $class_id ) ) {1412 $attachment_id = absint( $class_id[1] );1324 if ( false === strpos( $image, ' srcset=' ) && preg_match( '/wp-image-([0-9]+)/i', $image, $class_id ) && 1325 ( $attachment_id = absint( $class_id[1] ) ) ) { 1413 1326 1414 if ( $attachment_id ) { 1415 /* 1416 * If exactly the same image tag is used more than once, overwrite it. 1417 * All identical tags will be replaced later with 'str_replace()'. 1418 */ 1419 $selected_images[ $image ] = $attachment_id; 1420 // Overwrite the ID when the same image is included more than once. 1421 $attachment_ids[ $attachment_id ] = true; 1422 } 1327 /* 1328 * If exactly the same image tag is used more than once, overwrite it. 1329 * All identical tags will be replaced later with 'str_replace()'. 1330 */ 1331 $selected_images[ $image ] = $attachment_id; 1332 // Overwrite the ID when the same image is included more than once. 1333 $attachment_ids[ $attachment_id ] = true; 1423 1334 } 1424 1335 } 1425 1336 … … 1628 1539 * @param string $content The image element, possibly wrapped in a hyperlink. 1629 1540 */ 1630 1541 $output = apply_filters( 'img_caption_shortcode', '', $attr, $content ); 1631 1632 if ( ! empty( $output ) ) { 1542 if ( $output != '' ) { 1633 1543 return $output; 1634 1544 } 1635 1545 … … 1647 1557 ); 1648 1558 1649 1559 $atts['width'] = (int) $atts['width']; 1650 1651 1560 if ( $atts['width'] < 1 || empty( $atts['caption'] ) ) { 1652 1561 return $content; 1653 1562 } 1654 1563 1655 $id = ''; 1656 $caption_id = ''; 1657 $describedby = ''; 1564 $id = $caption_id = $describedby = ''; 1658 1565 1659 1566 if ( $atts['id'] ) { 1660 1567 $atts['id'] = sanitize_html_class( $atts['id'] ); … … 1696 1603 $caption_width = apply_filters( 'img_caption_shortcode_width', $width, $atts, $content ); 1697 1604 1698 1605 $style = ''; 1699 1700 1606 if ( $caption_width ) { 1701 1607 $style = 'style="width: ' . (int) $caption_width . 'px" '; 1702 1608 } … … 1799 1705 * @param int $instance Unique numeric ID of this gallery shortcode instance. 1800 1706 */ 1801 1707 $output = apply_filters( 'post_gallery', '', $attr, $instance ); 1802 1803 if ( ! empty( $output ) ) { 1708 if ( $output != '' ) { 1804 1709 return $output; 1805 1710 } 1806 1711 … … 1945 1850 $output = apply_filters( 'gallery_style', $gallery_style . $gallery_div ); 1946 1851 1947 1852 $i = 0; 1948 1949 1853 foreach ( $attachments as $id => $attachment ) { 1950 1854 1951 1855 $attr = ( trim( $attachment->post_excerpt ) ) ? array( 'aria-describedby' => "$selector-$id" ) : ''; 1952 1953 1856 if ( ! empty( $atts['link'] ) && 'file' === $atts['link'] ) { 1954 1857 $image_output = wp_get_attachment_link( $id, $atts['size'], false, false, false, $attr ); 1955 1858 } elseif ( ! empty( $atts['link'] ) && 'none' === $atts['link'] ) { … … 1957 1860 } else { 1958 1861 $image_output = wp_get_attachment_link( $id, $atts['size'], true, false, false, $attr ); 1959 1862 } 1960 1961 1863 $image_meta = wp_get_attachment_metadata( $id ); 1962 1864 1963 1865 $orientation = ''; 1964 1965 1866 if ( isset( $image_meta['height'], $image_meta['width'] ) ) { 1966 1867 $orientation = ( $image_meta['height'] > $image_meta['width'] ) ? 'portrait' : 'landscape'; 1967 1868 } 1968 1969 1869 $output .= "<{$itemtag} class='gallery-item'>"; 1970 1870 $output .= " 1971 1871 <{$icontag} class='gallery-icon {$orientation}'> 1972 1872 $image_output 1973 1873 </{$icontag}>"; 1974 1975 1874 if ( $captiontag && trim( $attachment->post_excerpt ) ) { 1976 1875 $output .= " 1977 1876 <{$captiontag} class='wp-caption-text gallery-caption' id='$selector-$id'> … … 1978 1877 " . wptexturize( $attachment->post_excerpt ) . " 1979 1878 </{$captiontag}>"; 1980 1879 } 1981 1982 1880 $output .= "</{$itemtag}>"; 1983 1984 if ( ! $html5 && $columns > 0 && ++$i % $columns === 0 ) { 1881 if ( ! $html5 && $columns > 0 && ++$i % $columns == 0 ) { 1985 1882 $output .= '<br style="clear: both" />'; 1986 1883 } 1987 1884 } … … 2128 2025 * @param int $instance Unique numeric ID of this playlist shortcode instance. 2129 2026 */ 2130 2027 $output = apply_filters( 'post_playlist', '', $attr, $instance ); 2131 2132 if ( ! empty( $output ) ) { 2028 if ( $output != '' ) { 2133 2029 return $output; 2134 2030 } 2135 2031 … … 2439 2335 * @param int $instance Unique numeric ID of this audio shortcode instance. 2440 2336 */ 2441 2337 $override = apply_filters( 'wp_audio_shortcode_override', '', $attr, $content, $instance ); 2442 2443 2338 if ( '' !== $override ) { 2444 2339 return $override; 2445 2340 } … … 2464 2359 $primary = false; 2465 2360 if ( ! empty( $atts['src'] ) ) { 2466 2361 $type = wp_check_filetype( $atts['src'], wp_get_mime_types() ); 2467 2468 if ( ! in_array( strtolower( $type['ext'] ), $default_types, true ) ) { 2362 if ( ! in_array( strtolower( $type['ext'] ), $default_types ) ) { 2469 2363 return sprintf( '<a class="wp-embedded-audio" href="%s">%s</a>', esc_url( $atts['src'] ), esc_html( $atts['src'] ) ); 2470 2364 } 2471 2472 2365 $primary = true; 2473 2366 array_unshift( $default_types, 'src' ); 2474 2367 } else { … … 2475 2368 foreach ( $default_types as $ext ) { 2476 2369 if ( ! empty( $atts[ $ext ] ) ) { 2477 2370 $type = wp_check_filetype( $atts[ $ext ], wp_get_mime_types() ); 2478 2479 2371 if ( strtolower( $type['ext'] ) === $ext ) { 2480 2372 $primary = true; 2481 2373 } … … 2485 2377 2486 2378 if ( ! $primary ) { 2487 2379 $audios = get_attached_media( 'audio', $post_id ); 2488 2489 2380 if ( empty( $audios ) ) { 2490 2381 return; 2491 2382 } … … 2492 2383 2493 2384 $audio = reset( $audios ); 2494 2385 $atts['src'] = wp_get_attachment_url( $audio->ID ); 2495 2496 2386 if ( empty( $atts['src'] ) ) { 2497 2387 return; 2498 2388 } … … 2508 2398 * @param string $library Media library used for the audio shortcode. 2509 2399 */ 2510 2400 $library = apply_filters( 'wp_audio_shortcode_library', 'mediaelement' ); 2511 2512 2401 if ( 'mediaelement' === $library && did_action( 'init' ) ) { 2513 2402 wp_enqueue_style( 'wp-mediaelement' ); 2514 2403 wp_enqueue_script( 'wp-mediaelement' ); … … 2542 2431 } 2543 2432 2544 2433 $attr_strings = array(); 2545 2546 2434 foreach ( $html_atts as $k => $v ) { 2547 2435 $attr_strings[] = $k . '="' . esc_attr( $v ) . '"'; 2548 2436 } 2549 2437 2550 2438 $html = ''; 2551 2552 2439 if ( 'mediaelement' === $library && 1 === $instance ) { 2553 2440 $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n"; 2554 2441 } 2555 2556 2442 $html .= sprintf( '<audio %s controls="controls">', join( ' ', $attr_strings ) ); 2557 2443 2558 2444 $fileurl = ''; 2559 2445 $source = '<source type="%s" src="%s" />'; 2560 2561 2446 foreach ( $default_types as $fallback ) { 2562 2447 if ( ! empty( $atts[ $fallback ] ) ) { 2563 2448 if ( empty( $fileurl ) ) { 2564 2449 $fileurl = $atts[ $fallback ]; 2565 2450 } 2566 2567 2451 $type = wp_check_filetype( $atts[ $fallback ], wp_get_mime_types() ); 2568 2452 $url = add_query_arg( '_', $instance, $atts[ $fallback ] ); 2569 2453 $html .= sprintf( $source, $type['type'], esc_url( $url ) ); … … 2573 2457 if ( 'mediaelement' === $library ) { 2574 2458 $html .= wp_mediaelement_fallback( $fileurl ); 2575 2459 } 2576 2577 2460 $html .= '</audio>'; 2578 2461 2579 2462 /** … … 2661 2544 * @param int $instance Unique numeric ID of this video shortcode instance. 2662 2545 */ 2663 2546 $override = apply_filters( 'wp_video_shortcode_override', '', $attr, $content, $instance ); 2664 2665 2547 if ( '' !== $override ) { 2666 2548 return $override; 2667 2549 } … … 2700 2582 } 2701 2583 } 2702 2584 2703 $is_vimeo = false; 2704 $is_youtube = false; 2585 $is_vimeo = $is_youtube = false; 2705 2586 $yt_pattern = '#^https?://(?:www\.)?(?:youtube\.com/watch|youtu\.be/)#'; 2706 2587 $vimeo_pattern = '#^https?://(.+\.)?vimeo\.com/.*#'; 2707 2588 … … 2709 2590 if ( ! empty( $atts['src'] ) ) { 2710 2591 $is_vimeo = ( preg_match( $vimeo_pattern, $atts['src'] ) ); 2711 2592 $is_youtube = ( preg_match( $yt_pattern, $atts['src'] ) ); 2712 2713 2593 if ( ! $is_youtube && ! $is_vimeo ) { 2714 2594 $type = wp_check_filetype( $atts['src'], wp_get_mime_types() ); 2715 2716 if ( ! in_array( strtolower( $type['ext'] ), $default_types, true ) ) { 2595 if ( ! in_array( strtolower( $type['ext'] ), $default_types ) ) { 2717 2596 return sprintf( '<a class="wp-embedded-video" href="%s">%s</a>', esc_url( $atts['src'] ), esc_html( $atts['src'] ) ); 2718 2597 } 2719 2598 } … … 2934 2813 ); 2935 2814 2936 2815 foreach ( $attachments as $k => $attachment ) { 2937 if ( intval( $attachment->ID ) === intval( $post->ID )) {2816 if ( $attachment->ID == $post->ID ) { 2938 2817 break; 2939 2818 } 2940 2819 } … … 2987 2866 } elseif ( is_array( $attachment ) ) { 2988 2867 $attachment = (object) $attachment; 2989 2868 } 2990 2991 2869 if ( ! is_object( $attachment ) ) { 2992 2870 return array(); 2993 2871 } … … 3000 2878 if ( false !== strpos( $filename, '.' ) ) { 3001 2879 $objects[] = 'attachment:' . substr( $filename, strrpos( $filename, '.' ) + 1 ); 3002 2880 } 3003 3004 2881 if ( ! empty( $attachment->post_mime_type ) ) { 3005 2882 $objects[] = 'attachment:' . $attachment->post_mime_type; 3006 3007 2883 if ( false !== strpos( $attachment->post_mime_type, '/' ) ) { 3008 2884 foreach ( explode( '/', $attachment->post_mime_type ) as $token ) { 3009 2885 if ( ! empty( $token ) ) { … … 3014 2890 } 3015 2891 3016 2892 $taxonomies = array(); 3017 3018 2893 foreach ( $objects as $object ) { 3019 $taxes = get_object_taxonomies( $object, $output ); 3020 3021 if ( $taxes ) { 2894 if ( $taxes = get_object_taxonomies( $object, $output ) ) { 3022 2895 $taxonomies = array_merge( $taxonomies, $taxes ); 3023 2896 } 3024 2897 } … … 3044 2917 */ 3045 2918 function get_taxonomies_for_attachments( $output = 'names' ) { 3046 2919 $taxonomies = array(); 3047 3048 2920 foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) { 3049 2921 foreach ( $taxonomy->object_type as $object_type ) { 3050 if ( 'attachment' == =$object_type || 0 === strpos( $object_type, 'attachment:' ) ) {3051 if ( 'names' == =$output ) {2922 if ( 'attachment' == $object_type || 0 === strpos( $object_type, 'attachment:' ) ) { 2923 if ( 'names' == $output ) { 3052 2924 $taxonomies[] = $taxonomy->name; 3053 2925 } else { 3054 2926 $taxonomies[ $taxonomy->name ] = $taxonomy; … … 3321 3193 * @return array|void Array of attachment details. 3322 3194 */ 3323 3195 function wp_prepare_attachment_for_js( $attachment ) { 3324 $attachment = get_post( $attachment ); 3325 3326 if ( ! $attachment ) { 3196 if ( ! $attachment = get_post( $attachment ) ) { 3327 3197 return; 3328 3198 } 3329 3199 3330 if ( 'attachment' != =$attachment->post_type ) {3200 if ( 'attachment' != $attachment->post_type ) { 3331 3201 return; 3332 3202 } 3333 3203 … … 3446 3316 foreach ( $possible_sizes as $size => $label ) { 3447 3317 3448 3318 /** This filter is documented in wp-includes/media.php */ 3449 $downsize = apply_filters( 'image_downsize', false, $attachment->ID, $size ); 3450 3451 if ( $downsize ) { 3319 if ( $downsize = apply_filters( 'image_downsize', false, $attachment->ID, $size ) ) { 3452 3320 if ( empty( $downsize[3] ) ) { 3453 3321 continue; 3454 3322 } … … 3560 3428 * @since 3.5.0 3561 3429 * 3562 3430 * @global int $content_width 3563 * @global wpdb $wpdb WordPress database abstraction object.3564 * @global WP_Locale $wp_locale WordPress date and time locale object.3431 * @global wpdb $wpdb 3432 * @global WP_Locale $wp_locale 3565 3433 * 3566 3434 * @param array $args { 3567 3435 * Arguments for enqueuing media scripts. … … 3675 3543 } 3676 3544 3677 3545 /** 3678 * Allows overriding the list of months displayedin the media library.3546 * Allows showing or hiding the months select in the media library. 3679 3547 * 3680 * By default (if this filter does not return an array), a query will be3681 * run to determine the months that have media items. This query can be 3682 * expensive for large media libraries, so it may be desirable for sites to 3683 * override this behavior.3548 * By default, the months select will always be shown in the media library 3549 * and a list of months will be generated to populate the select with. 3550 * If `false` is returned the 'media_library_months_with_files' filter 3551 * will not be run and no select will be shown. 3684 3552 * 3685 3553 * @since 4.7.4 3686 3554 * 3687 3555 * @link https://core.trac.wordpress.org/ticket/31071 3688 3556 * 3557 * @link https://core.trac.wordpress.org/ticket/41675 3558 * 3689 3559 * @param array|null An array of objects with `month` and `year` 3690 3560 * properties, or `null` (or any other non-array value) 3691 3561 * for default behavior. 3692 3562 */ 3563 $show_months_select = apply_filters( 'media_library_months_with_files', true ); 3564 $months = null; 3693 3565 $months = apply_filters( 'media_library_months_with_files', null ); 3694 if ( ! is_array( $months ) ) { 3695 $months = $wpdb->get_results( 3696 $wpdb->prepare( 3697 " 3698 SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month 3699 FROM $wpdb->posts 3700 WHERE post_type = %s 3701 ORDER BY post_date DESC 3702 ", 3703 'attachment' 3704 ) 3705 ); 3566 if ( $show_months_select === true ) { 3567 if ( ! is_array( $months ) ) { 3568 $months = $wpdb->get_results( 3569 $wpdb->prepare( 3570 " 3571 SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month 3572 FROM $wpdb->posts 3573 WHERE post_type = %s 3574 ORDER BY post_date DESC 3575 ", 3576 'attachment' 3577 ) 3578 ); 3579 } 3580 foreach ( $months as $month_year ) { 3581 $month_year->text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month_year->month ), $month_year->year ); 3582 } 3706 3583 } 3707 foreach ( $months as $month_year ) {3708 $month_year->text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month_year->month ), $month_year->year );3709 }3710 3584 3711 3585 $settings = array( 3712 3586 'tabs' => $tabs, … … 3730 3604 'embedMimes' => $ext_mimes, 3731 3605 'contentWidth' => $content_width, 3732 3606 'months' => $months, 3607 'showMonths' => $show_months_select, 3733 3608 'mediaTrash' => MEDIA_TRASH ? 1 : 0, 3734 3609 ); 3735 3610 … … 3948 3823 * @return array Found attachments. 3949 3824 */ 3950 3825 function get_attached_media( $type, $post = 0 ) { 3951 $post = get_post( $post ); 3952 3953 if ( ! $post ) { 3826 if ( ! $post = get_post( $post ) ) { 3954 3827 return array(); 3955 3828 } 3956 3829 … … 4040 3913 * from the expanded shortcode. 4041 3914 */ 4042 3915 function get_post_galleries( $post, $html = true ) { 4043 $post = get_post( $post ); 4044 4045 if ( ! $post ) { 3916 if ( ! $post = get_post( $post ) ) { 4046 3917 return array(); 4047 3918 } 4048 3919 … … 4163 4034 * @param WP_Post $attachment Attachment object. 4164 4035 */ 4165 4036 function wp_maybe_generate_attachment_metadata( $attachment ) { 4166 if ( empty( $attachment ) || empty($attachment->ID ) ) {4037 if ( empty( $attachment ) || ( empty( $attachment->ID ) || ! $attachment_id = (int) $attachment->ID ) ) { 4167 4038 return; 4168 4039 } 4169 4040 4170 $attachment_id = (int) $attachment->ID; 4171 $file = get_attached_file( $attachment_id ); 4172 $meta = wp_get_attachment_metadata( $attachment_id ); 4173 4041 $file = get_attached_file( $attachment_id ); 4042 $meta = wp_get_attachment_metadata( $attachment_id ); 4174 4043 if ( empty( $meta ) && file_exists( $file ) ) { 4175 $_meta = get_post_meta( $attachment_id ); 4176 $_lock = 'wp_generating_att_' . $attachment_id; 4177 4178 if ( ! array_key_exists( '_wp_attachment_metadata', $_meta ) && ! get_transient( $_lock ) ) { 4179 set_transient( $_lock, $file ); 4044 $_meta = get_post_meta( $attachment_id ); 4045 $regeneration_lock = 'wp_generating_att_' . $attachment_id; 4046 if ( ! array_key_exists( '_wp_attachment_metadata', $_meta ) && ! get_transient( $regeneration_lock ) ) { 4047 set_transient( $regeneration_lock, $file ); 4180 4048 wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) ); 4181 delete_transient( $ _lock );4049 delete_transient( $regeneration_lock ); 4182 4050 } 4183 4051 } 4184 4052 } … … 4211 4079 $path = substr( $path, strlen( $dir['baseurl'] . '/' ) ); 4212 4080 } 4213 4081 4214 $sql = $wpdb->prepare(4082 $sql = $wpdb->prepare( 4215 4083 "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = %s", 4216 4084 $path 4217 4085 ); 4218 4219 4086 $post_id = $wpdb->get_var( $sql ); 4220 4087 4221 4088 /**
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)