Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

LLMS_Block_Templates::block_templates_from_db( array $slugs = array() )

Gets the templates saved in the database.


Parameters Parameters

$slugs

(array) (Optional) An array of slugs to retrieve templates for.

Default value: array()


Top ↑

Return Return

(int[]|WP_Post[]) An array of found templates.


Top ↑

Source Source

File: includes/class-llms-block-templates.php

	private function block_templates_from_db( $slugs = array() ) {

		$query_args = array(
			'post_status'    => array( 'auto-draft', 'draft', 'publish' ),
			'post_type'      => 'wp_template',
			'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_merge(
						array( get_stylesheet(), get_template() ),
						array_column( $this->block_templates_config, 'namespace' )
					),
				),
			),
		);

		if ( is_array( $slugs ) && count( $slugs ) > 0 ) {
			$query_args['post_name__in'] = $slugs;
		}

		/**
		 * Filters the query arguments to retrieve the templates saved in the db.
		 *
		 * @since 5.8.0
		 *
		 * @param array $query_args WQ_Query argiments to retrieve the templates saved in the db.
		 */
		$query_args = apply_filters( 'llms_block_templates_from_db_query_args', $query_args );

		$templates = ( new WP_Query( $query_args ) )->posts;

		return array_map(
			function( $template ) {
				return $this->build_template_result_from_post( $template );
			},
			$templates
		);

	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.8.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.