get_file_description() WordPress Function

The get_file_description() function is used to get the description of a file. The function takes one parameter, which is the file path. The function returns a string containing the file description.

get_file_description( string $file ) #

Gets the description for standard WordPress theme files.


Parameters

$file

(string)(Required)Filesystem path or filename.


Top ↑

Return

(string) Description of file from $wp_file_descriptions or basename of $file if description doesn't exist. Appends 'Page Template' to basename of $file if the file is a page template.


Top ↑

Source

File: wp-admin/includes/file.php

function get_file_description( $file ) {
	global $wp_file_descriptions, $allowed_files;

	$dirname   = pathinfo( $file, PATHINFO_DIRNAME );
	$file_path = $allowed_files[ $file ];

	if ( isset( $wp_file_descriptions[ basename( $file ) ] ) && '.' === $dirname ) {
		return $wp_file_descriptions[ basename( $file ) ];
	} elseif ( file_exists( $file_path ) && is_file( $file_path ) ) {
		$template_data = implode( '', file( $file_path ) );

		if ( preg_match( '|Template Name:(.*)$|mi', $template_data, $name ) ) {
			/* translators: %s: Template name. */
			return sprintf( __( '%s Page Template' ), _cleanup_header_comment( $name[1] ) );
		}
	}

	return trim( basename( $file ) );
}


Top ↑

Changelog

Changelog
VersionDescription
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.