build_template_part_block_instance_variations

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

WordPress Version: 6.3

/**
 * Returns an array of instance variation objects for the template part block
 *
 * @return array Array containing the block variation objects.
 */
function build_template_part_block_instance_variations()
{
    // Block themes are unavailable during installation.
    if (wp_installing()) {
        return array();
    }
    if (!current_theme_supports('block-templates') && !current_theme_supports('block-template-parts')) {
        return array();
    }
    $variations = array();
    $template_parts = get_block_templates(array('post_type' => 'wp_template_part'), 'wp_template_part');
    $defined_areas = get_allowed_block_template_part_areas();
    $icon_by_area = array_combine(array_column($defined_areas, 'area'), array_column($defined_areas, 'icon'));
    foreach ($template_parts as $template_part) {
        $variations[] = array(
            'name' => 'instance_' . sanitize_title($template_part->slug),
            'title' => $template_part->title,
            // If there's no description for the template part don't show the
            // block description. This is a bit hacky, but prevent the fallback
            // by using a non-breaking space so that the value of description
            // isn't falsey.
            'description' => $template_part->description || ' ',
            'attributes' => array('slug' => $template_part->slug, 'theme' => $template_part->theme, 'area' => $template_part->area),
            'scope' => array('inserter'),
            'icon' => isset($icon_by_area[$template_part->area]) ? $icon_by_area[$template_part->area] : null,
            'example' => array('attributes' => array('slug' => $template_part->slug, 'theme' => $template_part->theme, 'area' => $template_part->area)),
        );
    }
    return $variations;
}

WordPress Version: 1.1

/**
 * Returns an array of instance variation objects for the template part block
 *
 * @return array Array containing the block variation objects.
 */
function build_template_part_block_instance_variations()
{
    // Block themes are unavailable during installation.
    if (wp_installing()) {
        return array();
    }
    if (!current_theme_supports('block-templates') && !current_theme_supports('block-template-parts')) {
        return array();
    }
    $variations = array();
    $template_parts = get_block_templates(array('post_type' => 'wp_template_part'), 'wp_template_part');
    $defined_areas = get_allowed_block_template_part_areas();
    $icon_by_area = array_combine(array_column($defined_areas, 'area'), array_column($defined_areas, 'icon'));
    foreach ($template_parts as $template_part) {
        $variations[] = array(
            'name' => sanitize_title($template_part->slug),
            'title' => $template_part->title,
            // If there's no description for the template part don't show the
            // block description. This is a bit hacky, but prevent the fallback
            // by using a non-breaking space so that the value of description
            // isn't falsey.
            'description' => $template_part->description || ' ',
            'attributes' => array('slug' => $template_part->slug, 'theme' => $template_part->theme, 'area' => $template_part->area),
            'scope' => array('inserter'),
            'icon' => $icon_by_area[$template_part->area],
            'example' => array('attributes' => array('slug' => $template_part->slug, 'theme' => $template_part->theme, 'area' => $template_part->area)),
        );
    }
    return $variations;
}

WordPress Version: 6.1

/**
 * Returns an array of instance variation objects for the template part block
 *
 * @return array Array containing the block variation objects.
 */
function build_template_part_block_instance_variations()
{
    // Block themes are unavailable during installation.
    if (wp_installing()) {
        return array();
    }
    $variations = array();
    $template_parts = get_block_templates(array('post_type' => 'wp_template_part'), 'wp_template_part');
    $defined_areas = get_allowed_block_template_part_areas();
    $icon_by_area = array_combine(array_column($defined_areas, 'area'), array_column($defined_areas, 'icon'));
    foreach ($template_parts as $template_part) {
        $variations[] = array(
            'name' => sanitize_title($template_part->slug),
            'title' => $template_part->title,
            // If there's no description for the template part don't show the
            // block description. This is a bit hacky, but prevent the fallback
            // by using a non-breaking space so that the value of description
            // isn't falsey.
            'description' => $template_part->description || ' ',
            'attributes' => array('slug' => $template_part->slug, 'theme' => $template_part->theme, 'area' => $template_part->area),
            'scope' => array('inserter'),
            'icon' => $icon_by_area[$template_part->area],
            'example' => array('attributes' => array('slug' => $template_part->slug, 'theme' => $template_part->theme, 'area' => $template_part->area)),
        );
    }
    return $variations;
}