get_file_description

函式
get_file_description ( $file )
引數
  • (string) $file Filesystem path or filename.
    Required:
返回值
  • (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.
定義位置
相關方法
term_descriptionget_the_archive_descriptionget_the_author_descriptionthe_archive_descriptiontag_description
引入
1.5.0
棄用
-

get_file_description: WordPress函式,用於檢索一個指定檔案的描述: 該函式以檔案路徑為引數,如果檔案存在,則返回檔案描述。如果該檔案沒有描述,該函式返回一個空字串。

獲取標準WordPress主題檔案的描述。

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

常見問題

FAQs
檢視更多 >