# _wp_make_subsizes()

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

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

## Сигнатура

```php
_wp_make_subsizes( array $new_sizes, string $file, array $image_meta, int $attachment_id ): array
```

## Описание

Обновляет метаданные изображения после создания каждого подразмера.
Ошибки сохраняются в возвращаемом массиве метаданных изображения.

## Параметры

- `$new_sizes` `array` — обязательный. Массив, определяющий, какие размеры создавать.
- `$file` `string` — обязательный. Полный путь к файлу изображения.
- `$image_meta` `array` — обязательный. Массив метаданных вложения.
- `$attachment_id` `int` — обязательный. ID вложения для обработки.

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

`array` — sizes

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

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

```php
function _wp_make_subsizes( $new_sizes, $file, $image_meta, $attachment_id ) {
	if ( empty( $image_meta ) || ! is_array( $image_meta ) ) {
		// Not an image attachment.
		return array();
	}

	// Check if any of the new sizes already exist.
	if ( isset( $image_meta['sizes'] ) && is_array( $image_meta['sizes'] ) ) {
		foreach ( $image_meta['sizes'] as $size_name => $size_meta ) {
			/*
			 * Only checks "size name" so we don't override existing images even if the dimensions
			 * don't match the currently defined size with the same name.
			 * To change the behavior, unset changed/mismatched sizes in the `sizes` array in image meta.
			 */
			if ( array_key_exists( $size_name, $new_sizes ) ) {
				unset( $new_sizes[ $size_name ] );
			}
		}
	} else {
		$image_meta['sizes'] = array();
	}

	if ( empty( $new_sizes ) ) {
		// Nothing to do...
		return $image_meta;
	}

	/*
	 * Sort the image sub-sizes in order of priority when creating them.
	 * This ensures there is an appropriate sub-size the user can access immediately
	 * even when there was an error and not all sub-sizes were created.
	 */
	$priority = array(
		'medium'       => null,
		'large'        => null,
		'thumbnail'    => null,
		'medium_large' => null,
	);

	$new_sizes = array_filter( array_merge( $priority, $new_sizes ) );

	$editor = wp_get_image_editor( $file );

	if ( is_wp_error( $editor ) ) {
		// The image cannot be edited.
		return $image_meta;
	}

	// If stored EXIF data exists, rotate the source image before creating sub-sizes.
	if ( ! empty( $image_meta['image_meta'] ) ) {
		$rotated = $editor->maybe_exif_rotate();

		if ( is_wp_error( $rotated ) ) {
			// TODO: Log errors.
		}
	}

	if ( method_exists( $editor, 'make_subsize' ) ) {
		foreach ( $new_sizes as $new_size_name => $new_size_data ) {
			$new_size_meta = $editor->make_subsize( $new_size_data );

			if ( is_wp_error( $new_size_meta ) ) {
				// TODO: Log errors.
			} else {
				// Save the size meta value.
				$image_meta['sizes'][ $new_size_name ] = $new_size_meta;
				wp_update_attachment_metadata( $attachment_id, $image_meta );
			}
		}
	} else {
		// Fall back to `$editor->multi_resize()`.
		$created_sizes = $editor->multi_resize( $new_sizes );

		if ( ! empty( $created_sizes ) ) {
			$image_meta['sizes'] = array_merge( $image_meta['sizes'], $created_sizes );
			wp_update_attachment_metadata( $attachment_id, $image_meta );
		}
	}

	return $image_meta;
}
```

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

- 5.3.0 — Introduced.

## Связанные

Использует: [`wp_get_image_editor`](https://chugunov.pro/api-wordpress/functions/wp_get_image_editor/), [`WP_Image_Editor`](https://chugunov.pro/api-wordpress/functions/wp_image_editor/), [`wp_update_attachment_metadata`](https://chugunov.pro/api-wordpress/functions/wp_update_attachment_metadata/), [`is_wp_error`](https://chugunov.pro/api-wordpress/functions/is_wp_error/).
Используется в: [`wp_update_image_subsizes`](https://chugunov.pro/api-wordpress/functions/wp_update_image_subsizes/), [`wp_create_image_subsizes`](https://chugunov.pro/api-wordpress/functions/wp_create_image_subsizes/), [`wp_generate_attachment_metadata`](https://chugunov.pro/api-wordpress/functions/wp_generate_attachment_metadata/).

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