#51137 closed defect (bug) (fixed)
wp_terms_checklist not checking selected taxonomy items with selected_cats option
| Reported by: | brianhogg | Owned by: | SergeyBiryukov |
|---|---|---|---|
| Priority: | normal | Milestone: | 5.5.1 |
| Component: | Taxonomy | Version: | 5.5 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: | template, coding-standards |
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)
#3
@
6 years ago
- Component General → Taxonomy
- Owner set to
- Status new → 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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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_optionorget_metadata.It looks like it also affects the following functions:
wp_popular_terms_checklistwp_link_category_checklistWalker_Category_Checklist::start_elLooking 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.