Make WordPress Core

Opened 5 years ago

#46338 new defect (bug)

taxonomy_meta_box_sanitize_cb_checkboxes: Warning: array_map(): Expected parameter 2 to be an array, string given

Reported by: conner_bw's profile conner_bw Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.1
Component: Taxonomy Keywords:
Focuses: Cc:

Description

Since upgrading to WordPress 5.1.0, when editing a custom post type I get a PHP error:

( ! ) Warning: array_map(): Expected parameter 2 to be an array, string given in wp-admin/includes/post.php on line 2005

/**
* Sanitizes POST values from a checkbox taxonomy metabox.
*
* @since 5.1.0
*
* @param mixed $terms Raw term data from the 'tax_input' field.
* @return array
*/
function taxonomy_meta_box_sanitize_cb_checkboxes( $taxonomy, $terms ) {
   return array_map( 'intval', $terms );
}

register_taxonomy: hierarchical is set to true.
The $_POST looks like: tax_input[chapter-type]: -1
The value of $terms passed to taxonomy_meta_box_sanitize_cb_checkboxes is equal to -1
The HTML that sends this info along, rendered by extended-cpts, looks like:

<select name="tax_input[chapter-type]" id="chapter-typedropdown" class="postform">
	<option value="-1">No chapter type</option>
	<option class="level-0" value="55">Numberless</option>
	<option class="level-0" value="54">Standard</option>
</select>

If I manually specify 'meta_box_sanitize_cb' => 'taxonomy_meta_box_sanitize_cb_input' as an arg in register_taxonomy the bug goes away.

The problem is, since no callbacks are specified, and since hierarchical is true, WordPress 5.1 sets up taxonomy_meta_box_sanitize_cb_checkboxes which doesn't work on $terms that are not an array.

It was working fine before.

Commit that broke things:

Change in 5.1.0 that weren't in 5.0.3

Related:

Change History (0)

Note: See TracTickets for help on using tickets.