Skip to content

Bulk Edit: Allow removing Uncategorized and reset category states - #16090

Open
AbdiTolesa wants to merge 2 commits into
WordPress:trunkfrom
AbdiTolesa:fix/bulk-edit-remove-uncategorized
Open

AbdiTolesa wants to merge 2 commits into
WordPress:trunkfrom
AbdiTolesa:fix/bulk-edit-remove-uncategorized

Conversation

@AbdiTolesa

@AbdiTolesa AbdiTolesa commented Nov 18, 2026 •

Copy link
Copy Markdown

Trac ticket: https://core.trac.wordpress.org/ticket/59374

What

Bulk Edit doesn't reliably remove "Uncategorized". There are two separate causes:

  1. Stale category states (JS). After Bulk Edit has been opened once, opening it again without a page reload keeps categories checked from the previous selection. Saving then adds those categories, typically "Uncategorized", to posts that weren't in them.
  2. No categories left (PHP). When the selected posts are only in "Uncategorized" and it is unchecked, wp_insert_post() assigns the default category again, so it can't be removed.

Why it happens

  1. inlineEditPost.setBulk() in src/js/_enqueues/admin/inline-edit-post.js only ever sets checkboxes to checked or indeterminate. It never clears them, and revert() doesn't reset them. Its selector also matched the Quick Edit form, and its change / click handlers were bound again on every open.
  2. The Bulk Edit checklist always submits a hidden post_category[] value of 0. When no real category is left for a post, wp_insert_post() falls back to default_category for posts of type post.

Change

JS, setBulk():

  • Reset the Bulk Edit category checkboxes (checked, indeterminate, aria-label) and remove leftover hidden indeterminate_post_category[] inputs before computing the new states.
  • Scope the selectors to #bulk-edit so the Quick Edit form is no longer affected.
  • Namespace the change / click handlers (.inlineEditPost) and unbind them before binding again.

PHP, bulk_edit_posts():

  • If a post's category list ends up empty and the user can assign categories, remove its categories with wp_set_object_terms() after the post is updated, instead of letting the default category be reassigned. This matches the block editor, which allows a post to have no categories.

Tests

New PHPUnit tests in tests/phpunit/tests/admin/includesPost.php:

  • Unchecking the default category on posts that have no other category leaves them with no categories (fails without this change).
  • With mixed posts, the default category is removed and the other (indeterminate) categories are kept (fails without this change).
  • Leaving the default category checked keeps it.

Testing instructions

Stale states:

  1. Create category "X". Create post A in "Uncategorized" only and post B in "X" only.
  2. Posts > All Posts: select post A only, then Bulk actions > Edit > Apply. "Uncategorized" is checked. Click Cancel.
  3. Select post B only and open Bulk Edit again.
  4. Before: "Uncategorized" is still checked, and Update adds it to post B. After: only "X" is checked, and post B stays in "X" only.

No categories left:

  1. Select two posts that are only in "Uncategorized".
  2. Open Bulk Edit, uncheck "Uncategorized", and click Update.
  3. Before: the posts are still in "Uncategorized". After: the posts have no categories.

Existing behaviour still works:

  • A category that only some selected posts have shows as indeterminate and is kept when left untouched.
  • Unchecking a category that all selected posts have removes it from all of them.
  • Quick Edit still shows the correct categories after Bulk Edit has been opened and cancelled.

🤖 Generated with Claude Code

`inlineEditPost.setBulk()` set category checkboxes to checked or
indeterminate but never cleared them. Reopening Bulk Edit without a page
reload kept categories checked from the previous selection, so saving
assigned those categories (typically "Uncategorized") to posts that were not
in them.

Category states and the hidden `indeterminate_post_category[]` inputs are now
reset before the new states are computed. The checkbox selectors are scoped
to the Bulk Edit row so they no longer change the Quick Edit form, and the
change and click handlers are namespaced so they are not bound again on every
open.

Props abditolessa.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

When the selected posts are only in the default category and it is unchecked
in Bulk Edit, `wp_insert_post()` assigned the default category again, so it
could not be removed. `bulk_edit_posts()` now removes the categories of a post
whose category list ends up empty, provided the user can assign categories.

Props abditolessa.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AbdiTolesa AbdiTolesa changed the title Bulk Edit: Reset category states each time Bulk Edit opens Bulk Edit: Allow removing Uncategorized and reset category states Nov 18, 2026
@AbdiTolesa
AbdiTolesa marked this pull request as ready for review November 18, 2026 16:59
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props abditsori.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant