_add_block_template_info

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

WordPress Version: 6.4

/**
 * Attempts to add custom template information to the template item.
 *
 * @since 5.9.0
 * @access private
 *
 * @param array $template_item Template to add information to (requires 'slug' field).
 * @return array Template item.
 */
function _add_block_template_info($template_item)
{
    if (!wp_theme_has_theme_json()) {
        return $template_item;
    }
    $theme_data = wp_get_theme_data_custom_templates();
    if (isset($theme_data[$template_item['slug']])) {
        $template_item['title'] = $theme_data[$template_item['slug']]['title'];
        $template_item['postTypes'] = $theme_data[$template_item['slug']]['postTypes'];
    }
    return $template_item;
}

WordPress Version: 6.2

/**
 * Attempts to add custom template information to the template item.
 *
 * @since 5.9.0
 * @access private
 *
 * @param array $template_item Template to add information to (requires 'slug' field).
 * @return array Template item.
 */
function _add_block_template_info($template_item)
{
    if (!wp_theme_has_theme_json()) {
        return $template_item;
    }
    $theme_data = WP_Theme_JSON_Resolver::get_theme_data(array(), array('with_supports' => false))->get_custom_templates();
    if (isset($theme_data[$template_item['slug']])) {
        $template_item['title'] = $theme_data[$template_item['slug']]['title'];
        $template_item['postTypes'] = $theme_data[$template_item['slug']]['postTypes'];
    }
    return $template_item;
}

WordPress Version: 5.9

/**
 * Attempts to add custom template information to the template item.
 *
 * @since 5.9.0
 * @access private
 *
 * @param array $template_item Template to add information to (requires 'slug' field).
 * @return array Template item.
 */
function _add_block_template_info($template_item)
{
    if (!WP_Theme_JSON_Resolver::theme_has_support()) {
        return $template_item;
    }
    $theme_data = WP_Theme_JSON_Resolver::get_theme_data()->get_custom_templates();
    if (isset($theme_data[$template_item['slug']])) {
        $template_item['title'] = $theme_data[$template_item['slug']]['title'];
        $template_item['postTypes'] = $theme_data[$template_item['slug']]['postTypes'];
    }
    return $template_item;
}