WP_REST_Attachments_Controller::get_attachment_filename( int $attachment_id ): string|null

In this article

Gets the attachment’s original file name.

Parameters

$attachment_idintrequired
Attachment ID.

Return

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

Source

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;
}

Changelog

VersionDescription
7.0.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.