_wp_image_meta_replace_original

函式
_wp_image_meta_replace_original ( $saved_data, $original_file, $image_meta, $attachment_id )
Access
Private
引數
  • (array) $saved_data The data returned from WP_Image_Editor after successfully saving an image.
    Required:
  • (string) $original_file Path to the original file.
    Required:
  • (array) $image_meta The image meta data.
    Required:
  • (int) $attachment_id The attachment post ID.
    Required:
返回值
  • (array) The updated image meta data.
定義位置
相關方法
wp_read_image_metadatawp_image_matches_ratiowp_image_editorwp_get_original_refererwp_get_cookie_login
引入
5.3.0
棄用
-

_wp_image_meta_replace_original: 這個函式用一個新圖片的後設資料來替換原始圖片的後設資料。它通常用於通過上傳相同檔名的新圖片來替換一個圖片。

當原始影象被編輯時,更新附件檔案和影象後設資料。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
// Add image file size.
$image_meta['filesize'] = wp_filesize( $new_file );
// Store the original image file name in image_meta.
$image_meta['original_image'] = wp_basename( $original_file );
return $image_meta;
}
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 ); // Add image file size. $image_meta['filesize'] = wp_filesize( $new_file ); // Store the original image file name in image_meta. $image_meta['original_image'] = wp_basename( $original_file ); return $image_meta; }
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 );

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

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

	return $image_meta;
}

常見問題

FAQs
檢視更多 >