WC_Admin_Status::get_file_version
Retrieve metadata from a file. Based on WP Core's get_file_data function.
Method of the class: WC_Admin_Status{}
No Hooks.
Returns
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() WC Admin Status::get file version code WC 10.6.2
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;
}