Make WordPress Core

Changeset 57094


Ignore:
Timestamp:
11/08/2023 11:23:10 PM (3 years ago)
Author:
peterwilsoncc
Message:

Quick/Bulk Edit: Prevent assigning posts to default categories during bulk edit.

During a bulk edit of posts with different categories, the categories for the edited posts would be reset to the default category: uncategorized by default.

This reverts [56712] to resolve the issue.

Merges [57093] to the 6.4 branch.

Props peterwilsoncc, hellofromtonya, jorbin.
Fixes #59837.
See #11302.

Location:
branches/6.4
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/6.4

  • branches/6.4/src/js/_enqueues/admin/inline-edit-post.js

    r56802 r57094  
    179179        setBulk : function(){
    180180                var te = '', type = this.type, c = true;
    181                 var checkedPosts = $( 'tbody th.check-column input[type="checkbox"]:checked' );
    182                 var categories = {};
    183                 var indeterminatePostCategoryField = $( '<input type="hidden" name="indeterminate_post_category[]">' );
    184181                this.revert();
    185182
     
    220217                // Populate the list of items to bulk edit.
    221218                $( '#bulk-titles' ).html( '<ul id="bulk-titles-list" role="list">' + te + '</ul>' );
    222 
    223                 // Gather up some statistics on which of these checked posts are in which categories.
    224                 checkedPosts.each( function() {
    225                         var id      = $( this ).val();
    226                         var checked = $( '#category_' + id ).text().split( ',' );
    227 
    228                         checked.map( function( cid ) {
    229                                 categories[ cid ] || ( categories[ cid ] = 0 );
    230                                 // Just record that this category is checked.
    231                                 categories[ cid ]++;
    232                         } );
    233                 } );
    234 
    235                 // Compute initial states.
    236                 $( '.inline-edit-categories input[name="post_category[]"]' ).each( function() {
    237                         // Clear indeterminate states.
    238                         $( '<input type="hidden" name="indeterminate_post_category[]">' ).remove();
    239 
    240                         if ( categories[ $( this ).val() ] == checkedPosts.length ) {
    241                                 // If the number of checked categories matches the number of selected posts, then all posts are in this category.
    242                                 $( this ).prop( 'checked', true );
    243                         } else if ( categories[ $( this ).val() ] > 0 ) {
    244                                 // If the number is less than the number of selected posts, then it's indeterminate.
    245                                 $( this ).prop( 'indeterminate', true );
    246 
    247                                 // Set indeterminate states for the backend.
    248                                 indeterminatePostCategoryField.val( $( this ).val() );
    249                                 $( this ).after( indeterminatePostCategoryField );
    250                         }
    251                 } );
    252 
    253                 $( '.inline-edit-categories input[name="post_category[]"]' ).on( 'change', function() {
    254                         // Remove the indeterminate flags as there was a specific state change.
    255                         $( this ).parent().find( 'input[name="indeterminate_post_category[]"]' ).remove();
    256                 } );
    257 
    258                 $( '.inline-edit-save button' ).on( 'click', function() {
    259                         $( '.inline-edit-categories input[name="post_category[]"]' ).prop( 'indeterminate', false );
    260                 } );
    261219
    262220                /**
  • branches/6.4/src/wp-admin/css/list-tables.css

    r56956 r57094  
    11481148}
    11491149
    1150 ul.cat-checklist input[name="post_category[]"]:indeterminate::before {
    1151         content: '';
    1152         border-top: 2px solid grey;
    1153         width: 65%;
    1154         height: 2px;
    1155         position: absolute;
    1156         top: calc( 50% + 1px );
    1157         left: 50%;
    1158         transform: translate( -50%, -50% );
    1159 }
    1160 
    11611150#bulk-titles .ntdelbutton,
    11621151#bulk-titles .ntdeltitle,
  • branches/6.4/src/wp-admin/includes/post.php

    r56802 r57094  
    650650
    651651                if ( isset( $new_cats ) && in_array( 'category', $tax_names, true ) ) {
    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 
     652                        $cats                       = (array) wp_get_post_categories( $post_id );
     653                        $post_data['post_category'] = array_unique( array_merge( $cats, $new_cats ) );
    667654                        unset( $post_data['tax_input']['category'] );
    668655                }
Note: See TracChangeset for help on using the changeset viewer.