Make WordPress Core

Ticket #45407: 45407.diff

File 45407.diff, 7.9 KB (added by azaozz, 6 years ago)
  • wp-includes/media.php

     
    10351035 *
    10361036 * @since 4.4.0
    10371037 *
    1038  * @param array  $size_array    Array of width and height values in pixels (in that order).
    1039  * @param string $image_src     The 'src' of the image.
    1040  * @param array  $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
    1041  * @param int    $attachment_id Optional. The image attachment ID to pass to the filter. Default 0.
    1042  * @return string|bool          The 'srcset' attribute value. False on error or when only one source exists.
     1038 * @param array  $size_array       Array of width and height values in pixels (in that order).
     1039 * @param string $image_src        The 'src' of the image.
     1040 * @param array  $image_meta       The image meta data as returned by 'wp_get_attachment_metadata()'.
     1041 * @param int    $attachment_id    Optional. The image attachment ID to pass to the filter. Default 0.
     1042 * @param array  $block_attributes Optional. Block attributes when an image block is rendered. 
     1043 * @return string|bool The 'srcset' attribute value. False on error or when only one source exists.
    10431044 */
    1044 function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id = 0 ) {
     1045function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id = 0, $block_attributes = null ) {
    10451046        /**
    10461047         * Let plugins pre-filter the image meta to be able to fix inconsistencies in the stored data.
    10471048         *
     
    11951196         *                                  pixel density value if paired with an 'x' descriptor.
    11961197         *     }
    11971198         * }
    1198          * @param array  $size_array    Array of width and height values in pixels (in that order).
    1199          * @param string $image_src     The 'src' of the image.
    1200          * @param array  $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
    1201          * @param int    $attachment_id Image attachment ID or 0.
     1199         * @param array      $size_array       Array of width and height values in pixels (in that order).
     1200         * @param string     $image_src        The 'src' of the image.
     1201         * @param array      $image_meta       The image meta data as returned by 'wp_get_attachment_metadata()'.
     1202         * @param int        $attachment_id    Image attachment ID or 0.
     1203         * @param array|null $block_attributes Block attributes when an image block is rendered or null.
    12021204         */
    1203         $sources = apply_filters( 'wp_calculate_image_srcset', $sources, $size_array, $image_src, $image_meta, $attachment_id );
     1205        $sources = apply_filters( 'wp_calculate_image_srcset', $sources, $size_array, $image_src, $image_meta, $attachment_id, $block_attributes );
    12041206
    12051207        // Only return a 'srcset' value if there is more than one source.
    12061208        if ( ! $src_matched || ! is_array( $sources ) || count( $sources ) < 2 ) {
     
    12531255 *
    12541256 * @since 4.4.0
    12551257 *
    1256  * @param array|string $size          Image size to retrieve. Accepts any valid image size, or an array
    1257  *                                    of width and height values in pixels (in that order). Default 'medium'.
    1258  * @param string       $image_src     Optional. The URL to the image file. Default null.
    1259  * @param array        $image_meta    Optional. The image meta data as returned by 'wp_get_attachment_metadata()'.
    1260  *                                    Default null.
    1261  * @param int          $attachment_id Optional. Image attachment ID. Either `$image_meta` or `$attachment_id`
    1262  *                                    is needed when using the image size name as argument for `$size`. Default 0.
     1258 * @param array|string $size             Image size to retrieve. Accepts any valid image size, or an array
     1259 *                                       of width and height values in pixels (in that order). Default 'medium'.
     1260 * @param string       $image_src        Optional. The URL to the image file. Default null.
     1261 * @param array        $image_meta       Optional. The image meta data as returned by 'wp_get_attachment_metadata()'.
     1262 *                                       Default null.
     1263 * @param int          $attachment_id    Optional. Image attachment ID. Either `$image_meta` or `$attachment_id`
     1264 *                                       is needed when using the image size name as argument for `$size`. Default 0.
     1265 * @param array        $block_attributes Optional. Block attributes when an image block is rendered.
    12631266 * @return string|bool A valid source size value for use in a 'sizes' attribute or false.
    12641267 */
    1265 function wp_calculate_image_sizes( $size, $image_src = null, $image_meta = null, $attachment_id = 0 ) {
     1268function wp_calculate_image_sizes( $size, $image_src = null, $image_meta = null, $attachment_id = 0, $block_attributes = null ) {
    12661269        $width = 0;
    12671270
    12681271        if ( is_array( $size ) ) {
     
    12921295         *
    12931296         * @since 4.4.0
    12941297         *
    1295          * @param string       $sizes         A source size value for use in a 'sizes' attribute.
    1296          * @param array|string $size          Requested size. Image size or array of width and height values
    1297          *                                    in pixels (in that order).
    1298          * @param string|null  $image_src     The URL to the image file or null.
    1299          * @param array|null   $image_meta    The image meta data as returned by wp_get_attachment_metadata() or null.
    1300          * @param int          $attachment_id Image attachment ID of the original image or 0.
     1298         * @param string       $sizes            A source size value for use in a 'sizes' attribute.
     1299         * @param array|string $size             Requested size. Image size or array of width and height values
     1300         *                                       in pixels (in that order).
     1301         * @param string|null  $image_src        The URL to the image file or null.
     1302         * @param array|null   $image_meta       The image meta data as returned by wp_get_attachment_metadata() or null.
     1303         * @param int          $attachment_id    Image attachment ID of the original image or 0.
     1304         * @param array|null   $block_attributes Block attributes when an image block is rendered or null.
    13011305         */
    1302         return apply_filters( 'wp_calculate_image_sizes', $sizes, $size, $image_src, $image_meta, $attachment_id );
     1306        return apply_filters( 'wp_calculate_image_sizes', $sizes, $size, $image_src, $image_meta, $attachment_id, $block_attributes );
    13031307}
    13041308
    13051309/**
     
    13571361 * @see wp_calculate_image_srcset()
    13581362 * @see wp_calculate_image_sizes()
    13591363 *
    1360  * @param string $image         An HTML 'img' element to be filtered.
    1361  * @param array  $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
    1362  * @param int    $attachment_id Image attachment ID.
     1364 * @param string $image            An HTML 'img' element to be filtered.
     1365 * @param array  $image_meta       The image meta data as returned by 'wp_get_attachment_metadata()'.
     1366 * @param int    $attachment_id    Image attachment ID.
     1367 * @param array  $block_attributes Optional Block attributes when an image block is rendered.
    13631368 * @return string Converted 'img' element with 'srcset' and 'sizes' attributes added.
    13641369 */
    1365 function wp_image_add_srcset_and_sizes( $image, $image_meta, $attachment_id ) {
     1370function wp_image_add_srcset_and_sizes( $image, $image_meta, $attachment_id, $block_attributes = null ) {
    13661371        // Ensure the image meta exists.
    13671372        if ( empty( $image_meta['sizes'] ) ) {
    13681373                return $image;
     
    14121417        }
    14131418
    14141419        $size_array = array( $width, $height );
    1415         $srcset = wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id );
     1420        $srcset = wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id, $block_attributes );
    14161421
    14171422        if ( $srcset ) {
    14181423                // Check if there is already a 'sizes' attribute.
     
    14191424                $sizes = strpos( $image, ' sizes=' );
    14201425
    14211426                if ( ! $sizes ) {
    1422                         $sizes = wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $attachment_id );
     1427                        $sizes = wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $attachment_id, $block_attributes );
    14231428                }
    14241429        }
    14251430