diff -r 7b1b88e27a20 -r 48c4eec2b7e6 wp/wp-admin/js/inline-edit-post.js --- a/wp/wp-admin/js/inline-edit-post.js Thu Sep 29 08:06:27 2022 +0200 +++ b/wp/wp-admin/js/inline-edit-post.js Fri Sep 05 18:40:08 2025 +0200 @@ -178,6 +178,8 @@ */ setBulk : function(){ var te = '', type = this.type, c = true; + var checkedPosts = $( 'tbody th.check-column input[type="checkbox"]:checked' ); + var categories = {}; this.revert(); $( '#bulk-edit td' ).attr( 'colspan', $( 'th:visible, td:visible', '.widefat:first thead' ).length ); @@ -217,6 +219,44 @@ // Populate the list of items to bulk edit. $( '#bulk-titles' ).html( '' ); + // Gather up some statistics on which of these checked posts are in which categories. + checkedPosts.each( function() { + var id = $( this ).val(); + var checked = $( '#category_' + id ).text().split( ',' ); + + checked.map( function( cid ) { + categories[ cid ] || ( categories[ cid ] = 0 ); + // Just record that this category is checked. + categories[ cid ]++; + } ); + } ); + + // Compute initial states. + $( '.inline-edit-categories input[name="post_category[]"]' ).each( function() { + if ( categories[ $( this ).val() ] == checkedPosts.length ) { + // If the number of checked categories matches the number of selected posts, then all posts are in this category. + $( this ).prop( 'checked', true ); + } else if ( categories[ $( this ).val() ] > 0 ) { + // If the number is less than the number of selected posts, then it's indeterminate. + $( this ).prop( 'indeterminate', true ); + if ( ! $( this ).parent().find( 'input[name="indeterminate_post_category[]"]' ).length ) { + // Get the term label text. + var label = $( this ).parent().text(); + // Set indeterminate states for the backend. Add accessible text for indeterminate inputs. + $( this ).after( '' ).attr( 'aria-label', label.trim() + ': ' + wp.i18n.__( 'Some selected posts have this category' ) ); + } + } + } ); + + $( '.inline-edit-categories input[name="post_category[]"]:indeterminate' ).on( 'change', function() { + // Remove accessible label text. Remove the indeterminate flags as there was a specific state change. + $( this ).removeAttr( 'aria-label' ).parent().find( 'input[name="indeterminate_post_category[]"]' ).remove(); + } ); + + $( '.inline-edit-save button' ).on( 'click', function() { + $( '.inline-edit-categories input[name="post_category[]"]' ).prop( 'indeterminate', false ); + } ); + /** * Binds on click events to handle the list of items to bulk edit. * @@ -228,6 +268,7 @@ $prev = $this.parent().prev().children( '.ntdelbutton' ), $next = $this.parent().next().children( '.ntdelbutton' ); + $( 'input#cb-select-all-1, input#cb-select-all-2' ).prop( 'checked', false ); $( 'table.widefat input[value="' + id + '"]' ).prop( 'checked', false ); $( '#_' + id ).parent().remove(); wp.a11y.speak( wp.i18n.__( 'Item removed.' ), 'assertive' ); @@ -305,7 +346,7 @@ if ( !$(':input[name="post_author"] option[value="' + $('.post_author', rowData).text() + '"]', editRow).val() ) { // The post author no longer has edit capabilities, so we need to add them to the list of authors. - $(':input[name="post_author"]', editRow).prepend(''); + $(':input[name="post_author"]', editRow).prepend(''); } if ( $( ':input[name="post_author"] option', editRow ).length === 1 ) { $('label.inline-edit-author', editRow).hide(); @@ -376,9 +417,14 @@ }); // Handle the post status. + var post_date_string = $(':input[name="aa"]').val() + '-' + $(':input[name="mm"]').val() + '-' + $(':input[name="jj"]').val(); + post_date_string += ' ' + $(':input[name="hh"]').val() + ':' + $(':input[name="mn"]').val() + ':' + $(':input[name="ss"]').val(); + var post_date = new Date( post_date_string ); status = $('._status', rowData).text(); - if ( 'future' !== status ) { + if ( 'future' !== status && Date.now() > post_date ) { $('select[name="_status"] option[value="future"]', editRow).remove(); + } else { + $('select[name="_status"] option[value="publish"]', editRow).remove(); } pw = $( '.inline-edit-password-input' ).prop( 'disabled', false );