[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ -> block-template-utils.php (summary)

Utilities used to fetch and create templates and template parts.

File Size: 1567 lines (55 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 27 functions

  get_block_theme_folders()
  get_allowed_block_template_part_areas()
  get_default_block_template_types()
  _filter_block_template_part_area()
  _get_block_templates_paths()
  _get_block_template_file()
  _get_block_templates_files()
  _add_block_template_info()
  _add_block_template_part_area_info()
  _flatten_blocks()
  _inject_theme_attribute_in_template_part_block()
  _remove_theme_attribute_from_template_part_block()
  _build_block_template_result_from_file()
  _wp_build_title_and_description_for_single_post_type_block_template()
  _wp_build_title_and_description_for_taxonomy_block_template()
  _build_block_template_object_from_post_object()
  _build_block_template_result_from_post()
  get_block_templates()
  get_block_template()
  get_block_file_template()
  block_template_part()
  block_header_area()
  block_footer_area()
  wp_is_theme_directory_ignored()
  wp_generate_block_templates_export_file()
  get_template_hierarchy()
  inject_ignored_hooked_blocks_metadata_attributes()

Functions
Functions that are not part of a class:

get_block_theme_folders( $theme_stylesheet = null )   X-Ref
For backward compatibility reasons,
block themes might be using block-templates or block-template-parts,
this function ensures we fallback to these folders properly.

param: string $theme_stylesheet The stylesheet. Default is to leverage the main theme root.
return: string[] {

get_allowed_block_template_part_areas()   X-Ref
Returns a filtered list of allowed area values for template parts.

return: array[] The supported template part area values.

get_default_block_template_types()   X-Ref
Returns a filtered list of default template types, containing their
localized titles and descriptions.

return: array[] The default template types.

_filter_block_template_part_area( $type )   X-Ref
Checks whether the input 'area' is a supported value.
Returns the input if supported, otherwise returns the 'uncategorized' value.

param: string $type Template part area name.
return: string Input if supported, else the uncategorized value.

_get_block_templates_paths( $base_directory )   X-Ref
No description

_get_block_template_file( $template_type, $slug )   X-Ref
Retrieves the template file from the theme for a given slug.

param: string $template_type Template type. Either 'wp_template' or 'wp_template_part'.
param: string $slug          Template slug.
return: array|null {

_get_block_templates_files( $template_type, $query = array()   X-Ref
Retrieves the template files from the theme.

param: string $template_type Template type. Either 'wp_template' or 'wp_template_part'.
param: array  $query {
return: array Template

_add_block_template_info( $template_item )   X-Ref
Attempts to add custom template information to the template item.

param: array $template_item Template to add information to (requires 'slug' field).
return: array Template item.

_add_block_template_part_area_info( $template_info )   X-Ref
Attempts to add the template part's area information to the input template.

param: array $template_info Template to add information to (requires 'type' and 'slug' fields).
return: array Template info.

_flatten_blocks( &$blocks )   X-Ref
Returns an array containing the references of
the passed blocks and their inner blocks.

param: array $blocks array of blocks.
return: array block references to the passed blocks and their inner blocks.

_inject_theme_attribute_in_template_part_block( &$block )   X-Ref
Injects the active theme's stylesheet as a `theme` attribute
into a given template part block.

param: array $block a parsed block.

_remove_theme_attribute_from_template_part_block( &$block )   X-Ref
Removes the `theme` attribute from a given template part block.

param: array $block a parsed block.

_build_block_template_result_from_file( $template_file, $template_type )   X-Ref
Builds a unified template object based on a theme file.

param: array  $template_file Theme file.
param: string $template_type Template type. Either 'wp_template' or 'wp_template_part'.
return: WP_Block_Template Template.

_wp_build_title_and_description_for_single_post_type_block_template( $post_type, $slug, WP_Block_Template $template )   X-Ref
Builds the title and description of a post-specific template based on the underlying referenced post.

Mutates the underlying template object.

param: string            $post_type Post type, e.g. page, post, product.
param: string            $slug      Slug of the post, e.g. a-story-about-shoes.
param: WP_Block_Template $template  Template to mutate adding the description and title computed.
return: bool Returns true if the referenced post was found and false otherwise.

_wp_build_title_and_description_for_taxonomy_block_template( $taxonomy, $slug, WP_Block_Template $template )   X-Ref
Builds the title and description of a taxonomy-specific template based on the underlying entity referenced.

Mutates the underlying template object.

param: string            $taxonomy Identifier of the taxonomy, e.g. category.
param: string            $slug     Slug of the term, e.g. shoes.
param: WP_Block_Template $template Template to mutate adding the description and title computed.
return: bool True if the term referenced was found and false otherwise.

_build_block_template_object_from_post_object( $post, $terms = array()   X-Ref
Builds a block template object from a post object.

This is a helper function that creates a block template object from a given post object.
It is self-sufficient in that it only uses information passed as arguments; it does not
query the database for additional information.

param: WP_Post $post  Template post.
param: array   $terms Additional terms to inform the template object.
param: array   $meta  Additional meta fields to inform the template object.
return: WP_Block_Template|WP_Error Template or error object.

_build_block_template_result_from_post( $post )   X-Ref
Builds a unified template object based a post Object.

param: WP_Post $post Template post.
return: WP_Block_Template|WP_Error Template or error object.

get_block_templates( $query = array()   X-Ref
Retrieves a list of unified template objects based on a query.

param: array  $query {
param: string $template_type Template type. Either 'wp_template' or 'wp_template_part'.
return: WP_Block_Template[] Array of block templates.

get_block_template( $id, $template_type = 'wp_template' )   X-Ref
Retrieves a single unified template object using its id.

param: string $id            Template unique identifier (example: 'theme_slug//template_slug').
param: string $template_type Optional. Template type. Either 'wp_template' or 'wp_template_part'.
return: WP_Block_Template|null Template.

get_block_file_template( $id, $template_type = 'wp_template' )   X-Ref
Retrieves a unified template object based on a theme file.

This is a fallback of get_block_template(), used when no templates are found in the database.

param: string $id            Template unique identifier (example: 'theme_slug//template_slug').
param: string $template_type Optional. Template type. Either 'wp_template' or 'wp_template_part'.
return: WP_Block_Template|null The found block template, or null if there isn't one.

block_template_part( $part )   X-Ref
Prints a block template part.

param: string $part The block template part to print. Either 'header' or 'footer'.

block_header_area()   X-Ref
Prints the header block template part.


block_footer_area()   X-Ref
Prints the footer block template part.


wp_is_theme_directory_ignored( $path )   X-Ref
Determines whether a theme directory should be ignored during export.

param: string $path The path of the file in the theme.
return: bool Whether this file is in an ignored directory.

wp_generate_block_templates_export_file()   X-Ref
Creates an export of the current templates and
template parts from the site editor at the
specified path in a ZIP file.

return: WP_Error|string Path of the ZIP file or error on failure.

get_template_hierarchy( $slug, $is_custom = false, $template_prefix = '' )   X-Ref
Gets the template hierarchy for the given template slug to be created.

Note: Always add `index` as the last fallback template.

param: string $slug            The template slug to be created.
param: bool   $is_custom       Optional. Indicates if a template is custom or
param: string $template_prefix Optional. The template prefix for the created template.
return: string[] The template hierarchy.

inject_ignored_hooked_blocks_metadata_attributes( $changes, $deprecated = null )   X-Ref
Inject ignoredHookedBlocks metadata attributes into a template or template part.

Given an object that represents a `wp_template` or `wp_template_part` post object
prepared for inserting or updating the database, locate all blocks that have
hooked blocks, and inject a `metadata.ignoredHookedBlocks` attribute into the anchor
blocks to reflect the latter.

param: stdClass        $changes    An object representing a template or template part
param: WP_REST_Request $deprecated Deprecated. Not used.
return: stdClass|WP_Error The updated object representing a template or template part.



Generated : Fri Apr 19 08:20:01 2024 Cross-referenced by PHPXref