: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if ( ! empty( $exif['ExposureTime'] ) ) {
$meta['shutter_speed'] = (string) $exif['ExposureTime'];
if ( is_scalar( $exif['ExposureTime'] ) ) {
$meta['shutter_speed'] = (string) wp_exif_frac2dec( $exif['ExposureTime'] );
if ( ! empty( $exif['Orientation'] ) ) {
$meta['orientation'] = $exif['Orientation'];
foreach ( array( 'title', 'caption', 'credit', 'copyright', 'camera', 'iso' ) as $key ) {
if ( $meta[ $key ] && ! seems_utf8( $meta[ $key ] ) ) {
$meta[ $key ] = utf8_encode( $meta[ $key ] );
foreach ( $meta['keywords'] as $key => $keyword ) {
if ( ! seems_utf8( $keyword ) ) {
$meta['keywords'][ $key ] = utf8_encode( $keyword );
$meta = wp_kses_post_deep( $meta );
* Filters the array of meta data read from an image's exif data.
* @since 4.4.0 The `$iptc` parameter was added.
* @since 5.0.0 The `$exif` parameter was added.
* @param array $meta Image meta data.
* @param string $file Path to image file.
* @param int $image_type Type of image, one of the `IMAGETYPE_XXX` constants.
* @param array $iptc IPTC data.
* @param array $exif EXIF data.
return apply_filters( 'wp_read_image_metadata', $meta, $file, $image_type, $iptc, $exif );
* Validates that file is an image.
* @param string $path File path to test if valid image.
* @return bool True if valid image, false if not valid image.
function file_is_valid_image( $path ) {
$size = wp_getimagesize( $path );
* Validates that file is suitable for displaying within a web page.
* @param string $path File path to test.
* @return bool True if suitable, false if not suitable.
function file_is_displayable_image( $path ) {
$displayable_image_types = array( IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_ICO, IMAGETYPE_WEBP, IMAGETYPE_AVIF );
$info = wp_getimagesize( $path );
} elseif ( ! in_array( $info[2], $displayable_image_types, true ) ) {
* Filters whether the current image is displayable in the browser.
* @param bool $result Whether the image can be displayed. Default true.
* @param string $path Path to the image.
return apply_filters( 'file_is_displayable_image', $result, $path );
* Loads an image resource for editing.
* @param int $attachment_id Attachment ID.
* @param string $mime_type Image mime type.
* @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array
* of width and height values in pixels (in that order). Default 'full'.
* @return resource|GdImage|false The resulting image resource or GdImage instance on success,
function load_image_to_edit( $attachment_id, $mime_type, $size = 'full' ) {
$filepath = _load_image_to_edit_path( $attachment_id, $size );
if ( empty( $filepath ) ) {
$image = imagecreatefromjpeg( $filepath );
$image = imagecreatefrompng( $filepath );
$image = imagecreatefromgif( $filepath );
if ( function_exists( 'imagecreatefromwebp' ) ) {
$image = imagecreatefromwebp( $filepath );
if ( is_gd_image( $image ) ) {
* Filters the current image being loaded for editing.
* @param resource|GdImage $image Current image.
* @param int $attachment_id Attachment ID.
* @param string|int[] $size Requested image size. Can be any registered image size name, or
* an array of width and height values in pixels (in that order).
$image = apply_filters( 'load_image_to_edit', $image, $attachment_id, $size );
if ( function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' ) ) {
imagealphablending( $image, false );
imagesavealpha( $image, true );
* Retrieves the path or URL of an attachment's attached file.
* If the attached file is not present on the local filesystem (usually due to replication plugins),
* then the URL of the file is returned if `allow_url_fopen` is supported.
* @param int $attachment_id Attachment ID.
* @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array
* of width and height values in pixels (in that order). Default 'full'.
* @return string|false File path or URL on success, false on failure.
function _load_image_to_edit_path( $attachment_id, $size = 'full' ) {
$filepath = get_attached_file( $attachment_id );
if ( $filepath && file_exists( $filepath ) ) {
if ( 'full' !== $size ) {
$data = image_get_intermediate_size( $attachment_id, $size );
$filepath = path_join( dirname( $filepath ), $data['file'] );
* Filters the path to an attachment's file when editing the image.
* The filter is evaluated for all image sizes except 'full'.
* @param string $path Path to the current image.
* @param int $attachment_id Attachment ID.
* @param string|int[] $size Requested image size. Can be any registered image size name, or
* an array of width and height values in pixels (in that order).
$filepath = apply_filters( 'load_image_to_edit_filesystempath', $filepath, $attachment_id, $size );
} elseif ( function_exists( 'fopen' ) && ini_get( 'allow_url_fopen' ) ) {
* Filters the path to an attachment's URL when editing the image.
* The filter is only evaluated if the file isn't stored locally and `allow_url_fopen` is enabled on the server.
* @param string|false $image_url Current image URL.
* @param int $attachment_id Attachment ID.
* @param string|int[] $size Requested image size. Can be any registered image size name, or
* an array of width and height values in pixels (in that order).
$filepath = apply_filters( 'load_image_to_edit_attachmenturl', wp_get_attachment_url( $attachment_id ), $attachment_id, $size );
* Filters the returned path or URL of the current image.
* @param string|false $filepath File path or URL to current image, or false.
* @param int $attachment_id Attachment ID.
* @param string|int[] $size Requested image size. Can be any registered image size name, or
* an array of width and height values in pixels (in that order).
return apply_filters( 'load_image_to_edit_path', $filepath, $attachment_id, $size );
* Copies an existing image file.
* @param int $attachment_id Attachment ID.
* @return string|false New file path on success, false on failure.
function _copy_image_file( $attachment_id ) {
$dst_file = get_attached_file( $attachment_id );
if ( ! file_exists( $src_file ) ) {
$src_file = _load_image_to_edit_path( $attachment_id );
$dst_file = str_replace( wp_basename( $dst_file ), 'copy-' . wp_basename( $dst_file ), $dst_file );
$dst_file = dirname( $dst_file ) . '/' . wp_unique_filename( dirname( $dst_file ), wp_basename( $dst_file ) );
* The directory containing the original file may no longer
* exist when using a replication plugin.
wp_mkdir_p( dirname( $dst_file ) );
if ( ! copy( $src_file, $dst_file ) ) {