Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2bf4a27

Browse files
committed
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. Props peterwilsoncc, hellofromtonya, jorbin. Fixes #59837. See WordPress#11302. git-svn-id: https://develop.svn.wordpress.org/trunk@57093 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 8c2c762 commit 2bf4a27

3 files changed

Lines changed: 2 additions & 68 deletions

File tree

src/js/_enqueues/admin/inline-edit-post.js

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,6 @@ window.wp = window.wp || {};
178178
*/
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

186183
$( '#bulk-edit td' ).attr( 'colspan', $( 'th:visible, td:visible', '.widefat:first thead' ).length );
@@ -220,45 +217,6 @@ window.wp = window.wp || {};
220217
// Populate the list of items to bulk edit.
221218
$( '#bulk-titles' ).html( '<ul id="bulk-titles-list" role="list">' + te + '</ul>' );
222219

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-
} );
261-
262220
/**
263221
* Binds on click events to handle the list of items to bulk edit.
264222
*

src/wp-admin/css/list-tables.css

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,17 +1147,6 @@ ul.cat-checklist {
11471147
overflow-y: scroll;
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,
11631152
.inline-edit-row fieldset ul.cat-checklist label {

src/wp-admin/includes/post.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -649,21 +649,8 @@ function bulk_edit_posts( $post_data = null ) {
649649
}
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
}
669656

0 commit comments

Comments
 (0)