Automattic\WooCommerce\Internal\Admin\Logging\FileV2

FileController::get_file_by_idpublicWC 1.0

Get a File instance from a file ID.

Method of the class: FileController{}

No Hooks.

Returns

File|WP_Error.

Usage

$FileController = new FileController();
$FileController->get_file_by_id( $file_id );
$file_id(string) (required)
A file ID (file basename without the hash).

FileController::get_file_by_id() code WC 10.8.1

public function get_file_by_id( string $file_id ) {
	$result = $this->get_files_by_id( array( $file_id ) );

	if ( count( $result ) < 1 ) {
		return new WP_Error(
			'wc_log_file_error',
			esc_html__( 'This file does not exist.', 'woocommerce' )
		);
	}

	if ( count( $result ) > 1 ) {
		return new WP_Error(
			'wc_log_file_error',
			esc_html__( 'Multiple files match this ID.', 'woocommerce' )
		);
	}

	return reset( $result );
}