Opened 10 months ago
Last modified 2 months ago
#63257 accepted defect (bug)
sanitize_term_field missing default $context value
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 7.0 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Taxonomy | Keywords: | has-patch |
| Focuses: | Cc: |
Description
As per the inline documentation of the sanitize_term_field() function, a default $context value should be passed in the function arguments.
Change History (18)
This ticket was mentioned in PR #8670 on WordPress/wordpress-develop by @dilipbheda.
10 months ago
#1
#3
@
10 months ago
@audrasjb You're right, but I noticed that the documentation mentions a Default value, which implies that if the last parameter is not passed, it should default to the 'display' context.
Ref: https://tinyurl.com/22neh87o
Or we can remove the default value mentioned in the inline docs.
#4
@
9 months ago
Defining the default $context = 'display' avoids errors if the function gets called without the $context parameter so it's making sense to me. For that reason it will be possible to also call the function with only the first 4 parameters, if needed. Also it is clearer in regards to the inline documentation.
#5
@
9 months ago
- Keywords 2nd-opinion removed
- Milestone changed from Awaiting Review to 6.9
- Owner set to audrasjb
- Status changed from new to accepted
You make a point @Presskopp. Let's add the default then.
@rollybueno commented on PR #8670:
5 months ago
#6
Looks good to me :+1:
#7
@
5 months ago
Hey @audrasjb, PR https://github.com/WordPress/wordpress-develop/pull/8670 only updates the $context to $context = 'display' as per https://core.trac.wordpress.org/ticket/63257#comment:4.
I believe this is ready for commit.
This ticket was mentioned in Slack in #core by welcher. View the logs.
3 months ago
#9
@
3 months ago
The was reviewed in the 6.9 bug scrub today. The linked PR has some failing unit tests. If we can get those passing before RC1 next week, this can probably be ready for commit.
#10
@
3 months ago
- Component changed from General to Taxonomy
- Keywords needs-unit-tests added
I think it's mostly ready to be deployed. @Presskopp made a good point, but I would have preferred to see some code to reproduce any scenario affecting this, plus some unit testing that proves this is required, would do even better.
@mindctrl commented on PR #8670:
3 months ago
#11
@dilipbheda could you bring your PR up to date with the trunk branch? This will ensure the patch applies cleanly and will also run the test suite again (which failed for some reason, but the logs are no longer available to understand why).
This ticket was mentioned in PR #10484 on WordPress/wordpress-develop by @nimeshatxecurify.
2 months ago
#12
refreshing the patch along with phpcbf
original credits : @dilipbheda
@wildworks commented on PR #10484:
2 months ago
#13
Thanks for the PR. However, this PR seems to contain unnecessary changes.
Let me close this PR, and I'd like to move #10484 forward.
@wildworks commented on PR #8670:
2 months ago
#14
could you bring your PR up to date with the
trunkbranch?
I handled it.
#15
@
2 months ago
Just one quick question: if we add a default value, will it affect consumers who are already using the "term_{$field}" or "{$taxonomy}_{$field}" filters?
For example, consumers may be using hooks such as the following:
add_filter( 'term_name', function( $value, $term_id, $taxonomy, $context ) {
if ( empty( $context ) ) {
return 'something';
}
return $value;
}, 10, 4 );
@mindctrl commented on PR #8670:
2 months ago
#17
Given your question on the Trac ticket, I think we should punt this one and leave room for discussion and discovery.
#18
@
2 months ago
- Keywords needs-unit-tests removed
- Milestone changed from 6.9 to 7.0
Just one quick question: if we add a default value, will it affect consumers who are already using the
"term_{$field}"or"{$taxonomy}_{$field}"filters?
For example, consumers may be using hooks such as the following:
add_filter( 'term_name', function( $value, $term_id, $taxonomy, $context ) { if ( empty( $context ) ) { return 'something'; } return $value; }, 10, 4 );
As I understand it, when sanitize_term_field is called without a context, the $context value passed to the above filter changes, which affects backward compatibility.
I'm not sure why the get_term_field() and sanitize_term() functions have default values while the sanitize_term_field() function doesn't, but further investigation is needed. Alternatively, it might be possible to close this as "wontfix".
Hello and thank you for the ticket.
I may be wrong but to be honest, given the default condition passes through a simple
elsestatement, I cannot see much value to pass the default value. It is not used anywhere in the function.