WP_REST_Attachments_Controller::get_attachment_filename │ protected │ WP 7.0.0

Gets the attachment's original file name.

Метод класса: WP_REST_Attachments_Controller{}

Хуков нет.

Возвращает

string|null. Attachment file name, or null if not found.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_attachment_filename( $attachment_id ): ?string;
$attachment_id(int) (обязательный)
Attachment ID.

Список изменений

С версии 7.0.0 Введена.

Код WP_REST_Attachments_Controller::get_attachment_filename() WP 7.1.2

protected function get_attachment_filename( int $attachment_id ): ?string {
	$path = wp_get_original_image_path( $attachment_id );

	if ( $path ) {
		return wp_basename( $path );
	}

	$path = get_attached_file( $attachment_id );

	if ( $path ) {
		return wp_basename( $path );
	}

	return null;
}