Make WordPress Core

Opened 19 months ago

Closed 19 months ago

Last modified 19 months ago

#59137 closed enhancement (fixed)

Add `wp_get_theme_data_custom_templates` function

Reported by: oandregal's profile oandregal Owned by: oandregal's profile oandregal
Milestone: 6.4 Priority: normal
Severity: normal Version:
Component: Themes Keywords: has-patch commit
Focuses: Cc:

Description

We lack a public function wp_get_theme_data_custom_templates to offer access to metadata stored under customTemplates in theme.json.

## Why

There is a no public function to get access to that data, so consumers need to resort to private APIs. This follows the steps of wp_get_global_settings, wp_theme_has_theme_json, wp_get_theme_directory_pattern_slugs, and wp_get_theme_data_template_parts.

Change History (11)

This ticket was mentioned in PR #5031 on WordPress/wordpress-develop by @oandregal.


19 months ago
#1

  • Keywords has-patch added

Part of https://github.com/WordPress/gutenberg/issues/45171
Trac ticket: https://core.trac.wordpress.org/ticket/59137

## What

This PR adds a new public function wp_get_theme_data_custom_templates to offer access to metadata stored under customTemplates in theme.json.

## Why

There is a no public function to get access to that data, so consumers need to resort to private APIs. This follows the steps of wp_get_global_settings, wp_theme_has_theme_json, wp_get_theme_directory_pattern_slugs, and wp_get_theme_data_template_parts.

## How

It creates a new function that uses the private calls and substitutes all the instances of the old one in the codebase.

## How to test

TBD.

## Commit message

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.

Fixes #59137

#2 @audrasjb
19 months ago

  • Keywords commit added

Thanks for the ticket and patch,
Marking this as ready for commit.

#3 @johnbillion
19 months ago

  • Keywords commit removed

@oandregal commented on PR #5031:


19 months ago
#4

This function is missing a return statement and its @return tag is incorrect. Can you check and correct those please?

Thanks, @johnbillion for catching the issue. Both things addressed.

@audrasjb commented on PR #5031:


19 months ago
#5

Ah correct.
The change looks good to me, but we usually add a line break on long docblock sentences to avoid having too much characters on the same line

@oandregal commented on PR #5031:


19 months ago
#6

The change looks good to me, but we usually add a line break on long docblock sentences to avoid having too much characters on the same line

Added the line break as well.

@oandregal commented on PR #5031:


19 months ago
#7

Looking for how we do @return in other functions, I've noticed this https://github.com/WordPress/wordpress-develop/pull/5033

@oandregal commented on PR #5031:


19 months ago
#8

@johnbillion when you have the time, can you clear up the blocker so I can commit this?

#9 @johnbillion
19 months ago

  • Keywords commit added

#10 @oandregal
19 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 56413:

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

Note: See TracTickets for help on using tickets.