Automattic\WooCommerce\Blocks\Utils
BlockTemplateUtils::get_block_templates_from_db
Gets the templates saved in the database.
Метод класса: BlockTemplateUtils{}
Хуков нет.
Возвращает
\WP_Block_Template[]. An array of found templates.
Использование
$result = BlockTemplateUtils::get_block_templates_from_db( $slugs, $template_type );
- $slugs(массив)
- An array of slugs to retrieve templates for.
По умолчанию: array() - $template_type(строка)
- wp_template or wp_template_part.
По умолчанию: 'wp_template'
Код BlockTemplateUtils::get_block_templates_from_db() BlockTemplateUtils::get block templates from db WC 10.3.6
public static function get_block_templates_from_db( $slugs = array(), $template_type = 'wp_template' ) {
$check_query_args = array(
'post_type' => $template_type,
'posts_per_page' => -1,
'no_found_rows' => true,
'tax_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
array(
'taxonomy' => 'wp_theme',
'field' => 'name',
'terms' => array( self::DEPRECATED_PLUGIN_SLUG, self::PLUGIN_SLUG, get_stylesheet() ),
),
),
);
if ( is_array( $slugs ) && count( $slugs ) > 0 ) {
$check_query_args['post_name__in'] = $slugs;
}
$check_query = new \WP_Query( $check_query_args );
$saved_woo_templates = $check_query->posts;
return array_map(
function ( $saved_woo_template ) {
return self::build_template_result_from_post( $saved_woo_template );
},
$saved_woo_templates
);
}