get_file_data [ WordPress Function ]
| Parameters: |
|
| See: | |
| Defined at: |
|
Retrieve metadata from a file.
Searches for metadata in the first 8kiB of a file, such as a plugin or theme. Each piece of metadata must be on its own line. Fields can not span multiple lines, the value will get cut at the end of the first line.
If the file data is not within that first 8kiB, then the author should correct their plugin file and move the data headers to the top.
Source
<?php
function get_file_data( $file, $default_headers, $context = '' ) {
// We don't need to write to the file, so just open for reading.
$fp = fopen( $file, 'r' );
// Pull only the first 8kiB of the file in.
$file_data = fread( $fp, 8192 );
// PHP will close file handle, but we are good citizens.
fclose( $fp );
// Make sure we catch CR-only line endings.
$file_data = str_replace( "\r", "\n", $file_data );
if ( $context && $extra_headers = apply_filters( "extra_{$context}_headers", array() ) ) {
$extra_headers = array_combine( $extra_headers, $extra_headers ); // keys equal values
$all_headers = array_merge( $extra_headers, (array) $default_headers );
} else {
$all_headers = $default_headers;
}
foreach ( $all_headers as $field => $regex ) {
if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $match[1] )
$all_headers[ $field ] = _cleanup_header_comment( $match[1] );
else
$all_headers[ $field ] = '';
}
return $all_headers;
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- Function Reference/get file data « WordPress Codex
Function Reference/get file data. Description. get_file_data is the name of a function in the global namespace within WordPress. It is a File Header related ...
codex.wordpress.org - #17060 (Code cleanup in get_file_data()) – WordPress Trac
The patch that originally introduced the get_file_data() function had a spot that was not PHP 4 compatible. The fix was a bit clunky, but necessary at the time.
core.trac.wordpress.org - get_file_data | A HitchHackers guide through WordPress
Feb 12, 2011 ... function get_file_data( $file, $default_headers, $context = '' ) { // We don't need to write to the file, so just open for reading. $fp = fopen( $file, 'r' ) ...
hitchhackerguide.com - Return Value of get_file_data
Aug 9, 2006 ... get_file_data() returns a reference (like a pointer in C) to a variable that contains the file data. Try: print $$filecontents2; The first dollar sign will ...
lists.danga.com