#51137 closed defect (bug) (fixed)
wp_terms_checklist not checking selected taxonomy items with selected_cats option
Reported by: | brianhogg | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 5.5.1 | Priority: | normal |
Severity: | normal | Version: | 5.5 |
Component: | Taxonomy | Keywords: | has-patch |
Focuses: | template, coding-standards | Cc: |
Description
Since WP 5.5, using the selected_cats
option with an array of taxonomy IDs as strings no longer selects those items in the checklist. It appears line 174 of wp-admin/includes/template.php is using a strict type comparison for in_array:
if ( in_array( $categories[ $k ]->term_id, $args['selected_cats'], true ) ) {
Since form results are often returned as strings, and the term ID will always be an integer in the WP_Term class, I think the strict flag should be removed. Otherwise anyone using the function would need to ensure the array elements are integers with something like array_map( 'intval', ... )
Attachments (1)
Change History (8)
#2
@
4 years ago
- Focuses template coding-standards added
- Milestone changed from Awaiting Review to 5.5.1
#3
@
4 years ago
- Component changed from General to Taxonomy
- Owner set to SergeyBiryukov
- Status changed from new to reviewing
Hi there, welcome back to WordPress Trac! Thanks for the report.
I agree this should be fixed in 5.5.1. I thought I verified that $args['selected_cats']
is an array of integers here, but apparently that's not always the case.
As noted above, array_map( 'intval', ... )
would be the way to go here, as removing the strict check would just reintroduce the coding standards issue.
Thanks for the ticket @brianhogg!
Introduce in [47557]. I agree, I think this is worth fixing precisely because these functions are used so often in contexts where the value will be a string. Both form elements, and also as the results of
get_option
orget_metadata
.It looks like it also affects the following functions:
wp_popular_terms_checklist
wp_link_category_checklist
Walker_Category_Checklist::start_el
Looking at some other places in Core, we might instead want to
array_map( 'intval' )
instead of making it a loose comparison. For instanceWP_Http_Cookie::test
.Cc: @SergeyBiryukov.