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( array $slugs = array(), string $post_type = '', bool $fs_only = false )
Gets the templates.
Parameters Parameters
- $slugs
-
(array) (Optional) An array of slugs to retrieve templates for.
Default value: array()
- $post_type
-
(string) (Optional) Post Type.
Default value: ''
- $fs_only
-
(bool) (Optional) Retrieve templates from the filesystem ony.
Default value: false
Return Return
(WP_Block_Template[]) Templates.
Source Source
File: includes/class-llms-block-templates.php
private function block_templates( $slugs = array(), $post_type = '', $fs_only = false ) { // Get paths where to look for block templates. $block_templates_paths = $this->block_templates_paths(); // Get all the slugs. $template_slugs = array_map( array( $this, 'generate_template_slug_from_path' ), $block_templates_paths ); // If specific slugs are required, filter them only. $template_slugs = empty( array_filter( $slugs ) ) ? $template_slugs : array_intersect( $slugs, $template_slugs ); if ( empty( $template_slugs ) ) { return array(); } $templates = $fs_only ? $this->block_templates_from_fs( $block_templates_paths, $template_slugs ) : array_merge( $this->block_templates_from_db( $template_slugs ), $this->block_templates_from_fs( $block_templates_paths, $template_slugs ) ); // DB wins over fs, exclude not allowed post types. $templates = array_values( array_filter( $templates, function( $template, $key ) use ( $templates, $post_type ) { return ( ! ( $post_type && isset( $template->post_types ) && ! in_array( $post_type, $template->post_types, true ) ) ) && array_search( $template->slug, array_unique( wp_list_pluck( $templates, 'slug' ) ), true ) === $key; }, ARRAY_FILTER_USE_BOTH ) ); return $templates; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
5.9.0 | Filter template slugs array before checking if it's empty. |
5.8.0 | Introduced. |