From 39af262eb8a098ddf25cad1715c317d58995755e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Fri, 18 Aug 2023 10:35:35 +0200 Subject: [PATCH 1/4] Add public method wp_get_theme_data_custom_templates --- src/wp-includes/block-template-utils.php | 2 +- src/wp-includes/global-styles-and-settings.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/block-template-utils.php b/src/wp-includes/block-template-utils.php index 88bda858f06a8..438556a7b9df5 100644 --- a/src/wp-includes/block-template-utils.php +++ b/src/wp-includes/block-template-utils.php @@ -411,7 +411,7 @@ function _add_block_template_info( $template_item ) { return $template_item; } - $theme_data = WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) )->get_custom_templates(); + $theme_data = wp_get_theme_data_custom_templates(); if ( isset( $theme_data[ $template_item['slug'] ] ) ) { $template_item['title'] = $theme_data[ $template_item['slug'] ]['title']; $template_item['postTypes'] = $theme_data[ $template_item['slug'] ]['postTypes']; diff --git a/src/wp-includes/global-styles-and-settings.php b/src/wp-includes/global-styles-and-settings.php index 0f1ca5c82bb59..19e26eebe59b5 100644 --- a/src/wp-includes/global-styles-and-settings.php +++ b/src/wp-includes/global-styles-and-settings.php @@ -441,6 +441,17 @@ function wp_get_theme_directory_pattern_slugs() { return WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) )->get_patterns(); } +/** + * Returns the metadata for the custom templates defined by the theme via theme.json. + * + * @since 6.4.0 + * + * @return array + */ +function wp_get_theme_data_custom_templates() { + WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) )->get_custom_templates(); +} + /** * Returns the metadata for the template parts defined by the theme. * From d49ef7f5d95cef92d0fea73065e86e7b2fea19dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Fri, 18 Aug 2023 11:29:57 +0200 Subject: [PATCH 2/4] Fix typo --- src/wp-includes/global-styles-and-settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/global-styles-and-settings.php b/src/wp-includes/global-styles-and-settings.php index 19e26eebe59b5..96874c7b2a8a2 100644 --- a/src/wp-includes/global-styles-and-settings.php +++ b/src/wp-includes/global-styles-and-settings.php @@ -449,7 +449,7 @@ function wp_get_theme_directory_pattern_slugs() { * @return array */ function wp_get_theme_data_custom_templates() { - WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) )->get_custom_templates(); + return WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) )->get_custom_templates(); } /** From d669cc98e343713b157773160a473eb67064e9bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Fri, 18 Aug 2023 11:35:23 +0200 Subject: [PATCH 3/4] Add description to @return tag --- src/wp-includes/global-styles-and-settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/global-styles-and-settings.php b/src/wp-includes/global-styles-and-settings.php index 96874c7b2a8a2..65ed6bbb05e6b 100644 --- a/src/wp-includes/global-styles-and-settings.php +++ b/src/wp-includes/global-styles-and-settings.php @@ -446,7 +446,7 @@ function wp_get_theme_directory_pattern_slugs() { * * @since 6.4.0 * - * @return array + * @return array Associative array of `$template_name => $template_data` pairs, with `$template_data` having "title" and "postTypes" fields. */ function wp_get_theme_data_custom_templates() { return WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) )->get_custom_templates(); From 2264fe4944f42ae6f07625409775a520baf6d579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Fri, 18 Aug 2023 12:00:48 +0200 Subject: [PATCH 4/4] Add line break to @return description --- src/wp-includes/global-styles-and-settings.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/global-styles-and-settings.php b/src/wp-includes/global-styles-and-settings.php index 65ed6bbb05e6b..17ff41d002214 100644 --- a/src/wp-includes/global-styles-and-settings.php +++ b/src/wp-includes/global-styles-and-settings.php @@ -446,7 +446,8 @@ function wp_get_theme_directory_pattern_slugs() { * * @since 6.4.0 * - * @return array Associative array of `$template_name => $template_data` pairs, with `$template_data` having "title" and "postTypes" fields. + * @return array Associative array of `$template_name => $template_data` pairs, + * with `$template_data` having "title" and "postTypes" fields. */ function wp_get_theme_data_custom_templates() { return WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) )->get_custom_templates();