From 66e059218583bb92e3901e92bd0f6155cf1305b7 Mon Sep 17 00:00:00 2001 From: oandregal Date: Fri, 18 Aug 2023 13:22:13 +0000 Subject: [PATCH] Themes: add `wp_get_theme_data_custom_templates` function. Adds a new public function, `wp_get_theme_data_custom_templates` that returns the `customTemplates` defined by the active theme from `theme.json`. It also substitutes the usage of private APIs by this new API. Props johnbillion, audrasjb. Fixes #59137 Built from https://develop.svn.wordpress.org/trunk@56413 git-svn-id: http://core.svn.wordpress.org/trunk@55925 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/block-template-utils.php | 2 +- wp-includes/global-styles-and-settings.php | 12 ++++++++++++ wp-includes/version.php | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/wp-includes/block-template-utils.php b/wp-includes/block-template-utils.php index 88bda858f0..438556a7b9 100644 --- a/wp-includes/block-template-utils.php +++ b/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/wp-includes/global-styles-and-settings.php b/wp-includes/global-styles-and-settings.php index e531e7e704..6ff5673318 100644 --- a/wp-includes/global-styles-and-settings.php +++ b/wp-includes/global-styles-and-settings.php @@ -441,6 +441,18 @@ 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 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(); +} + /** * Returns the metadata for the template parts defined by the theme. * diff --git a/wp-includes/version.php b/wp-includes/version.php index 6244db9f82..c495818a6e 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-alpha-56412'; +$wp_version = '6.4-alpha-56413'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.