WordPress.org

Make WordPress Core

Ticket #32378: 32378.patch

File 32378.patch, 1.5 KB (added by dmsnell, 4 years ago)

Remove OLYMPUS DIGITAL CAMERA and use file name if present

  • wp-admin/includes/image.php

     
    418418}
    419419
    420420/**
     421 * Filters unwanted default metadata from Olympus cameras
     422 *
     423 * Olympus cameras store a default value in the fields
     424 * that we use to get the title and caption. This issue
     425 * impacts other photo sharing sites and apps in addition
     426 * to WordPress.
     427 *
     428 * Clear out those default values if they come through and
     429 * use the additional EXIF data stored by the Olympus
     430 * cameras for the image file name if it exists.
     431 *
     432 * @since 4.3.0
     433 *
     434 * @param array $meta
     435 * @param string $file
     436 * @param $sourceImageType Image type constant
     437 */
     438function filter_olympus_image_metadata( $meta, $file, $sourceImageType ) {
     439        if ( 'OLYMPUS DIGITAL CAMERA' === $meta['title'] ) {
     440                $meta['title'] = '';
     441
     442                if ( is_callable( 'exif_read_data' ) && in_array( $sourceImageType, apply_filters( 'wp_read_image_metadata_types', array( IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM ) ) ) ) {
     443                        $exif = @exif_read_data( $file );
     444
     445                        if ( ! empty( $exif[ 'FileName' ] ) ) {
     446                                $meta['title'] = trim( $exif[ 'FileName'] );
     447                        }
     448                }
     449        }
     450
     451        if ( 'OLYMPUS DIGITAL CAMERA' === $meta['caption'] ) {
     452                $meta['caption'] = '';
     453        }
     454
     455        return $meta;
     456}
     457add_filter( 'wp_read_image_metadata', 'filter_olympus_image_metadata', 10, 3 );
     458
     459/**
    421460 * Validate that file is an image.
    422461 *
    423462 * @since 2.5.0