#61580 closed defect (bug) (fixed)
WP_REST_Templates_Controller::get_wp_templates_author_text_field() doesn't always return value
| Reported by: | antonvlasenko | Owned by: | hellofromTonya |
|---|---|---|---|
| Priority: | normal | Milestone: | 6.7 |
| Component: | REST API | Version: | 6.6 |
| Severity: | minor | Keywords: | has-patch commit |
| Cc: | Focuses: | rest-api |
Description
The WP_REST_Templates_Controller::get_wp_templates_author_text_field() method sometimes fails to return a value. Its @return type is specified as a string, so it should consistently return a string.
Possible solutions include returning an empty string or throwing an exception if the $original_source does not equal one of the expected values.
Change History (10)
This ticket was mentioned in PR #7000 on WordPress/wordpress-develop by @antonvlasenko.
2 years ago
#2
- Keywords has-patch added
Trac ticket: https://core.trac.wordpress.org/ticket/61580
#3
in reply to: ↑ 1
@
2 years ago
Replying to debarghyabanerjee:
I have checked the core codebase, and if you check this function, you will find that it will always return a string, which will be one of the expected values/cases.
WP_REST_Templates_Controller::get_wp_templates_original_source_field()
Thank you for your feedback. You are right. The :: get_wp_templates_author_text_field() method will always return a string if the ::get_wp_templates_original_source_field() method returns one of the expected values: theme, plugin, site, or user.
However, if ::get_wp_templates_original_source_field() method is changed to return unexpected values, it poses a risk.
I suggest that ::get_wp_templates_author_text_field() should return a default value instead of relying on ::get_wp_templates_original_source_field() to return predefined values.
I explored that option in https://github.com/WordPress/wordpress-develop/pull/7000.
#4
@
2 years ago
- Keywords changes-requested added
- Milestone Awaiting Review → 6.7
Hmm, this is interesting.
WP_REST_Templates_Controller:: get_wp_templates_original_source_field() always returns a string with one of the values used within the switch() within WP_REST_Templates_Controller::get_wp_templates_author_text_field().
But as @antonvlasenko noted, what if either method gets changed? To make the code more future-proof to avoid changes in one method affecting the other, a default of an empty string could be the graceful fall-through, e.g. return '';' at the end of the method.
Moving this into 6.7 for visibility.
I'll also comment on the PR with a suggested change.
@debarghyabanerjee commented on PR #7000:
2 years ago
#5
Hi @anton-vlasenko,
Did you check this method,
WP_REST_Templates_Controller::get_wp_templates_original_source_field()
This will always return a string which will match atleast one of the cases. Thanks :-)
@debarghyabanerjee commented on PR #7000:
2 years ago
#6
Hi @anton-vlasenko,
Did you check this method,
WP_REST_Templates_Controller::get_wp_templates_original_source_field()
This will always return a string which will match atleast one of the cases. Thanks :-)
#7
@
2 years ago
- Keywords commit added; changes-requested removed
- Owner set to
- Status new → reviewing
Patch: https://github.com/WordPress/wordpress-develop/pull/7000
Marking this ready for commit and self-assigning for the commit.
@hellofromTonya commented on PR #7000:
2 years ago
#9
Committed via https://core.trac.wordpress.org/changeset/58705. Thanks everyone for your contributions
@antonvlasenko commented on PR #7000:
2 years ago
#10
Committed via https://core.trac.wordpress.org/changeset/58705. Thanks everyone for your contributions
Thank you!
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Replying to antonvlasenko: