Make WordPress Core


Ignore:
Timestamp:
02/09/2024 07:48:41 PM (8 months ago)
Author:
joedolson
Message:

Quick/Bulk Edit: Pre-fill category fields with their status.

Pre-fill category fields in the Quick/Bulk Edit form with their current status.

When bulk editing, if only some of the selected items are in a given category, the category's checkbox will display a line to indicate an indeterminate status.

Originally committed in [56172], but reverted due to a bug that removed all categories. Updated commit fixes the bug, adds unit tests, and improves the accessibility of the indeterminate state checkboxes.

Props pavelevap, scribu, chasedsiedu, helen, joshcanhelp, ubernaut, Cyberchicken, laumindproductscomau, SergeyBiryukov, Marcoevich, tomybyte, thinkluke, virtality-marketing-solutions, Michalooki, dmsnell, itecrs, pannelars, WHSajid, samba45, Mte90, johnbillion, tomluckies, soulseekah, francina, oglekler, ajmcfadyen, mukesh27, costdev, hellofromTonya, peterwilsoncc, joedolson, pbiron, oglekler, webcommsat, jorbin, ajmcfadyen, huzaifaalmesbah.
Fixes #11302.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/post.php

    r57521 r57580  
    650650
    651651        if ( isset( $new_cats ) && in_array( 'category', $tax_names, true ) ) {
    652             $cats                       = (array) wp_get_post_categories( $post_id );
    653             $post_data['post_category'] = array_unique( array_merge( $cats, $new_cats ) );
     652            $cats = (array) wp_get_post_categories( $post_id );
     653
     654            if (
     655                isset( $post_data['indeterminate_post_category'] )
     656                && is_array( $post_data['indeterminate_post_category'] )
     657            ) {
     658                $indeterminate_post_category = $post_data['indeterminate_post_category'];
     659            } else {
     660                $indeterminate_post_category = array();
     661            }
     662
     663            $indeterminate_cats         = array_intersect( $cats, $indeterminate_post_category );
     664            $determinate_cats           = array_diff( $new_cats, $indeterminate_post_category );
     665            $post_data['post_category'] = array_unique( array_merge( $indeterminate_cats, $determinate_cats ) );
     666
    654667            unset( $post_data['tax_input']['category'] );
    655668        }
Note: See TracChangeset for help on using the changeset viewer.