Make WordPress Core


Ignore:
Timestamp:
08/27/2020 03:06:22 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Taxonomy: Make sure wp_terms_checklist() and Walker_Category_Checklist::start_el() properly handle an array of strings as selected_cats or popular_cats values.

Even with these values documented as an array of integers, they can technically also accept an array of strings, e.g. as form results.

Add a unit test.

Props brianhogg, TimothyBlynJacobs, SergeyBiryukov.
Merges [48880] to the 5.5 branch.
Fixes #51137.

Location:
branches/5.5
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.5

  • branches/5.5/src/wp-admin/includes/class-walker-category-checklist.php

    r47557 r48882  
    8282        }
    8383
    84         $args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats'];
     84        $args['popular_cats'] = ! empty( $args['popular_cats'] ) ? array_map( 'intval', $args['popular_cats'] ) : array();
    8585
    8686        $class = in_array( $category->term_id, $args['popular_cats'], true ) ? ' class="popular-category"' : '';
    8787
    88         $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats'];
     88        $args['selected_cats'] = ! empty( $args['selected_cats'] ) ? array_map( 'intval', $args['selected_cats'] ) : array();
    8989
    9090        if ( ! empty( $args['list_only'] ) ) {
Note: See TracChangeset for help on using the changeset viewer.