Make WordPress Core

Ticket #34464: 34464.1.diff

File 34464.1.diff, 7.5 KB (added by jaspermdegroot, 9 years ago)

Replaces 34464.diff

  • src/wp-includes/media.php

    diff --git src/wp-includes/media.php src/wp-includes/media.php
    index 30df322..29933a6 100644
    function wp_get_attachment_image_url( $attachment_id, $size = 'thumbnail', $icon 
    879879 *
    880880 *     @type array $values {
    881881 *        @type string $url        An image URL.
    882  *        @type string $descriptor A width or density descriptor used in a srcset.
     882 *        @type string $descriptor A width or density descriptor used in a 'srcset'.
    883883 *        @type int    $value      The descriptor value representing a width or
    884884 *                                 or pixel density.
    885885 *     }
    886886 * }
    887  *
    888887 */
    889888function wp_get_attachment_image_srcset_array( $attachment_id, $size = 'medium' ) {
    890889        // Get the intermediate size.
    function wp_get_attachment_image_srcset_array( $attachment_id, $size = 'medium' 
    905904                return false;
    906905        }
    907906
    908         // Use the URL from the intermediate size or build the url from the metadata.
     907        // Use the URL from the intermediate size or build the URL from the metadata.
    909908        if ( ! empty( $image['url'] ) ) {
    910909                $img_url = $image['url'];
    911910        } else {
    function wp_get_attachment_image_srcset_array( $attachment_id, $size = 'medium' 
    934933        $img_edited = preg_match( '/-e[0-9]{13}/', $img_url, $img_edit_hash );
    935934
    936935        /**
    937          * Filter the maximum width included in a srcset attribute.
     936         * Filter the maximum width included in a 'srcset' attribute.
    938937         *
    939938         * @since 4.4.0
    940939         *
    941          * @param array|string $size Size of image, either array or string.
     940         * @param int          $max_width The maximum width to include in the 'srcset'. Default '1600'.
     941         * @param array|string $size      Image size. Image size or an array of width and height
     942         *                                values in pixels (in that order).
    942943         */
    943944        $max_srcset_width = apply_filters( 'max_srcset_image_width', 1600, $size );
    944945
    945946        /*
    946          * Set up arrays to hold url candidates and matched image sources so
    947          * we can avoid duplicates without looping through the full sources array
     947         * Set up arrays to hold URL candidates and matched image sources so
     948         * we can avoid duplicates without looping through the full sources array.
    948949         */
    949950        $candidates = $sources = array();
    950951
    function wp_get_attachment_image_srcset_array( $attachment_id, $size = 'medium' 
    959960                        continue;
    960961                }
    961962
    962                 // Filter out images that are wider than $max_srcset_width.
     963                // Filter out images that are wider than `$max_srcset_width`.
    963964                if ( $max_srcset_width && $img['width'] > $max_srcset_width ) {
    964965                        continue;
    965966                }
    function wp_get_attachment_image_srcset_array( $attachment_id, $size = 'medium' 
    978979                        // Add the URL to our list of candidates.
    979980                        $candidates[] = $candidate_url;
    980981
    981                         // Add the url, descriptor, and value to the sources array to be returned.
     982                        // Add the URL, descriptor, and value to the sources array to be returned.
    982983                        $sources[] = array(
    983984                                'url'        => $candidate_url,
    984985                                'descriptor' => 'w',
    function wp_get_attachment_image_srcset_array( $attachment_id, $size = 'medium' 
    994995         *
    995996         * @param array        $sources       An array of image urls and widths.
    996997         * @param int          $attachment_id Attachment ID for image.
    997          * @param array|string $size          Image size. Accepts any valid image size, or an array of width and height
    998          *                                    values in pixels (in that order). Default 'medium'.
     998         * @param array|string $size          Image size. Image size or an array of width and height
     999         *                                    values in pixels (in that order).
    9991000         */
    10001001        return apply_filters( 'wp_get_attachment_image_srcset_array', $sources, $attachment_id, $size );
    10011002}
    function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium' ) { 
    10281029         *
    10291030         * @since 4.4.0
    10301031         *
    1031          * @param string       $srcset        A source set formated for a `srcset` attribute.
     1032         * @param string       $srcset        A source set formatted for a `srcset` attribute.
    10321033         * @param int          $attachment_id Attachment ID for image.
    1033          * @param array|string $size          Image size. Accepts any valid image size, or an array of width and height
    1034          *                                    values in pixels (in that order). Default 'medium'.
     1034         * @param array|string $size          Image size. Image size or an array of width and height
     1035         *                                    values in pixels (in that order).
    10351036         */
    10361037        return apply_filters( 'wp_get_attachment_image_srcset', rtrim( $srcset, ', ' ), $attachment_id, $size );
    10371038}
    function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $width 
    10601061                $img_width = $image ? $image['width'] : false;
    10611062        }
    10621063
    1063         // Bail early if $img_width isn't set.
     1064        // Bail early if `$img_width` isn't set.
    10641065        if ( ! $img_width ) {
    10651066                return false;
    10661067        }
    function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $width 
    10751076         *
    10761077         * @param string       $sizes         A source size value for use in a 'sizes' attribute.
    10771078         * @param int          $attachment_id Post ID of the original image.
    1078          * @param array|string $size          Image size. Accepts any valid image size, or an array of width and height
    1079          *                                    values in pixels (in that order). Default 'medium'.
     1079         * @param array|string $size          Image size. Image size or an array of width and height
     1080         *                                    values in pixels (in that order).
    10801081         * @param int          $width         Display width of the image.
    10811082         */
    10821083        return apply_filters( 'wp_get_attachment_image_sizes', $sizes, $attachment_id, $size, $width );
    function wp_make_content_images_responsive( $content ) { 
    11081109
    11091110        if ( 0 < count( $attachment_ids ) ) {
    11101111                /*
    1111                  * Warm object caches for use with wp_get_attachment_metadata.
     1112                 * Warm object caches for use with `wp_get_attachment_metadata`.
    11121113                 *
    11131114                 * To avoid making a database call for each image, a single query
    11141115                 * warms the object cache with the meta information for all images.
    function wp_img_add_srcset_and_sizes( $image ) { 
    11401141                return $image;
    11411142        }
    11421143
    1143         // Parse id, size, width, and height from the `img` element.
     1144        // Parse ID, size, width, and height from the `img` element.
    11441145        $id     = preg_match( '/wp-image-([0-9]+)/i', $image, $match_id     ) ? (int) $match_id[1]     : false;
    11451146        $size   = preg_match( '/size-([^\s|"]+)/i',   $image, $match_size   ) ? $match_size[1]         : false;
    11461147        $width  = preg_match( '/ width="([0-9]+)"/',  $image, $match_width  ) ? (int) $match_width[1]  : false;
    function wp_img_add_srcset_and_sizes( $image ) { 
    11601161        if ( $id && ! $size ) {
    11611162                $meta = wp_get_attachment_metadata( $id );
    11621163
    1163                 // Parse the image src value from the img element.
     1164                // Parse the image 'src' value from the 'img' element.
    11641165                $src = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : false;
    11651166
    1166                 // Return early if the metadata does not exist or the src value is empty.
     1167                // Return early if the metadata does not exist or the 'src' value is empty.
    11671168                if ( ! $meta || ! $src ) {
    11681169                        return $image;
    11691170                }
    function wp_img_add_srcset_and_sizes( $image ) { 
    11961197                        // Format the srcset and sizes string and escape attributes.
    11971198                        $srcset_and_sizes = sprintf( ' srcset="%s" sizes="%s"', esc_attr( $srcset ), esc_attr( $sizes) );
    11981199
    1199                         // Add srcset and sizes attributes to the image markup.
     1200                        // Add 'srcset' and 'sizes' attributes to the image markup.
    12001201                        $image = preg_replace( '/<img ([^>]+)[\s?][\/?]>/', '<img $1' . $srcset_and_sizes . ' />', $image );
    12011202                }
    12021203        }