LLMS_Block_Templates::get_single_block_template( WP_Block_Template $template, string $id, array $template_type )
Runs on the get_block_template hook.
Description Description
If a template is already found and passed to this function, then return it and don’t run. If a template is not passed, try to look for one that matches the ID in the database, if that’s not found defer to Blocks templates files. Priority goes: DB-Theme, DB-Blocks, Filesystem-Theme, Filesystem-Blocks.
Parameters Parameters
- $template
-
(WP_Block_Template) (Required) The found block template.
- $id
-
(string) (Required) Template unique identifier (example: theme_slug//template_slug).
- $template_type
-
(array) (Required) wp_template or wp_template_part.
Return Return
(mixed|null)
Source Source
File: includes/class-llms-block-templates.php
public function get_single_block_template( $template, $id, $template_type ) { // The template was already found before the filter runs, or the requested template is not a 'wp_template' type, just return it immediately. if ( null !== $template || 'wp_template' !== $template_type ) { return $template; } $template_name_parts = explode( '//', $id ); if ( count( $template_name_parts ) < 2 ) { return $template; } list( , $slug ) = $template_name_parts; // Get available llms templates from the filesystem. $available_templates = $this->block_templates( array( $slug ), '', true ); // If this blocks template doesn't exist then we should just skip the function and let Gutenberg handle it. if ( ! in_array( $slug, wp_list_pluck( $available_templates, 'slug' ), true ) ) { return $template; } $template = ( is_array( $available_templates ) && count( $available_templates ) > 0 ) ? $available_templates[0] : $template; return $template; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
5.8.0 | Introduced. |