Make WordPress Core


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/template.php

    r48760 r48880  
    121121
    122122    if ( is_array( $parsed_args['selected_cats'] ) ) {
    123         $args['selected_cats'] = $parsed_args['selected_cats'];
     123        $args['selected_cats'] = array_map( 'intval', $parsed_args['selected_cats'] );
    124124    } elseif ( $post_id ) {
    125125        $args['selected_cats'] = wp_get_object_terms( $post_id, $taxonomy, array_merge( $args, array( 'fields' => 'ids' ) ) );
     
    129129
    130130    if ( is_array( $parsed_args['popular_cats'] ) ) {
    131         $args['popular_cats'] = $parsed_args['popular_cats'];
     131        $args['popular_cats'] = array_map( 'intval', $parsed_args['popular_cats'] );
    132132    } else {
    133133        $args['popular_cats'] = get_terms(
Note: See TracChangeset for help on using the changeset viewer.