Advertisements

get_file_data

Definition:
function get_file_data( $file, $default_headers, $context = '' ) {}

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.

Parameters

  • string $file: Path to the file
  • array $default_headers: List of headers, in the format array(‘HeaderKey’ => ‘Header Name’)
  • string $context: If specified adds filter hook “extra_{$context}_headers”

Defined filters

  • extra_{$context}_headers
    apply_filters( "extra_{$context}_headers", array()

Source code

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



	if ( $context != '' ) {

		$extra_headers = apply_filters( "extra_{$context}_headers", array() );



		$extra_headers = array_flip( $extra_headers );

		foreach( $extra_headers as $key=>$value ) {

			$extra_headers[$key] = $key;

		}

		$all_headers = array_merge( $extra_headers, (array) $default_headers );

	} else {

1394

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: