# get_media_states()

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

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

## Сигнатура

```php
get_media_states( WP_Post $post ): string[]
```

## Описание

Возвращает массив состояний медиафайла для вложения.

## Параметры

- `$post` `WP_Post` — обязательный. Вложение, для которого возвращаются состояния.

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

`string[]`

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

Файл: `wp-admin/includes/template.php:2418`

```php
function get_media_states( $post ) {
	static $header_images;

	$media_states = array();
	$stylesheet   = get_option( 'stylesheet' );

	if ( current_theme_supports( 'custom-header' ) ) {
		$meta_header = get_post_meta( $post->ID, '_wp_attachment_is_custom_header', true );

		if ( is_random_header_image() ) {
			if ( ! isset( $header_images ) ) {
				$header_images = wp_list_pluck( get_uploaded_header_images(), 'attachment_id' );
			}

			if ( $meta_header === $stylesheet && in_array( $post->ID, $header_images, true ) ) {
				$media_states[] = __( 'Header Image' );
			}
		} else {
			$header_image = get_header_image();

			// Display "Header Image" if the image was ever used as a header image.
			if ( ! empty( $meta_header ) && $meta_header === $stylesheet && wp_get_attachment_url( $post->ID ) !== $header_image ) {
				$media_states[] = __( 'Header Image' );
			}

			// Display "Current Header Image" if the image is currently the header image.
			if ( $header_image && wp_get_attachment_url( $post->ID ) === $header_image ) {
				$media_states[] = __( 'Current Header Image' );
			}
		}

		if ( get_theme_support( 'custom-header', 'video' ) && has_header_video() ) {
			$mods = get_theme_mods();
			if ( isset( $mods['header_video'] ) && $post->ID === $mods['header_video'] ) {
				$media_states[] = __( 'Current Header Video' );
			}
		}
	}

	if ( current_theme_supports( 'custom-background' ) ) {
		$meta_background = get_post_meta( $post->ID, '_wp_attachment_is_custom_background', true );

		if ( ! empty( $meta_background ) && $meta_background === $stylesheet ) {
			$media_states[] = __( 'Background Image' );

			$background_image = get_background_image();
			if ( $background_image && wp_get_attachment_url( $post->ID ) === $background_image ) {
				$media_states[] = __( 'Current Background Image' );
			}
		}
	}

	if ( (int) get_option( 'site_icon' ) === $post->ID ) {
		$media_states[] = __( 'Site Icon' );
	}

	if ( (int) get_theme_mod( 'custom_logo' ) === $post->ID ) {
		$media_states[] = __( 'Logo' );
	}

	/**
	 * Filters the default media display states for items in the Media list table.
	 *
	 * @since 3.2.0
	 * @since 4.8.0 Added the `$post` parameter.
	 *
	 * @param string[] $media_states An array of media states. Default 'Header Image',
	 *                               'Background Image', 'Site Icon', 'Logo'.
	 * @param WP_Post  $post         The current attachment object.
	 */
	return apply_filters( 'display_media_states', $media_states, $post );
}
```

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

- 5.6.0 — Introduced.

## Связанные

Использует: [`has_header_video`](https://chugunov.pro/api-wordpress/functions/has_header_video/), [`get_theme_support`](https://chugunov.pro/api-wordpress/functions/get_theme_support/), [`is_random_header_image`](https://chugunov.pro/api-wordpress/functions/is_random_header_image/), [`get_uploaded_header_images`](https://chugunov.pro/api-wordpress/functions/get_uploaded_header_images/), [`get_header_image`](https://chugunov.pro/api-wordpress/functions/get_header_image/), [`get_background_image`](https://chugunov.pro/api-wordpress/functions/get_background_image/), [`get_theme_mods`](https://chugunov.pro/api-wordpress/functions/get_theme_mods/), [`get_theme_mod`](https://chugunov.pro/api-wordpress/functions/get_theme_mod/), [`wp_list_pluck`](https://chugunov.pro/api-wordpress/functions/wp_list_pluck/), [`wp_get_attachment_url`](https://chugunov.pro/api-wordpress/functions/wp_get_attachment_url/), [`current_theme_supports`](https://chugunov.pro/api-wordpress/functions/current_theme_supports/), [`__`](https://chugunov.pro/api-wordpress/functions/__/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), [`get_option`](https://chugunov.pro/api-wordpress/functions/get_option/), [`get_post_meta`](https://chugunov.pro/api-wordpress/functions/get_post_meta/).
Используется в: [`_media_states`](https://chugunov.pro/api-wordpress/functions/_media_states/), [`wp_prepare_attachment_for_js`](https://chugunov.pro/api-wordpress/functions/wp_prepare_attachment_for_js/).

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