Commit cbf9ed6f authored by Sergey Biryukov's avatar Sergey Biryukov
Browse files

Taxonomy: Make sure `wp_terms_checklist()` and...

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.
Built from https://develop.svn.wordpress.org/branches/5.5@48882


git-svn-id: https://core.svn.wordpress.org/branches/5.5@48644 1a063a9b-81f0-0310-95a4-ce76da25c4cd
parent 6dd2627d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -81,11 +81,11 @@ class Walker_Category_Checklist extends Walker {
			$name = 'tax_input[' . $taxonomy . ']';
		}

		$args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats'];
		$args['popular_cats'] = ! empty( $args['popular_cats'] ) ? array_map( 'intval', $args['popular_cats'] ) : array();

		$class = in_array( $category->term_id, $args['popular_cats'], true ) ? ' class="popular-category"' : '';

		$args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats'];
		$args['selected_cats'] = ! empty( $args['selected_cats'] ) ? array_map( 'intval', $args['selected_cats'] ) : array();

		if ( ! empty( $args['list_only'] ) ) {
			$aria_checked = 'false';
+2 −2
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ function wp_terms_checklist( $post_id = 0, $args = array() ) {
	$args['list_only'] = ! empty( $parsed_args['list_only'] );

	if ( is_array( $parsed_args['selected_cats'] ) ) {
		$args['selected_cats'] = $parsed_args['selected_cats'];
		$args['selected_cats'] = array_map( 'intval', $parsed_args['selected_cats'] );
	} elseif ( $post_id ) {
		$args['selected_cats'] = wp_get_object_terms( $post_id, $taxonomy, array_merge( $args, array( 'fields' => 'ids' ) ) );
	} else {
@@ -128,7 +128,7 @@ function wp_terms_checklist( $post_id = 0, $args = array() ) {
	}

	if ( is_array( $parsed_args['popular_cats'] ) ) {
		$args['popular_cats'] = $parsed_args['popular_cats'];
		$args['popular_cats'] = array_map( 'intval', $parsed_args['popular_cats'] );
	} else {
		$args['popular_cats'] = get_terms(
			array(
+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@
 *
 * @global string $wp_version
 */
$wp_version = '5.5.1-alpha-48879';
$wp_version = '5.5.1-alpha-48882';

/**
 * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.