Skip to content

Posts: hand the bulk-actions and columns filters the window mode - #856

Merged
AllTerrainDeveloper merged 2 commits into
WordPress:trunkfrom
juanlentino:bulk-actions-mode
Oct 9, 2026
Merged

AllTerrainDeveloper merged 2 commits into
WordPress:trunkfrom
juanlentino:bulk-actions-mode

Conversation

@juanlentino

@juanlentino juanlentino commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #854.

The problem

openstation.postsWindow.bulkActions was applied with the defaults array and nothing else, though defaultBulkActions( mode ) right above it already held the mode. A plugin action that only makes sense for posts therefore painted its button in the Pages window too, and the only way to keep it out was at run() time, by walking ctx.body for the undocumented desktop-mode-pages root class and refusing with a toast: a button the window shows and then declines.

The change

resolveBulkActions( defaults, mode ) passes { mode } ('posts' | 'pages') as the filter's second argument; the columns filter gets the same from the cell env, since buildAllColumns already had it in hand. wp.hooks passes extra arguments positionally, so a callback that reads only the first argument is unchanged. statusSegments is untouched (no mode in scope there).

wp.hooks.addFilter( 'openstation.postsWindow.bulkActions', 'my-plugin/reschedule', ( actions, ctx ) =>
	ctx.mode === 'pages' ? actions : [ ...actions, RESCHEDULE ]
);
  • Test: the bulk-actions and columns callbacks receive { mode: 'posts' } then { mode: 'pages' }, and a one-arg callback in the same chain still returns the list (through createHooksStub()). Red against trunk on the assertion.
  • Docs: the two rows in docs/hooks-reference.md name the second argument; docs/examples/native-posts.md shows the pages-aware callback.
  • npm run build:apps, lint, test:js (6317 passed), typecheck all green.

Found while adding a posts-only bulk action from a plugin, which had to read the window's DOM to tell the two modes apart.

🤖 Generated with Claude Code

Open WordPress Playground Preview

A plugin action that only makes sense for posts painted its button
in the Pages window too: `openstation.postsWindow.bulkActions` got
the defaults array and nothing else, though `defaultBulkActions()`
right above it already held the mode. The only way to keep the
action out was at `run()` time, by walking `ctx.body` for the
`desktop-mode-pages` root class and refusing with a toast.

`resolveBulkActions()` now takes the mode and passes `{ mode }` as
the filter's second argument, `'posts' | 'pages'`; the columns
filter gets the same from the cell env. A callback that reads only
the first argument is unchanged. Documented in the hooks reference
and the native-posts example.

Fixes WordPress#854

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@AllTerrainDeveloper

Copy link
Copy Markdown
Collaborator

Thanks @juanlentino. We've been a bit busy. Going back to contributors now!

@AllTerrainDeveloper
AllTerrainDeveloper merged commit 36f5170 into WordPress:trunk Oct 9, 2026
7 checks passed
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.

Posts window: the bulkActions filter receives no mode, so a plugin cannot keep a posts-only action out of the Pages window

2 participants