函数原型
get_file_description( string $file ): string
函数描述
Gets the description for standard WordPress theme files.
是否弃用
未弃用
函数参数
-
$file
string
Required - Filesystem path or filename.
函数返回值
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.
函数位置
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 ) );
}
源码链接
变更日志
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |

