# wp_get_missing_image_subsizes()

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

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

## Сигнатура

```php
wp_get_missing_image_subsizes( int $attachment_id ): array[]
```

## Описание

Зарегистрированные подразмеры, превышающие размер изображения, пропускаются.

## Параметры

- `$attachment_id` `int` — обязательный. ID записи-вложения изображения.

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

`array[]`

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

Файл: `wp-admin/includes/image.php:87`

```php
function wp_get_missing_image_subsizes( $attachment_id ) {
	if ( ! wp_attachment_is_image( $attachment_id ) ) {
		return array();
	}

	$registered_sizes = wp_get_registered_image_subsizes();
	$image_meta       = wp_get_attachment_metadata( $attachment_id );

	// Meta error?
	if ( empty( $image_meta ) ) {
		return $registered_sizes;
	}

	// Use the originally uploaded image dimensions as full_width and full_height.
	if ( ! empty( $image_meta['original_image'] ) ) {
		$image_file = wp_get_original_image_path( $attachment_id );
		$imagesize  = wp_getimagesize( $image_file );
	}

	if ( ! empty( $imagesize ) ) {
		$full_width  = $imagesize[0];
		$full_height = $imagesize[1];
	} else {
		$full_width  = (int) $image_meta['width'];
		$full_height = (int) $image_meta['height'];
	}

	$possible_sizes = array();

	// Skip registered sizes that are too large for the uploaded image.
	foreach ( $registered_sizes as $size_name => $size_data ) {
		if ( image_resize_dimensions( $full_width, $full_height, $size_data['width'], $size_data['height'], $size_data['crop'] ) ) {
			$possible_sizes[ $size_name ] = $size_data;
		}
	}

	if ( empty( $image_meta['sizes'] ) ) {
		$image_meta['sizes'] = array();
	}

	/*
	 * Remove sizes that already exist. Only checks for matching "size names".
	 * It is possible that the dimensions for a particular size name have changed.
	 * For example the user has changed the values on the Settings -> Media screen.
	 * However we keep the old sub-sizes with the previous dimensions
	 * as the image may have been used in an older post.
	 */
	$missing_sizes = array_diff_key( $possible_sizes, $image_meta['sizes'] );

	/**
	 * Filters the array of missing image sub-sizes for an uploaded image.
	 *
	 * @since 5.3.0
	 *
	 * @param array[] $missing_sizes Associative array of arrays of image sub-size information for
	 *                               missing image sizes, keyed by image size name.
	 * @param array   $image_meta    The image meta data.
	 * @param int     $attachment_id The image attachment post ID.
	 */
	return apply_filters( 'wp_get_missing_image_subsizes', $missing_sizes, $image_meta, $attachment_id );
}
```

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

- 5.3.0 — Introduced.

## Связанные

Использует: [`wp_getimagesize`](https://chugunov.pro/api-wordpress/functions/wp_getimagesize/), [`wp_get_original_image_path`](https://chugunov.pro/api-wordpress/functions/wp_get_original_image_path/), [`wp_get_registered_image_subsizes`](https://chugunov.pro/api-wordpress/functions/wp_get_registered_image_subsizes/), [`image_resize_dimensions`](https://chugunov.pro/api-wordpress/functions/image_resize_dimensions/), [`WP_Image_Editor`](https://chugunov.pro/api-wordpress/functions/wp_image_editor/), [`wp_attachment_is_image`](https://chugunov.pro/api-wordpress/functions/wp_attachment_is_image/), [`wp_get_attachment_metadata`](https://chugunov.pro/api-wordpress/functions/wp_get_attachment_metadata/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/).
Используется в: [`wp_update_image_subsizes`](https://chugunov.pro/api-wordpress/functions/wp_update_image_subsizes/), `WP_REST_Attachments_Controller::prepare_item_for_response`.

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