johnbillion / extended-cpts

A library which provides extended functionality to WordPress custom post types and taxonomies.
GNU General Public License v2.0
979 stars 96 forks source link

WordPress 5.1: Warning: array_map(): Expected parameter 2 to be an array, string given #116

Closed dac514 closed 4 years ago

dac514 commented 5 years ago

Issue:

register_extended_taxonomy(
    'chapter-type',
    'chapter',
    [
        'meta_box' => 'dropdown',
        'hierarchical' => true,
        // ... snip ...

Since upgrading to WordPress 5.1.0, when I $_POST, 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 );
}

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

Commit that broke things:

Change in 5.1.0 that weren't in 5.0.3

dac514 commented 5 years ago

I can fix the issue by setting:

'meta_box_sanitize_cb' => 'taxonomy_meta_box_sanitize_cb_input',

Maybe extended-cpts can just do this automatically when meta_box is dropdown?

More likely, the taxonomy_meta_box_sanitize_cb_checkboxes needs to be fixed.

The param says @param mixed $terms ... but that's now how array_map works.

dac514 commented 5 years ago

WordPress Core Ticket: https://core.trac.wordpress.org/ticket/46338

johnbillion commented 4 years ago

This should be fixed by #131