pre_get_block_templates хук-фильтрWP 5.9.0

Filters the block templates array before the query takes place.

Return a non-null value to bypass the WordPress queries.

Использование

add_filter( 'pre_get_block_templates', 'wp_kama_pre_get_block_templates_filter', 10, 3 );

/**
 * Function for `pre_get_block_templates` filter-hook.
 * 
 * @param WP_Block_Template[]|null $block_templates Return an array of block templates to short-circuit the default query, or null to allow WP to run it's normal queries.
 * @param array                    $query           Optional. Arguments to retrieve templates.
 * @param string                   $template_type   wp_template or wp_template_part.
 *
 * @return WP_Block_Template[]|null
 */
function wp_kama_pre_get_block_templates_filter( $block_templates, $query, $template_type ){

	// filter...
	return $block_templates;
}
$block_templates(WP_Block_Template[]|null)
Return an array of block templates to short-circuit the default query, or null to allow WP to run it's normal queries.
$query(массив)

Optional. Arguments to retrieve templates.

  • slug__in(массив)
    List of slugs to include.

  • wp_id(int)
    Post ID of customized template.

  • post_type(строка)
    Post type to get the templates for.
$template_type(строка)
wp_template or wp_template_part.

Список изменений

С версии 5.9.0 Введена.

Где вызывается хук

get_block_templates()
pre_get_block_templates
wp-includes/block-template-utils.php 634
$templates = apply_filters( 'pre_get_block_templates', null, $query, $template_type );

Где используется хук в WordPress

Использование не найдено.