# wp_image_file_matches_image_meta()

URL: https://chugunov.pro/api-wordpress/functions/wp_image_file_matches_image_meta/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 5.5.0.

## Сигнатура

```php
wp_image_file_matches_image_meta( string $image_location, array $image_meta, int $attachment_id ): bool
```

## Описание

Метаданные изображения извлекаются по идентификатору записи вложения. В некоторых случаях идентификаторы записей могут меняться.
Например, когда сайт экспортируется и импортируется на другой сайт. Тогда идентификаторы записей вложений в post_content экспортированного сайта могут не совпадать с теми же вложениями на новом сайте.

## Параметры

- `$image_location` `string` — обязательный. Полный путь или URI к файлу изображения.
- `$image_meta` `array` — обязательный. Метаданные вложения в том виде, в каком их возвращает «wp_get_attachment_metadata() ».
- `$attachment_id` `int` — необязательный. ID вложения-изображения. Значение по умолчанию — 0.

## Возвращаемое значение

`bool`

## Исходный код

Файл: `wp-includes/media.php:1650`

```php
function wp_image_file_matches_image_meta( $image_location, $image_meta, $attachment_id = 0 ) {
	$match = false;

	// Ensure the $image_meta is valid.
	if ( isset( $image_meta['file'] ) && strlen( $image_meta['file'] ) > 4 ) {
		// Remove query args in image URI.
		list( $image_location ) = explode( '?', $image_location );

		// Check if the relative image path from the image meta is at the end of $image_location.
		if ( strrpos( $image_location, $image_meta['file'] ) === strlen( $image_location ) - strlen( $image_meta['file'] ) ) {
			$match = true;
		} else {
			// Retrieve the uploads sub-directory from the full size image.
			$dirname = _wp_get_attachment_relative_path( $image_meta['file'] );

			if ( $dirname ) {
				$dirname = trailingslashit( $dirname );
			}

			if ( ! empty( $image_meta['original_image'] ) ) {
				$relative_path = $dirname . $image_meta['original_image'];

				if ( strrpos( $image_location, $relative_path ) === strlen( $image_location ) - strlen( $relative_path ) ) {
					$match = true;
				}
			}

			if ( ! $match && ! empty( $image_meta['sizes'] ) ) {
				foreach ( $image_meta['sizes'] as $image_size_data ) {
					$relative_path = $dirname . $image_size_data['file'];

					if ( strrpos( $image_location, $relative_path ) === strlen( $image_location ) - strlen( $relative_path ) ) {
						$match = true;
						break;
					}
				}
			}
		}
	}

	/**
	 * Filters whether an image path or URI matches image meta.
	 *
	 * @since 5.5.0
	 *
	 * @param bool   $match          Whether the image relative path from the image meta
	 *                               matches the end of the URI or path to the image file.
	 * @param string $image_location Full path or URI to the tested image file.
	 * @param array  $image_meta     The image meta data as returned by 'wp_get_attachment_metadata()'.
	 * @param int    $attachment_id  The image attachment ID or 0 if not supplied.
	 */
	return apply_filters( 'wp_image_file_matches_image_meta', $match, $image_location, $image_meta, $attachment_id );
}
```

## История изменений

- 5.5.0 — Introduced.

## Связанные

Использует: [`_wp_get_attachment_relative_path`](https://chugunov.pro/api-wordpress/functions/_wp_get_attachment_relative_path/), [`trailingslashit`](https://chugunov.pro/api-wordpress/functions/trailingslashit/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/).
Используется в: `WP_REST_Attachments_Controller::edit_media_item`.

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/wp_image_file_matches_image_meta/
