get_file_description

The timeline below displays how wordpress function get_file_description has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.5

/**
 * Gets the description for standard WordPress theme files.
 *
 * @since 1.5.0
 *
 * @global array $wp_file_descriptions Theme file descriptions.
 * @global array $allowed_files        List of allowed files.
 *
 * @param string $file Filesystem path or filename.
 * @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.
 */
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));
}

WordPress Version: 5.3

/**
 * Get the description for standard WordPress theme files and other various standard
 * WordPress files
 *
 * @since 1.5.0
 *
 * @global array $wp_file_descriptions Theme file descriptions.
 * @global array $allowed_files        List of allowed files.
 * @param string $file Filesystem path or filename
 * @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
 */
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));
}

WordPress Version: 4.9

/**
 * Get the description for standard WordPress theme files and other various standard
 * WordPress files
 *
 * @since 1.5.0
 *
 * @global array $wp_file_descriptions Theme file descriptions.
 * @global array $allowed_files        List of allowed files.
 * @param string $file Filesystem path or filename
 * @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
 */
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)) {
            return sprintf(__('%s Page Template'), _cleanup_header_comment($name[1]));
        }
    }
    return trim(basename($file));
}

WordPress Version: 4.7

/**
 * Get the description for standard WordPress theme files and other various standard
 * WordPress files
 *
 * @since 1.5.0
 *
 * @global array $wp_file_descriptions
 * @param string $file Filesystem path or filename
 * @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
 */
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)) {
            return sprintf(__('%s Page Template'), _cleanup_header_comment($name[1]));
        }
    }
    return trim(basename($file));
}

WordPress Version: 4.4

/**
 * Get the description for standard WordPress theme files and other various standard
 * WordPress files
 *
 * @since 1.5.0
 *
 * @global array $wp_file_descriptions
 * @param string $file Filesystem path or filename
 * @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
 */
function get_file_description($file)
{
    global $wp_file_descriptions, $allowed_files;
    $relative_pathinfo = pathinfo($file);
    $file_path = $allowed_files[$file];
    if (isset($wp_file_descriptions[basename($file)]) && '.' === $relative_pathinfo['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)) {
            return sprintf(__('%s Page Template'), _cleanup_header_comment($name[1]));
        }
    }
    return trim(basename($file));
}

WordPress Version: 4.3

/**
 * Get the description for standard WordPress theme files and other various standard
 * WordPress files
 *
 * @since 1.5.0
 *
 * @global array $wp_file_descriptions
 * @param string $file Filesystem path or filename
 * @return string Description of file from $wp_file_descriptions or basename of $file if description doesn't exist
 */
function get_file_description($file)
{
    global $wp_file_descriptions;
    if (isset($wp_file_descriptions[basename($file)])) {
        return $wp_file_descriptions[basename($file)];
    } elseif (file_exists($file) && is_file($file)) {
        $template_data = implode('', file($file));
        if (preg_match('|Template Name:(.*)$|mi', $template_data, $name)) {
            return sprintf(__('%s Page Template'), _cleanup_header_comment($name[1]));
        }
    }
    return trim(basename($file));
}

WordPress Version: 4.1

/**
 * Get the description for standard WordPress theme files and other various standard
 * WordPress files
 *
 * @since 1.5.0
 *
 * @uses $wp_file_descriptions
 * @param string $file Filesystem path or filename
 * @return string Description of file from $wp_file_descriptions or basename of $file if description doesn't exist
 */
function get_file_description($file)
{
    global $wp_file_descriptions;
    if (isset($wp_file_descriptions[basename($file)])) {
        return $wp_file_descriptions[basename($file)];
    } elseif (file_exists($file) && is_file($file)) {
        $template_data = implode('', file($file));
        if (preg_match('|Template Name:(.*)$|mi', $template_data, $name)) {
            return sprintf(__('%s Page Template'), _cleanup_header_comment($name[1]));
        }
    }
    return trim(basename($file));
}

WordPress Version: 3.7

/**
 * Get the description for standard WordPress theme files and other various standard
 * WordPress files
 *
 * @since 1.5.0
 *
 * @uses _cleanup_header_comment
 * @uses $wp_file_descriptions
 * @param string $file Filesystem path or filename
 * @return string Description of file from $wp_file_descriptions or basename of $file if description doesn't exist
 */
function get_file_description($file)
{
    global $wp_file_descriptions;
    if (isset($wp_file_descriptions[basename($file)])) {
        return $wp_file_descriptions[basename($file)];
    } elseif (file_exists($file) && is_file($file)) {
        $template_data = implode('', file($file));
        if (preg_match('|Template Name:(.*)$|mi', $template_data, $name)) {
            return sprintf(__('%s Page Template'), _cleanup_header_comment($name[1]));
        }
    }
    return trim(basename($file));
}