diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:51:18 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:51:18 +0000 |
commit | 0e41b5d52fdc6af6442816b5f465c9db9f84e126 (patch) | |
tree | e139a90049b158d4eed892d1662ee7f5c358fa31 /wp-includes/block-template-utils.php | |
parent | Adding upstream version 6.5.5+dfsg1. (diff) | |
download | wordpress-0e41b5d52fdc6af6442816b5f465c9db9f84e126.tar.xz wordpress-0e41b5d52fdc6af6442816b5f465c9db9f84e126.zip |
Adding upstream version 6.6.1+dfsg1.upstream/6.6.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'wp-includes/block-template-utils.php')
-rw-r--r-- | wp-includes/block-template-utils.php | 121 |
1 files changed, 93 insertions, 28 deletions
diff --git a/wp-includes/block-template-utils.php b/wp-includes/block-template-utils.php index 72ac83f..2681acb 100644 --- a/wp-includes/block-template-utils.php +++ b/wp-includes/block-template-utils.php @@ -53,7 +53,19 @@ function get_block_theme_folders( $theme_stylesheet = null ) { * * @since 5.9.0 * - * @return array[] The supported template part area values. + * @return array[] { + * The allowed template part area values. + * + * @type array ...$0 { + * Data for the allowed template part area. + * + * @type string $area Template part area name. + * @type string $label Template part area label. + * @type string $description Template part area description. + * @type string $icon Template part area icon. + * @type string $area_tag Template part area tag. + * } + * } */ function get_allowed_block_template_part_areas() { $default_area_definitions = array( @@ -91,7 +103,19 @@ 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 { + * The allowed template part area values. + * + * @type array ...$0 { + * Data for the template part area. + * + * @type string $area Template part area name. + * @type string $label Template part area label. + * @type string $description Template part area description. + * @type string $icon Template part area icon. + * @type string $area_tag Template part area tag. + * } + * } */ return apply_filters( 'default_wp_template_part_areas', $default_area_definitions ); } @@ -103,7 +127,16 @@ function get_allowed_block_template_part_areas() { * * @since 5.9.0 * - * @return array[] The default template types. + * @return array[] { + * The default template types. + * + * @type array ...$0 { + * Data for the template type. + * + * @type string $title Template type title. + * @type string $description Template type description. + * } + * } */ function get_default_block_template_types() { $default_template_types = array( @@ -178,7 +211,16 @@ 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 { + * The default template types. + * + * @type array ...$0 { + * Data for the template type. + * + * @type string $title Template type title. + * @type string $description Template type description. + * } + * } */ return apply_filters( 'default_template_types', $default_template_types ); } @@ -210,7 +252,7 @@ function _filter_block_template_part_area( $type ) { $type, WP_TEMPLATE_PART_AREA_UNCATEGORIZED ); - trigger_error( $warning_message, E_USER_NOTICE ); + wp_trigger_error( __FUNCTION__, $warning_message ); return WP_TEMPLATE_PART_AREA_UNCATEGORIZED; } @@ -249,16 +291,16 @@ function _get_block_templates_paths( $base_directory ) { * @param string $template_type Template type. Either 'wp_template' or 'wp_template_part'. * @param string $slug Template slug. * @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'. + * 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 ) { @@ -320,6 +362,11 @@ function _get_block_templates_files( $template_type, $query = array() ) { return null; } + $default_template_types = array(); + if ( 'wp_template' === $template_type ) { + $default_template_types = get_default_block_template_types(); + } + // 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(); @@ -383,12 +430,19 @@ function _get_block_templates_files( $template_type, $query = array() ) { if ( 'wp_template' === $template_type ) { $candidate = _add_block_template_info( $new_template_item ); + $is_custom = ! isset( $default_template_types[ $candidate['slug'] ] ); + if ( ! $post_type || ( $post_type && isset( $candidate['postTypes'] ) && in_array( $post_type, $candidate['postTypes'], true ) ) ) { $template_files[ $template_slug ] = $candidate; } + + // The custom templates with no associated post types are available for all post types. + if ( $post_type && ! isset( $candidate['postTypes'] ) && $is_custom ) { + $template_files[ $template_slug ] = $candidate; + } } } } @@ -556,8 +610,8 @@ function _build_block_template_result_from_file( $template_file, $template_type $after_block_visitor = null; $hooked_blocks = get_hooked_blocks(); if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) { - $before_block_visitor = make_before_block_visitor( $hooked_blocks, $template ); - $after_block_visitor = make_after_block_visitor( $hooked_blocks, $template ); + $before_block_visitor = make_before_block_visitor( $hooked_blocks, $template, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' ); + $after_block_visitor = make_after_block_visitor( $hooked_blocks, $template, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' ); } $blocks = parse_blocks( $template->content ); $template->content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor ); @@ -942,8 +996,8 @@ function _build_block_template_result_from_post( $post ) { $hooked_blocks = get_hooked_blocks(); if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) { - $before_block_visitor = make_before_block_visitor( $hooked_blocks, $template ); - $after_block_visitor = make_after_block_visitor( $hooked_blocks, $template ); + $before_block_visitor = make_before_block_visitor( $hooked_blocks, $template, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' ); + $after_block_visitor = make_after_block_visitor( $hooked_blocks, $template, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' ); $blocks = parse_blocks( $template->content ); $template->content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor ); } @@ -1223,7 +1277,7 @@ function get_block_file_template( $id, $template_type = 'wp_template' ) { * * @since 5.9.0 * - * @param string $part The block template part to print. Either 'header' or 'footer'. + * @param string $part The block template part to print, for example 'header' or 'footer'. */ function block_template_part( $part ) { $template_part = get_block_template( get_stylesheet() . '//' . $part, 'wp_template_part' ); @@ -1397,13 +1451,16 @@ function wp_generate_block_templates_export_file() { */ function get_template_hierarchy( $slug, $is_custom = false, $template_prefix = '' ) { if ( 'index' === $slug ) { - return array( 'index' ); + /** This filter is documented in wp-includes/template.php */ + return apply_filters( 'index_template_hierarchy', array( 'index' ) ); } if ( $is_custom ) { - return array( 'page', 'singular', 'index' ); + /** This filter is documented in wp-includes/template.php */ + return apply_filters( 'page_template_hierarchy', array( 'page', 'singular', 'index' ) ); } if ( 'front-page' === $slug ) { - return array( 'front-page', 'home', 'index' ); + /** This filter is documented in wp-includes/template.php */ + return apply_filters( 'frontpage_template_hierarchy', array( 'front-page', 'home', 'index' ) ); } $matches = array(); @@ -1469,6 +1526,18 @@ function get_template_hierarchy( $slug, $is_custom = false, $template_prefix = ' $template_hierarchy[] = 'singular'; } $template_hierarchy[] = 'index'; + + $template_type = ''; + if ( ! empty( $template_prefix ) ) { + list( $template_type ) = explode( '-', $template_prefix ); + } else { + list( $template_type ) = explode( '-', $slug ); + } + $valid_template_types = array( '404', 'archive', 'attachment', 'author', 'category', 'date', 'embed', 'frontpage', 'home', 'index', 'page', 'paged', 'privacypolicy', 'search', 'single', 'singular', 'tag', 'taxonomy' ); + if ( in_array( $template_type, $valid_template_types, true ) ) { + /** This filter is documented in wp-includes/template.php */ + return apply_filters( "{$template_type}_template_hierarchy", $template_hierarchy ); + } return $template_hierarchy; } @@ -1542,11 +1611,7 @@ function inject_ignored_hooked_blocks_metadata_attributes( $changes, $deprecated return $template; } - $before_block_visitor = make_before_block_visitor( $hooked_blocks, $template, 'set_ignored_hooked_blocks_metadata' ); - $after_block_visitor = make_after_block_visitor( $hooked_blocks, $template, 'set_ignored_hooked_blocks_metadata' ); - - $blocks = parse_blocks( $changes->post_content ); - $changes->post_content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor ); + $changes->post_content = apply_block_hooks_to_content( $changes->post_content, $template, 'set_ignored_hooked_blocks_metadata' ); return $changes; } |