rebase on oct-10-2023
This commit is contained in:
@@ -59,13 +59,13 @@ function get_block_theme_folders( $theme_stylesheet = null ) {
|
||||
*
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @return array The supported template part area values.
|
||||
* @return array[] The supported template part area values.
|
||||
*/
|
||||
function get_allowed_block_template_part_areas() {
|
||||
$default_area_definitions = array(
|
||||
array(
|
||||
'area' => WP_TEMPLATE_PART_AREA_UNCATEGORIZED,
|
||||
'label' => __( 'General' ),
|
||||
'label' => _x( 'General', 'template part area' ),
|
||||
'description' => __(
|
||||
'General templates often perform a specific role like displaying post content, and are not tied to any particular area.'
|
||||
),
|
||||
@@ -74,7 +74,7 @@ function get_allowed_block_template_part_areas() {
|
||||
),
|
||||
array(
|
||||
'area' => WP_TEMPLATE_PART_AREA_HEADER,
|
||||
'label' => __( 'Header' ),
|
||||
'label' => _x( 'Header', 'template part area' ),
|
||||
'description' => __(
|
||||
'The Header template defines a page area that typically contains a title, logo, and main navigation.'
|
||||
),
|
||||
@@ -83,7 +83,7 @@ function get_allowed_block_template_part_areas() {
|
||||
),
|
||||
array(
|
||||
'area' => WP_TEMPLATE_PART_AREA_FOOTER,
|
||||
'label' => __( 'Footer' ),
|
||||
'label' => _x( 'Footer', 'template part area' ),
|
||||
'description' => __(
|
||||
'The Footer template defines a page area that typically contains site credits, social links, or any other combination of blocks.'
|
||||
),
|
||||
@@ -97,7 +97,7 @@ function get_allowed_block_template_part_areas() {
|
||||
*
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $default_area_definitions An array of supported area objects.
|
||||
* @param array[] $default_area_definitions An array of supported area objects.
|
||||
*/
|
||||
return apply_filters( 'default_wp_template_part_areas', $default_area_definitions );
|
||||
}
|
||||
@@ -109,7 +109,7 @@ function get_allowed_block_template_part_areas() {
|
||||
*
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @return array The default template types.
|
||||
* @return array[] The default template types.
|
||||
*/
|
||||
function get_default_block_template_types() {
|
||||
$default_template_types = array(
|
||||
@@ -118,55 +118,55 @@ function get_default_block_template_types() {
|
||||
'description' => __( 'Used as a fallback template for all pages when a more specific template is not defined.' ),
|
||||
),
|
||||
'home' => array(
|
||||
'title' => _x( 'Home', 'Template name' ),
|
||||
'description' => __( 'Displays the latest posts as either the site homepage or a custom page defined under reading settings. If it exists, the Front Page template overrides this template when posts are shown on the front page.' ),
|
||||
'title' => _x( 'Blog Home', 'Template name' ),
|
||||
'description' => __( 'Displays the latest posts as either the site homepage or as the "Posts page" as defined under reading settings. If it exists, the Front Page template overrides this template when posts are shown on the homepage.' ),
|
||||
),
|
||||
'front-page' => array(
|
||||
'title' => _x( 'Front Page', 'Template name' ),
|
||||
'description' => __( 'Displays your site\'s front page, whether it is set to display latest posts or a static page. The Front Page template takes precedence over all templates.' ),
|
||||
'description' => __( 'Displays your site\'s homepage, whether it is set to display latest posts or a static page. The Front Page template takes precedence over all templates.' ),
|
||||
),
|
||||
'singular' => array(
|
||||
'title' => _x( 'Singular', 'Template name' ),
|
||||
'description' => __( 'Displays any single entry, such as a post or a page. This template will serve as a fallback when a more specific template (e.g., Single Post, Page, or Attachment) cannot be found.' ),
|
||||
'title' => _x( 'Single Entries', 'Template name' ),
|
||||
'description' => __( 'Displays any single entry, such as a post or a page. This template will serve as a fallback when a more specific template (e.g. Single Post, Page, or Attachment) cannot be found.' ),
|
||||
),
|
||||
'single' => array(
|
||||
'title' => _x( 'Single', 'Template name' ),
|
||||
'title' => _x( 'Single Posts', 'Template name' ),
|
||||
'description' => __( 'Displays single posts on your website unless a custom template has been applied to that post or a dedicated template exists.' ),
|
||||
),
|
||||
'page' => array(
|
||||
'title' => _x( 'Page', 'Template name' ),
|
||||
'title' => _x( 'Pages', 'Template name' ),
|
||||
'description' => __( 'Display all static pages unless a custom template has been applied or a dedicated template exists.' ),
|
||||
),
|
||||
'archive' => array(
|
||||
'title' => _x( 'Archive', 'Template name' ),
|
||||
'description' => __( 'Displays any archive, including posts by a single author, category, tag, taxonomy, custom post type, and date. This template will serve as a fallback when more specific templates (e.g., Category or Tag) cannot be found.' ),
|
||||
'title' => _x( 'All Archives', 'Template name' ),
|
||||
'description' => __( 'Displays any archive, including posts by a single author, category, tag, taxonomy, custom post type, and date. This template will serve as a fallback when more specific templates (e.g. Category or Tag) cannot be found.' ),
|
||||
),
|
||||
'author' => array(
|
||||
'title' => _x( 'Author', 'Template name' ),
|
||||
'description' => __( 'Displays a single author\'s post archive. This template will serve as a fallback when a more specific template (e.g., Author: Admin) cannot be found.' ),
|
||||
'title' => _x( 'Author Archives', 'Template name' ),
|
||||
'description' => __( 'Displays a single author\'s post archive. This template will serve as a fallback when a more specific template (e.g. Author: Admin) cannot be found.' ),
|
||||
),
|
||||
'category' => array(
|
||||
'title' => _x( 'Category', 'Template name' ),
|
||||
'description' => __( 'Displays a post category archive. This template will serve as a fallback when a more specific template (e.g., Category: Recipes) cannot be found.' ),
|
||||
'title' => _x( 'Category Archives', 'Template name' ),
|
||||
'description' => __( 'Displays a post category archive. This template will serve as a fallback when a more specific template (e.g. Category: Recipes) cannot be found.' ),
|
||||
),
|
||||
'taxonomy' => array(
|
||||
'title' => _x( 'Taxonomy', 'Template name' ),
|
||||
'description' => __( 'Displays a custom taxonomy archive. Like categories and tags, taxonomies have terms which you use to classify things. For example: a taxonomy named "Art" can have multiple terms, such as "Modern" and "18th Century." This template will serve as a fallback when a more specific template (e.g, Taxonomy: Art) cannot be found.' ),
|
||||
'description' => __( 'Displays a custom taxonomy archive. Like categories and tags, taxonomies have terms which you use to classify things. For example: a taxonomy named "Art" can have multiple terms, such as "Modern" and "18th Century." This template will serve as a fallback when a more specific template (e.g. Taxonomy: Art) cannot be found.' ),
|
||||
),
|
||||
'date' => array(
|
||||
'title' => _x( 'Date', 'Template name' ),
|
||||
'title' => _x( 'Date Archives', 'Template name' ),
|
||||
'description' => __( 'Displays a post archive when a specific date is visited (e.g., example.com/2023/).' ),
|
||||
),
|
||||
'tag' => array(
|
||||
'title' => _x( 'Tag', 'Template name' ),
|
||||
'description' => __( 'Displays a post tag archive. This template will serve as a fallback when a more specific template (e.g., Tag: Pizza) cannot be found.' ),
|
||||
'title' => _x( 'Tag Archives', 'Template name' ),
|
||||
'description' => __( 'Displays a post tag archive. This template will serve as a fallback when a more specific template (e.g. Tag: Pizza) cannot be found.' ),
|
||||
),
|
||||
'attachment' => array(
|
||||
'title' => __( 'Media' ),
|
||||
'title' => __( 'Attachment Pages' ),
|
||||
'description' => __( 'Displays when a visitor views the dedicated page that exists for any media attachment.' ),
|
||||
),
|
||||
'search' => array(
|
||||
'title' => _x( 'Search', 'Template name' ),
|
||||
'title' => _x( 'Search Results', 'Template name' ),
|
||||
'description' => __( 'Displays when a visitor performs a search on your website.' ),
|
||||
),
|
||||
'privacy-policy' => array(
|
||||
@@ -174,7 +174,7 @@ function get_default_block_template_types() {
|
||||
'description' => __( 'Displays your site\'s Privacy Policy page.' ),
|
||||
),
|
||||
'404' => array(
|
||||
'title' => _x( '404', 'Template name' ),
|
||||
'title' => _x( 'Page: 404', 'Template name' ),
|
||||
'description' => __( 'Displays when a visitor views a non-existent page, such as a dead link or a mistyped URL.' ),
|
||||
),
|
||||
);
|
||||
@@ -184,7 +184,7 @@ function get_default_block_template_types() {
|
||||
*
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $default_template_types An array of template types, formatted as [ slug => [ title, description ] ].
|
||||
* @param array[] $default_template_types An array of template types, formatted as [ slug => [ title, description ] ].
|
||||
*/
|
||||
return apply_filters( 'default_template_types', $default_template_types );
|
||||
}
|
||||
@@ -227,7 +227,7 @@ function _filter_block_template_part_area( $type ) {
|
||||
* @access private
|
||||
*
|
||||
* @param string $base_directory The theme's file path.
|
||||
* @return array A list of paths to all template part files.
|
||||
* @return string[] A list of paths to all template part files.
|
||||
*/
|
||||
function _get_block_templates_paths( $base_directory ) {
|
||||
$path_list = array();
|
||||
@@ -249,7 +249,18 @@ function _get_block_templates_paths( $base_directory ) {
|
||||
*
|
||||
* @param string $template_type 'wp_template' or 'wp_template_part'.
|
||||
* @param string $slug Template slug.
|
||||
* @return array|null Template.
|
||||
* @return array|null {
|
||||
* Array with template metadata if $template_type is one of 'wp_template' or 'wp_template_part'.
|
||||
* null otherwise.
|
||||
*
|
||||
* @type string $slug Template slug.
|
||||
* @type string $path Template file path.
|
||||
* @type string $theme Theme slug.
|
||||
* @type string $type Template type.
|
||||
* @type string $area Template area. Only for 'wp_template_part'.
|
||||
* @type string $title Optional. Template title.
|
||||
* @type string[] $postTypes Optional. List of post types that the template supports. Only for 'wp_template'.
|
||||
* }
|
||||
*/
|
||||
function _get_block_template_file( $template_type, $slug ) {
|
||||
if ( 'wp_template' !== $template_type && 'wp_template_part' !== $template_type ) {
|
||||
@@ -290,20 +301,41 @@ function _get_block_template_file( $template_type, $slug ) {
|
||||
* Retrieves the template files from the theme.
|
||||
*
|
||||
* @since 5.9.0
|
||||
* @since 6.3.0 Added the `$query` parameter.
|
||||
* @access private
|
||||
*
|
||||
* @param string $template_type 'wp_template' or 'wp_template_part'.
|
||||
* @return array Template.
|
||||
* @param array $query {
|
||||
* Arguments to retrieve templates. Optional, empty by default.
|
||||
*
|
||||
* @type array $slug__in List of slugs to include.
|
||||
* @type array $slug__not_in List of slugs to skip.
|
||||
* @type string $area A 'wp_template_part_area' taxonomy value to filter by (for 'wp_template_part' template type only).
|
||||
* @type string $post_type Post type to get the templates for.
|
||||
* }
|
||||
*
|
||||
* @return array Template
|
||||
*/
|
||||
function _get_block_templates_files( $template_type ) {
|
||||
function _get_block_templates_files( $template_type, $query = array() ) {
|
||||
if ( 'wp_template' !== $template_type && 'wp_template_part' !== $template_type ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$themes = array(
|
||||
get_stylesheet() => get_stylesheet_directory(),
|
||||
get_template() => get_template_directory(),
|
||||
// Prepare metadata from $query.
|
||||
$slugs_to_include = isset( $query['slug__in'] ) ? $query['slug__in'] : array();
|
||||
$slugs_to_skip = isset( $query['slug__not_in'] ) ? $query['slug__not_in'] : array();
|
||||
$area = isset( $query['area'] ) ? $query['area'] : null;
|
||||
$post_type = isset( $query['post_type'] ) ? $query['post_type'] : '';
|
||||
|
||||
$stylesheet = get_stylesheet();
|
||||
$template = get_template();
|
||||
$themes = array(
|
||||
$stylesheet => get_stylesheet_directory(),
|
||||
);
|
||||
// Add the parent theme if it's not the same as the current theme.
|
||||
if ( $stylesheet !== $template ) {
|
||||
$themes[ $template ] = get_template_directory();
|
||||
}
|
||||
$template_files = array();
|
||||
foreach ( $themes as $theme_slug => $theme_dir ) {
|
||||
$template_base_paths = get_block_theme_folders( $theme_slug );
|
||||
@@ -317,6 +349,25 @@ function _get_block_templates_files( $template_type ) {
|
||||
// Subtract ending '.html'.
|
||||
-5
|
||||
);
|
||||
|
||||
// Skip this item if its slug doesn't match any of the slugs to include.
|
||||
if ( ! empty( $slugs_to_include ) && ! in_array( $template_slug, $slugs_to_include, true ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip this item if its slug matches any of the slugs to skip.
|
||||
if ( ! empty( $slugs_to_skip ) && in_array( $template_slug, $slugs_to_skip, true ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* The child theme items (stylesheet) are processed before the parent theme's (template).
|
||||
* If a child theme defines a template, prevent the parent template from being added to the list as well.
|
||||
*/
|
||||
if ( isset( $template_files[ $template_slug ] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$new_template_item = array(
|
||||
'slug' => $template_slug,
|
||||
'path' => $template_file,
|
||||
@@ -325,16 +376,25 @@ function _get_block_templates_files( $template_type ) {
|
||||
);
|
||||
|
||||
if ( 'wp_template_part' === $template_type ) {
|
||||
$template_files[] = _add_block_template_part_area_info( $new_template_item );
|
||||
$candidate = _add_block_template_part_area_info( $new_template_item );
|
||||
if ( ! isset( $area ) || ( isset( $area ) && $area === $candidate['area'] ) ) {
|
||||
$template_files[ $template_slug ] = $candidate;
|
||||
}
|
||||
}
|
||||
|
||||
if ( 'wp_template' === $template_type ) {
|
||||
$template_files[] = _add_block_template_info( $new_template_item );
|
||||
$candidate = _add_block_template_info( $new_template_item );
|
||||
if (
|
||||
! $post_type ||
|
||||
( $post_type && isset( $candidate['postTypes'] ) && in_array( $post_type, $candidate['postTypes'], true ) )
|
||||
) {
|
||||
$template_files[ $template_slug ] = $candidate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $template_files;
|
||||
return array_values( $template_files );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -490,6 +550,7 @@ function _remove_theme_attribute_in_block_template_content( $template_content )
|
||||
* Builds a unified template object based on a theme file.
|
||||
*
|
||||
* @since 5.9.0
|
||||
* @since 6.3.0 Added `modified` property to template objects.
|
||||
* @access private
|
||||
*
|
||||
* @param array $template_file Theme file.
|
||||
@@ -512,6 +573,7 @@ function _build_block_template_result_from_file( $template_file, $template_type
|
||||
$template->status = 'publish';
|
||||
$template->has_theme_file = true;
|
||||
$template->is_custom = true;
|
||||
$template->modified = null;
|
||||
|
||||
if ( 'wp_template' === $template_type && isset( $default_template_types[ $template_file['slug'] ] ) ) {
|
||||
$template->description = $default_template_types[ $template_file['slug'] ]['description'];
|
||||
@@ -691,10 +753,11 @@ function _wp_build_title_and_description_for_taxonomy_block_template( $taxonomy,
|
||||
* Builds a unified template object based a post Object.
|
||||
*
|
||||
* @since 5.9.0
|
||||
* @since 6.3.0 Added `modified` property to template objects.
|
||||
* @access private
|
||||
*
|
||||
* @param WP_Post $post Template post.
|
||||
* @return WP_Block_Template|WP_Error Template.
|
||||
* @return WP_Block_Template|WP_Error Template or error object.
|
||||
*/
|
||||
function _build_block_template_result_from_post( $post ) {
|
||||
$default_template_types = get_default_block_template_types();
|
||||
@@ -730,6 +793,7 @@ function _build_block_template_result_from_post( $post ) {
|
||||
$template->has_theme_file = $has_theme_file;
|
||||
$template->is_custom = empty( $is_wp_suggestion );
|
||||
$template->author = $post->post_author;
|
||||
$template->modified = $post->post_modified;
|
||||
|
||||
if ( 'wp_template' === $post->post_type && $has_theme_file && isset( $template_file['postTypes'] ) ) {
|
||||
$template->post_types = $template_file['postTypes'];
|
||||
@@ -865,13 +929,13 @@ function _build_block_template_result_from_post( $post ) {
|
||||
* @param array $query {
|
||||
* Optional. Arguments to retrieve templates.
|
||||
*
|
||||
* @type array $slug__in List of slugs to include.
|
||||
* @type int $wp_id Post ID of customized template.
|
||||
* @type string $area A 'wp_template_part_area' taxonomy value to filter by (for wp_template_part template type only).
|
||||
* @type string $post_type Post type to get the templates for.
|
||||
* @type string[] $slug__in List of slugs to include.
|
||||
* @type int $wp_id Post ID of customized template.
|
||||
* @type string $area A 'wp_template_part_area' taxonomy value to filter by (for 'wp_template_part' template type only).
|
||||
* @type string $post_type Post type to get the templates for.
|
||||
* }
|
||||
* @param string $template_type 'wp_template' or 'wp_template_part'.
|
||||
* @return array Templates.
|
||||
* @return WP_Block_Template[] Array of block templates.
|
||||
*/
|
||||
function get_block_templates( $query = array(), $template_type = 'wp_template' ) {
|
||||
/**
|
||||
@@ -882,15 +946,16 @@ function get_block_templates( $query = array(), $template_type = 'wp_template' )
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param WP_Block_Template[]|null $block_templates Return an array of block templates to short-circuit the default query,
|
||||
* or null to allow WP to run it's normal queries.
|
||||
* or null to allow WP to run its normal queries.
|
||||
* @param array $query {
|
||||
* Optional. Arguments to retrieve templates.
|
||||
* Arguments to retrieve templates. All arguments are optional.
|
||||
*
|
||||
* @type array $slug__in List of slugs to include.
|
||||
* @type int $wp_id Post ID of customized template.
|
||||
* @type string $post_type Post type to get the templates for.
|
||||
* @type string[] $slug__in List of slugs to include.
|
||||
* @type int $wp_id Post ID of customized template.
|
||||
* @type string $area A 'wp_template_part_area' taxonomy value to filter by (for 'wp_template_part' template type only).
|
||||
* @type string $post_type Post type to get the templates for.
|
||||
* }
|
||||
* @param string $template_type wp_template or wp_template_part.
|
||||
* @param string $template_type 'wp_template' or 'wp_template_part'.
|
||||
*/
|
||||
$templates = apply_filters( 'pre_get_block_templates', null, $query, $template_type );
|
||||
if ( ! is_null( $templates ) ) {
|
||||
@@ -899,11 +964,12 @@ function get_block_templates( $query = array(), $template_type = 'wp_template' )
|
||||
|
||||
$post_type = isset( $query['post_type'] ) ? $query['post_type'] : '';
|
||||
$wp_query_args = array(
|
||||
'post_status' => array( 'auto-draft', 'draft', 'publish' ),
|
||||
'post_type' => $template_type,
|
||||
'posts_per_page' => -1,
|
||||
'no_found_rows' => true,
|
||||
'tax_query' => array(
|
||||
'post_status' => array( 'auto-draft', 'draft', 'publish' ),
|
||||
'post_type' => $template_type,
|
||||
'posts_per_page' => -1,
|
||||
'no_found_rows' => true,
|
||||
'lazy_load_term_meta' => false,
|
||||
'tax_query' => array(
|
||||
array(
|
||||
'taxonomy' => 'wp_theme',
|
||||
'field' => 'name',
|
||||
@@ -921,8 +987,9 @@ function get_block_templates( $query = array(), $template_type = 'wp_template' )
|
||||
$wp_query_args['tax_query']['relation'] = 'AND';
|
||||
}
|
||||
|
||||
if ( isset( $query['slug__in'] ) ) {
|
||||
$wp_query_args['post_name__in'] = $query['slug__in'];
|
||||
if ( ! empty( $query['slug__in'] ) ) {
|
||||
$wp_query_args['post_name__in'] = $query['slug__in'];
|
||||
$wp_query_args['posts_per_page'] = count( array_unique( $query['slug__in'] ) );
|
||||
}
|
||||
|
||||
// This is only needed for the regular templates/template parts post type listing and editor.
|
||||
@@ -957,34 +1024,14 @@ function get_block_templates( $query = array(), $template_type = 'wp_template' )
|
||||
}
|
||||
|
||||
if ( ! isset( $query['wp_id'] ) ) {
|
||||
$template_files = _get_block_templates_files( $template_type );
|
||||
/*
|
||||
* If the query has found some use templates, those have priority
|
||||
* over the theme-provided ones, so we skip querying and building them.
|
||||
*/
|
||||
$query['slug__not_in'] = wp_list_pluck( $query_result, 'slug' );
|
||||
$template_files = _get_block_templates_files( $template_type, $query );
|
||||
foreach ( $template_files as $template_file ) {
|
||||
$template = _build_block_template_result_from_file( $template_file, $template_type );
|
||||
|
||||
if ( $post_type && ! $template->is_custom ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $post_type &&
|
||||
isset( $template->post_types ) &&
|
||||
! in_array( $post_type, $template->post_types, true )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$is_not_custom = false === array_search(
|
||||
get_stylesheet() . '//' . $template_file['slug'],
|
||||
wp_list_pluck( $query_result, 'id' ),
|
||||
true
|
||||
);
|
||||
$fits_slug_query =
|
||||
! isset( $query['slug__in'] ) || in_array( $template_file['slug'], $query['slug__in'], true );
|
||||
$fits_area_query =
|
||||
! isset( $query['area'] ) || $template_file['area'] === $query['area'];
|
||||
$should_include = $is_not_custom && $fits_slug_query && $fits_area_query;
|
||||
if ( $should_include ) {
|
||||
$query_result[] = $template;
|
||||
}
|
||||
$query_result[] = _build_block_template_result_from_file( $template_file, $template_type );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -994,13 +1041,15 @@ function get_block_templates( $query = array(), $template_type = 'wp_template' )
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param WP_Block_Template[] $query_result Array of found block templates.
|
||||
* @param array $query {
|
||||
* Optional. Arguments to retrieve templates.
|
||||
* @param array $query {
|
||||
* Arguments to retrieve templates. All arguments are optional.
|
||||
*
|
||||
* @type array $slug__in List of slugs to include.
|
||||
* @type int $wp_id Post ID of customized template.
|
||||
* @type string[] $slug__in List of slugs to include.
|
||||
* @type int $wp_id Post ID of customized template.
|
||||
* @type string $area A 'wp_template_part_area' taxonomy value to filter by (for 'wp_template_part' template type only).
|
||||
* @type string $post_type Post type to get the templates for.
|
||||
* }
|
||||
* @param string $template_type wp_template or wp_template_part.
|
||||
* @param string $template_type wp_template or wp_template_part.
|
||||
*/
|
||||
return apply_filters( 'get_block_templates', $query_result, $query, $template_type );
|
||||
}
|
||||
@@ -1010,9 +1059,9 @@ function get_block_templates( $query = array(), $template_type = 'wp_template' )
|
||||
*
|
||||
* @since 5.8.0
|
||||
*
|
||||
* @param string $id Template unique identifier (example: theme_slug//template_slug).
|
||||
* @param string $template_type Optional. Template type: `'wp_template'` or '`wp_template_part'`.
|
||||
* Default `'wp_template'`.
|
||||
* @param string $id Template unique identifier (example: 'theme_slug//template_slug').
|
||||
* @param string $template_type Optional. Template type: 'wp_template' or 'wp_template_part'.
|
||||
* Default 'wp_template'.
|
||||
* @return WP_Block_Template|null Template.
|
||||
*/
|
||||
function get_block_template( $id, $template_type = 'wp_template' ) {
|
||||
@@ -1025,8 +1074,8 @@ function get_block_template( $id, $template_type = 'wp_template' ) {
|
||||
*
|
||||
* @param WP_Block_Template|null $block_template Return block template object to short-circuit the default query,
|
||||
* or null to allow WP to run its normal queries.
|
||||
* @param string $id Template unique identifier (example: theme_slug//template_slug).
|
||||
* @param string $template_type Template type: `'wp_template'` or '`wp_template_part'`.
|
||||
* @param string $id Template unique identifier (example: 'theme_slug//template_slug').
|
||||
* @param string $template_type Template type: 'wp_template' or 'wp_template_part'.
|
||||
*/
|
||||
$block_template = apply_filters( 'pre_get_block_template', null, $id, $template_type );
|
||||
if ( ! is_null( $block_template ) ) {
|
||||
@@ -1071,8 +1120,8 @@ function get_block_template( $id, $template_type = 'wp_template' ) {
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param WP_Block_Template|null $block_template The found block template, or null if there isn't one.
|
||||
* @param string $id Template unique identifier (example: theme_slug//template_slug).
|
||||
* @param array $template_type Template type: `'wp_template'` or '`wp_template_part'`.
|
||||
* @param string $id Template unique identifier (example: 'theme_slug//template_slug').
|
||||
* @param array $template_type Template type: 'wp_template' or 'wp_template_part'.
|
||||
*/
|
||||
return apply_filters( 'get_block_template', $block_template, $id, $template_type );
|
||||
}
|
||||
@@ -1084,9 +1133,9 @@ function get_block_template( $id, $template_type = 'wp_template' ) {
|
||||
*
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param string $id Template unique identifier (example: theme_slug//template_slug).
|
||||
* @param string $template_type Optional. Template type: `'wp_template'` or '`wp_template_part'`.
|
||||
* Default `'wp_template'`.
|
||||
* @param string $id Template unique identifier (example: 'theme_slug//template_slug').
|
||||
* @param string $template_type Optional. Template type: 'wp_template' or 'wp_template_part'.
|
||||
* Default 'wp_template'.
|
||||
* @return WP_Block_Template|null The found block template, or null if there isn't one.
|
||||
*/
|
||||
function get_block_file_template( $id, $template_type = 'wp_template' ) {
|
||||
@@ -1099,8 +1148,8 @@ function get_block_file_template( $id, $template_type = 'wp_template' ) {
|
||||
*
|
||||
* @param WP_Block_Template|null $block_template Return block template object to short-circuit the default query,
|
||||
* or null to allow WP to run its normal queries.
|
||||
* @param string $id Template unique identifier (example: theme_slug//template_slug).
|
||||
* @param string $template_type Template type: `'wp_template'` or '`wp_template_part'`.
|
||||
* @param string $id Template unique identifier (example: 'theme_slug//template_slug').
|
||||
* @param string $template_type Template type: 'wp_template' or 'wp_template_part'.
|
||||
*/
|
||||
$block_template = apply_filters( 'pre_get_block_file_template', null, $id, $template_type );
|
||||
if ( ! is_null( $block_template ) ) {
|
||||
@@ -1133,8 +1182,8 @@ function get_block_file_template( $id, $template_type = 'wp_template' ) {
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param WP_Block_Template|null $block_template The found block template, or null if there is none.
|
||||
* @param string $id Template unique identifier (example: theme_slug//template_slug).
|
||||
* @param string $template_type Template type: `'wp_template'` or '`wp_template_part'`.
|
||||
* @param string $id Template unique identifier (example: 'theme_slug//template_slug').
|
||||
* @param string $template_type Template type: 'wp_template' or 'wp_template_part'.
|
||||
*/
|
||||
return apply_filters( 'get_block_file_template', $block_template, $id, $template_type );
|
||||
}
|
||||
@@ -1300,7 +1349,6 @@ function wp_generate_block_templates_export_file() {
|
||||
/**
|
||||
* Gets the template hierarchy for the given template slug to be created.
|
||||
*
|
||||
*
|
||||
* Note: Always add `index` as the last fallback template.
|
||||
*
|
||||
* @since 6.1.0
|
||||
|
||||
Reference in New Issue
Block a user