#61580 closed defect (bug) (fixed)
WP_REST_Templates_Controller::get_wp_templates_author_text_field() doesn't always return value
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.7 | Priority: | normal |
Severity: | minor | Version: | 6.6 |
Component: | REST API | Keywords: | has-patch commit |
Focuses: | rest-api | Cc: |
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.
9 months ago
#2
- Keywords has-patch added
Trac ticket: https://core.trac.wordpress.org/ticket/61580
#3
in reply to:
↑ 1
@
9 months 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
@
9 months ago
- Keywords changes-requested added
- Milestone changed from Awaiting Review to 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:
9 months 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:
9 months 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
@
8 months ago
- Keywords commit added; changes-requested removed
- Owner set to hellofromTonya
- Status changed from new to 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:
8 months ago
#9
Committed via https://core.trac.wordpress.org/changeset/58705. Thanks everyone for your contributions
@antonvlasenko commented on PR #7000:
8 months ago
#10
Committed via https://core.trac.wordpress.org/changeset/58705. Thanks everyone for your contributions
Thank you!
Replying to antonvlasenko: