Themes: add wp_get_theme_data_template_parts function.

Adds a new public function, `wp_get_theme_data_template_parts` that returns the `templateParts` defined by the active theme from `theme.json`. It also substitutes the usage of private APIs by this new API.

Props felixarntz.
Fixes #59003

Built from https://develop.svn.wordpress.org/trunk@56385


git-svn-id: http://core.svn.wordpress.org/trunk@55897 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
oandregal 2023-08-11 11:24:11 +00:00
parent 77a55d839e
commit 96c6c273dd
3 changed files with 33 additions and 2 deletions

View File

@ -431,7 +431,7 @@ function _add_block_template_info( $template_item ) {
*/
function _add_block_template_part_area_info( $template_info ) {
if ( wp_theme_has_theme_json() ) {
$theme_data = WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) )->get_template_parts();
$theme_data = wp_get_theme_data_template_parts();
}
if ( isset( $theme_data[ $template_info['slug'] ]['area'] ) ) {

View File

@ -425,6 +425,7 @@ function wp_clean_theme_json_cache() {
wp_cache_delete( 'wp_get_global_settings_custom', 'theme_json' );
wp_cache_delete( 'wp_get_global_settings_theme', 'theme_json' );
wp_cache_delete( 'wp_get_global_styles_custom_css', 'theme_json' );
wp_cache_delete( 'wp_get_theme_data_template_parts', 'theme_json' );
WP_Theme_JSON_Resolver::clean_cached_data();
}
@ -440,6 +441,36 @@ 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 template parts defined by the theme.
*
* @since 6.4.0
*
* return array Associative array of `$part_name => $part_data` pairs, with `$part_data` having "title" and "area" fields.
*/
function wp_get_theme_data_template_parts() {
$cache_group = 'theme_json';
$cache_key = 'wp_get_theme_data_template_parts';
$can_use_cached = ! wp_is_development_mode( 'theme' );
$metadata = false;
if ( $can_use_cached ) {
$metadata = wp_cache_get( $cache_key, $cache_group );
if ( false !== $metadata ) {
return $metadata;
}
}
if ( false === $metadata ) {
$metadata = WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) )->get_template_parts();
if ( $can_use_cached ) {
wp_cache_set( $cache_key, $metadata, $cache_group );
}
}
return $metadata;
}
/**
* Determines the CSS selector for the block type and property provided,
* returning it if available.

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.4-alpha-56384';
$wp_version = '6.4-alpha-56385';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.