Make WordPress Core


Ignore:
Timestamp:
08/27/2020 02:46:22 AM (17 months 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.
Fixes #51137.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-walker-category-checklist.php

    r47557 r48880  
    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.