Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

_wp_image_meta_replace_original() WordPress Function

The wp_image_meta_replace_original() function is used to update the image meta data for a given image. This function will replace the original image file with the new image file.

_wp_image_meta_replace_original( array $saved_data, string $original_file, array $image_meta, int $attachment_id ) #

Updates the attached file and image meta data when the original image was edited.


Parameters

$saved_data

(array)(Required)The data returned from WP_Image_Editor after successfully saving an image.

$original_file

(string)(Required)Path to the original file.

$image_meta

(array)(Required)The image meta data.

$attachment_id

(int)(Required)The attachment post ID.


Top ↑

Return

(array) The updated image meta data.


Top ↑

Source

File: wp-admin/includes/image.php

function _wp_image_meta_replace_original( $saved_data, $original_file, $image_meta, $attachment_id ) {
	$new_file = $saved_data['path'];

	// Update the attached file meta.
	update_attached_file( $attachment_id, $new_file );

	// Width and height of the new image.
	$image_meta['width']  = $saved_data['width'];
	$image_meta['height'] = $saved_data['height'];

	// Make the file path relative to the upload dir.
	$image_meta['file'] = _wp_relative_upload_path( $new_file );

	// Store the original image file name in image_meta.
	$image_meta['original_image'] = wp_basename( $original_file );

	// Add image file size.
	$image_meta['filesize'] = wp_filesize( $new_file );

	return $image_meta;
}


Top ↑

Changelog

Changelog
VersionDescription
5.3.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.