Make WordPress Core

Opened 5 years ago

Last modified 13 months ago

#46482 new defect (bug)

Non-hierarchical taxonomies using checkbox display are not saving in quick edit

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

Description

What steps should be taken to consistently reproduce the problem?
1) Register a custom taxonomy with these arguments to make a non-hierarchical taxonomy use checkbox display*:

'meta_box_cb' => 'post_categories_meta_box',			
'meta_box_sanitize_cb' => 'taxonomy_meta_box_sanitize_cb_checkboxes'

* I am aware it does not display this way with Gutenburg, but not everyone uses Gutenburg and CPTs do not use Gutenburg

2) Quick Edit a post of a post type that uses the custom taxonomy

3) Add terms to the custom taxonomy

4) Click Update

What is the expected output or result? What did you see instead?

The terms entered into taxonomy field should be added to the post. Instead, all terms are removed from the post for this taxonomy.

Change History (1)

#1 @mdifelice
13 months ago

Even if the meta_box_sanitize_cb argument is not set, WordPress will still use taxonomy_meta_box_sanitize_cb_checkboxes as the sanitizer when the meta_box_cb is set to post_categories_meta_box.

When using quick edit, WordPress does not take into account those arguments when printing the term selector, it just checks if the taxonomy is hierarchical or not. However, when saving the quick edit data, it uses what the meta_box_sanitize_cb defines. That is a strong inconsistency: quick edit sends a string, and the save function attempts to sanitize an array. The result is a fatal error (Uncaught Error: array_map(): Argument 2 ($array) must be of type array, string given in /wp-admin/includes/post.php on line 2107).

It is hard to propose a solution here. A quick fix I found for my plugins is to add the show_in_quick_edit argument with a false value on these cases, which prevents the error but it is far from being a desirable solution.

I think that the best approach would be to use the same functions used in the edit screen in the quick edit screen, but without rewriting them it may break some retro-compatibility.

Note: See TracTickets for help on using tickets.