LLMS_Template_Loader::block_template_loader( WP_Block_Template[] $result, array $query, array $template_type )

Filter blocks templates.


Parameters Parameters

$result

(WP_Block_Template[]) (Required) Array of found block templates.

$query

(array) (Optional) Arguments to retrieve templates.

  • 'slug__in'
    (array) List of slugs to include.
  • 'wp_id'
    (int) Post ID of customized template.

$template_type

(array) (Optional) wp_template or wp_template_part.


Top ↑

Return Return

(array) Templates.


Top ↑

Source Source

File: includes/class.llms.template.loader.php

	 * @return array Templates.
	 */
	public function block_template_loader( $result, $query, $template_type ) {

		// Bail if it's not a block theme, or is being retrieved a non wp_template file.
		if ( ! llms_is_block_theme() || 'wp_template' !== $template_type ) {
			return $result;
		}

		$template_name = $this->get_maybe_forced_template();

		/**
		 * Since LifterLMS 6.0.0 certificates have their own PHP template that do no depend on the theme.
		 * This means that we can use the PHP template loaded in the method `LLMS_Template_Loader::template_loader()` below.
		 */
		$template_name = is_singular( array( 'llms_certificate', 'llms_my_certificate' ) ) ? '' : $template_name;

		/**
		 * Filters the block template to be loded forced.
		 *
		 * @since 5.8.0
		 *
		 * @param string $template_slug The template slug to be force loaded.
		 * @param string $template      The name of template to be force loaded.
		 */
		$template_slug = apply_filters( 'llms_forced_block_template_slug', $template_name ? LLMS_Block_Templates::LLMS_BLOCK_TEMPLATES_PREFIX . $template_name : '', $template_name );

		if ( empty( $template_slug ) ) {
			return $result;
		}

		// Prevent template_loader to load a php template.
		add_filter( 'llms_force_php_template_loading', '__return_false' );

		return llms()->block_templates()->add_llms_block_templates(
			array(),
			array( 'slug__in' => array( $template_slug ) )
		);


Top ↑

Changelog Changelog

Changelog
Version Description
6.0.0 Remove LifterLMS 6.0 version check about the certificate template. Use llms_is_block_theme() in favor of wp_is_block_theme().
5.8.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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