# wp_attachment_is()

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

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

## Сигнатура

```php
wp_attachment_is( string $type, int|WP_Post $post = null ): bool
```

## Описание

Проверяет, что вложение имеет заданный тип.

## Параметры

- `$type` `string` — обязательный. Тип вложения. Принимает image, audio, video или расширение файла.
- `$post` `int|WP_Post` — необязательный, по умолчанию `null`. ID или объект вложения. По умолчанию — глобальный $post.

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

`bool`

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

Файл: `wp-includes/post.php:7110`

```php
function wp_attachment_is( $type, $post = null ) {
	$post = get_post( $post );

	if ( ! $post ) {
		return false;
	}

	$file = get_attached_file( $post->ID );

	if ( ! $file ) {
		return false;
	}

	if ( str_starts_with( $post->post_mime_type, $type . '/' ) ) {
		return true;
	}

	$check = wp_check_filetype( $file );

	if ( empty( $check['ext'] ) ) {
		return false;
	}

	$ext = $check['ext'];

	if ( 'import' !== $post->post_mime_type ) {
		return $type === $ext;
	}

	switch ( $type ) {
		case 'image':
			$image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'webp', 'avif', 'heic' );
			return in_array( $ext, $image_exts, true );

		case 'audio':
			return in_array( $ext, wp_get_audio_extensions(), true );

		case 'video':
			return in_array( $ext, wp_get_video_extensions(), true );

		default:
			return $type === $ext;
	}
}
```

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

- 4.2.0 — Introduced.

## Связанные

Использует: [`wp_check_filetype`](https://chugunov.pro/api-wordpress/functions/wp_check_filetype/), [`wp_get_video_extensions`](https://chugunov.pro/api-wordpress/functions/wp_get_video_extensions/), [`wp_get_audio_extensions`](https://chugunov.pro/api-wordpress/functions/wp_get_audio_extensions/), [`get_attached_file`](https://chugunov.pro/api-wordpress/functions/get_attached_file/), [`get_post`](https://chugunov.pro/api-wordpress/functions/get_post/).
Используется в: `WP_REST_Attachments_Controller::handle_featured_media`, [`register_and_do_post_meta_boxes`](https://chugunov.pro/api-wordpress/functions/register_and_do_post_meta_boxes/), `WP_Widget_Media::is_attachment_with_mime_type`, [`get_oembed_response_data_rich`](https://chugunov.pro/api-wordpress/functions/get_oembed_response_data_rich/), [`wp_generate_attachment_metadata`](https://chugunov.pro/api-wordpress/functions/wp_generate_attachment_metadata/), [`edit_form_image_editor`](https://chugunov.pro/api-wordpress/functions/edit_form_image_editor/), [`wp_ajax_send_attachment_to_editor`](https://chugunov.pro/api-wordpress/functions/wp_ajax_send_attachment_to_editor/), [`wp_ajax_save_attachment`](https://chugunov.pro/api-wordpress/functions/wp_ajax_save_attachment/), [`prepend_attachment`](https://chugunov.pro/api-wordpress/functions/prepend_attachment/), [`wp_enqueue_media`](https://chugunov.pro/api-wordpress/functions/wp_enqueue_media/), [`wp_attachment_is_image`](https://chugunov.pro/api-wordpress/functions/wp_attachment_is_image/), [`wp_insert_post`](https://chugunov.pro/api-wordpress/functions/wp_insert_post/).

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