get_file_description

Get the description for standard WordPress theme files and other various standard WordPress files.

Description

(string) get_file_description( (string) $file ); 

Returns (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

Parameters (1)

0. $file (string)
Filesystem path or filename

Usage

  1. if ( !function_exists( 'get_file_description' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/file.php'; 
  3.  
  4. // Filesystem path or filename 
  5. $file = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_file_description($file); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/file.php  
  1. function get_file_description( $file ) { 
  2. global $wp_file_descriptions, $allowed_files; 
  3.  
  4. $dirname = pathinfo( $file, PATHINFO_DIRNAME ); 
  5.  
  6. $file_path = $allowed_files[ $file ]; 
  7. if ( isset( $wp_file_descriptions[ basename( $file ) ] ) && '.' === $dirname ) { 
  8. return $wp_file_descriptions[ basename( $file ) ]; 
  9. } elseif ( file_exists( $file_path ) && is_file( $file_path ) ) { 
  10. $template_data = implode( '', file( $file_path ) ); 
  11. if ( preg_match( '|Template Name:(.*)$|mi', $template_data, $name ) ) { 
  12. return sprintf( __( '%s Page Template' ), _cleanup_header_comment( $name[1] ) ); 
  13.  
  14. return trim( basename( $file ) );