WordPress.org

Make WordPress Core

Changeset 48547


Ignore:
Timestamp:
07/21/2020 04:52:48 PM (3 months ago)
Author:
SergeyBiryukov
Message:

Media: Pass the attachment ID to the wp_image_file_matches_image_meta filter.

Props spacedmonkey.
Fixes #50722.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r48496 r48547  
    15081508 * @since 5.5.0
    15091509 *
    1510  * @param string $image_location  The full path or URI to the image file.
    1511  * @param array  $image_meta      The attachment meta data as returned by 'wp_get_attachment_metadata()'.
     1510 * @param string $image_location The full path or URI to the image file.
     1511 * @param array  $image_meta     The attachment meta data as returned by 'wp_get_attachment_metadata()'.
     1512 * @param int    $attachment_id  Optional. The image attachment ID. Default 0.
    15121513 * @return bool Whether the image meta is for this image file.
    15131514 */
    1514 function wp_image_file_matches_image_meta( $image_location, $image_meta ) {
     1515function wp_image_file_matches_image_meta( $image_location, $image_meta, $attachment_id = 0 ) {
    15151516    $match = false;
    15161517
     
    15601561     *                               matches the end of the URI or path to the image file.
    15611562     * @param string $image_location Full path or URI to the tested image file.
    1562      * @param array  $image_meta     The image meta data being tested.
    1563      */
    1564     return apply_filters( 'wp_image_file_matches_image_meta', $match, $image_location, $image_meta );
     1563     * @param array  $image_meta     The image meta data as returned by 'wp_get_attachment_metadata()'.
     1564     * @param int    $attachment_id  The image attachment ID or 0 if not supplied.
     1565     */
     1566    return apply_filters( 'wp_image_file_matches_image_meta', $match, $image_location, $image_meta, $attachment_id );
    15651567}
    15661568
     
    15701572 * @since 5.5.0
    15711573 *
    1572  * @param string $image_src  The image source file.
    1573  * @param array  $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'.
     1574 * @param string $image_src     The image source file.
     1575 * @param array  $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
     1576 * @param int    $attachment_id Optional. The image attachment ID. Default 0.
    15741577 * @return array|false Array with first element being the width and second element being the height,
    15751578 *                     or false if dimensions cannot be determined.
    15761579 */
    1577 function wp_image_src_get_dimensions( $image_src, $image_meta ) {
    1578     if ( ! wp_image_file_matches_image_meta( $image_src, $image_meta ) ) {
     1580function wp_image_src_get_dimensions( $image_src, $image_meta, $attachment_id = 0 ) {
     1581    if ( ! wp_image_file_matches_image_meta( $image_src, $image_meta, $attachment_id ) ) {
    15791582        return false;
    15801583    }
     
    16441647        $size_array = array( $width, $height );
    16451648    } else {
    1646         $size_array = wp_image_src_get_dimensions( $image_src, $image_meta );
     1649        $size_array = wp_image_src_get_dimensions( $image_src, $image_meta, $attachment_id );
    16471650        if ( ! $size_array ) {
    16481651            return $image;
     
    18641867    if ( true === $add ) {
    18651868        $image_meta = wp_get_attachment_metadata( $attachment_id );
    1866         $size_array = wp_image_src_get_dimensions( $image_src, $image_meta );
     1869        $size_array = wp_image_src_get_dimensions( $image_src, $image_meta, $attachment_id );
    18671870
    18681871        if ( $size_array ) {
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php

    r48525 r48547  
    425425            ! $image_meta ||
    426426            ! $image_file ||
    427             ! wp_image_file_matches_image_meta( $request['src'], $image_meta )
     427            ! wp_image_file_matches_image_meta( $request['src'], $image_meta, $attachment_id )
    428428        ) {
    429429            return new WP_Error(
Note: See TracChangeset for help on using the changeset viewer.