[wp-trac] [WordPress Trac] #46338: taxonomy_meta_box_sanitize_cb_checkboxes: Warning: array_map(): Expected parameter 2 to be an array, string given

WordPress Trac noreply at wordpress.org
Mon Feb 25 02:30:33 UTC 2019


#46338: taxonomy_meta_box_sanitize_cb_checkboxes: Warning: array_map(): Expected
parameter 2 to be an array, string given
--------------------------+-----------------------------
 Reporter:  conner_bw     |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Taxonomy      |    Version:  5.1
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 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:

 * [WordPress/wordpress-develop at 4ec5d65](https://github.com/WordPress
 /wordpress-develop/commit/4ec5d65dcc2e480506c22dc77e56af8a6334a33e)

 Change in 5.1.0 that weren't in 5.0.3

 * https://github.com/WordPress/wordpress-develop/blob/5.1.0/src/wp-
 includes/class-wp-taxonomy.php#L360
 * https://github.com/WordPress/wordpress-develop/blob/5.0.3/src/wp-
 includes/class-wp-taxonomy.php#L346

 Related:

  * https://github.com/johnbillion/extended-cpts/issues/116

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/46338>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list