Automattic\WooCommerce\Blocks
BlockTemplatesController::get_block_templates_from_db()
Gets the templates saved in the database.
Метод класса: BlockTemplatesController{}
Хуков нет.
Возвращает
int[]|\WP_Post[]
. An array of found templates.
Использование
$BlockTemplatesController = new BlockTemplatesController(); $BlockTemplatesController->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'
Код BlockTemplatesController::get_block_templates_from_db() BlockTemplatesController::get block templates from db WC 7.3.0
public 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( BlockTemplateUtils::DEPRECATED_PLUGIN_SLUG, BlockTemplateUtils::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 BlockTemplateUtils::build_template_result_from_post( $saved_woo_template ); }, $saved_woo_templates ); }