WC_Admin_Status::get_file_version()public staticWC 2.1.1

Retrieve metadata from a file. Based on WP Core's get_file_data function.

Method of the class: WC_Admin_Status{}

No Hooks.

Return

String.

Usage

$result = WC_Admin_Status::get_file_version( $file );
$file(string) (required)
Path to the file.

Changelog

Since 2.1.1 Introduced.

WC_Admin_Status::get_file_version() code WC 8.7.0

public static function get_file_version( $file ) {

	// Avoid notices if file does not exist.
	if ( ! file_exists( $file ) ) {
		return '';
	}

	// We don't need to write to the file, so just open for reading.
	$fp = fopen( $file, 'r' ); // @codingStandardsIgnoreLine.

	// Pull only the first 8kiB of the file in.
	$file_data = fread( $fp, 8192 ); // @codingStandardsIgnoreLine.

	// PHP will close file handle, but we are good citizens.
	fclose( $fp ); // @codingStandardsIgnoreLine.

	// Make sure we catch CR-only line endings.
	$file_data = str_replace( "\r", "\n", $file_data );
	$version   = '';

	if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( '@version', '/' ) . '(.*)$/mi', $file_data, $match ) && $match[1] ) {
		$version = _cleanup_header_comment( $match[1] );
	}

	return $version;
}