Skip to content

Media Editor Route: Add actions so that a media item can be deleted - #86349

Merged
andrewserong merged 7 commits into
trunkfrom
add/post-actions-to-new-media-editor
Nov 9, 2026
Merged

andrewserong merged 7 commits into
trunkfrom
add/post-actions-to-new-media-editor

Conversation

@andrewserong

@andrewserong andrewserong commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

What?

Part of #72734

In the Media Editor Route add post actions, available from the more menu, so that a media item can be deleted. This also exposes the "View" action, and opens up the possibility of additional actions in the future.

I've included these in the More menu for now. There could be a better long-term home eventually, but given we're behind an experiment I thought this a logical place to begin with.

Why?

Currently in the Media Editor Route there is no way to delete an item from the screen where you edit it! This adds that in, as part of addressing parity between the core media editor and this experiment.

How?

  • Grab the actions from usePostActions
  • We skip the duplicate and rename actions for now as they don't quite work for attachments (at least in this context yet)
  • Render the actions in the MoreMenu of the media editor, borrowing basically the same rendering logic from DataViews for the actions
  • Also, update the behaviour for cancel/redirect to be a bit more reliable (and explicitly return folks to the media library when needed). On redirecting to the media library, we clear out the snackbar, too, to make sure there's no flicker of a notice while redirectly

Testing Instructions

  1. Activate the Media Editor Route experiment:
image
  1. Go to the media library in list view mode, and go to edit an image
  2. At the top right ellipsis menu you should now see two actions under the menu (View, and Permanently Delete)
  3. If you click Permanently Delete you should get a modal confirming if you want to delete. If you click to delete, it should then take you back to the media library, with the notice displayed that the media item has been deleted
  4. (Additionally, the View item should allow you to view the image in isolation)
  5. Repeat the above with a non image media item (e.g. a PDF or ZIP file) and the more menu / actions should also be available for these
  6. Double check in the post editor's media editor modal on the image block that the ellipsis menu only shows

Screenshots or screencast

image
2026-11-06.12.54.34.mp4

Use of AI Tools

Claude Code (Opus 5.5)

@andrewserong andrewserong self-assigned this Nov 5, 2026
@andrewserong andrewserong added [Type] Enhancement A suggestion for improvement. [Feature] Media Anything that impacts the experience of managing media labels Nov 5, 2026
@github-actions github-actions Bot added the [Package] Core data /packages/core-data label Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>

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 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.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: +359 B (0%)

Total Size: 8.61 MB

📦 View Changed
Filename Size Change
build/scripts/editor/index.min.js 568 kB +359 B (+0.06%)

50450d2 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 990668e trunk % Change
timeToFirstByte 48.7 ms +7.39% -4.52% 45.7 ms +6.67% -4.27% 6.56%
largestContentfulPaint 80 ms +12.5% -5% 76 ms +7.89% -0% 5.26%
lcpMinusTtfb 31.75 ms +19.53% -8.35% 30.8 ms +17.53% -6.66% 3.08%
wpBeforeTemplate 24.53 ms +10.35% -1.92% 23.59 ms +6.95% -5.55% 3.98%
wpTemplate 19.67 ms +4.37% -3.3% 18.11 ms +6.96% -2.43% 8.61%
wpTotal 45.13 ms +7.8% -4.3% 42.27 ms +7.4% -5.13% 6.77%
wpMemoryUsage 7.72 MB +0% -0% 7.69 MB +0% -0% 0.43%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 990668e trunk % Change
timeToFirstByte 38.4 ms +4.17% -2.99% 38.85 ms +7.46% -4.5% -1.16%
largestContentfulPaint 84 ms +4.76% -4.76% 84 ms +4.76% -0% 0%
lcpMinusTtfb 45.55 ms +3.51% -3.62% 45.7 ms +1.75% -2.52% -0.33%
wpBeforeTemplate 20.73 ms +4.58% -1.25% 20.59 ms +14.96% -3.11% 0.68%
wpTemplate 14.4 ms +3.12% -5.35% 14.66 ms +7.71% -5.12% -1.77%
wpTotal 35.49 ms +4.87% -3.27% 35.84 ms +7.9% -4.38% -0.98%
wpMemoryUsage 6.41 MB +0% -0% 6.38 MB +0% -0% 0.53%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 990668e trunk % Change
mediaProcessingJpeg 324.24 ms +5.13% -0.21% 325.26 ms +1.63% -0.35% -0.31%
mediaProcessingAvif 4893.54 ms +0.57% -0.17% 4874.47 ms +0.25% -0.52% 0.39%
mediaProcessingJpegToAvif 3381.29 ms +0.71% -0.11% 3405.47 ms +0.59% -0.24% -0.71%

media-upload

Metric 990668e trunk % Change
jpegUploadProcessing 1439.83 ms +1.29% -0.54% 1436.55 ms +0.25% -0.49% 0.23%
pngUploadProcessing 232.88 ms +2.19% -6.55% 233.81 ms +4% -3.5% -0.4%
largeJpegUploadProcessing 1426.06 ms +0.36% -0.64% 1423.84 ms +0.35% -0.77% 0.16%
multipleImageUploadProcessing 1509.29 ms +1.2% -1.11% 1511.35 ms +1.63% -0.5% -0.14%

post-editor

Metric 990668e trunk % Change
serverResponse 455.01 ms +5.7% -5.21% 458.46 ms +4.51% -6.13% -0.75%
firstPaint 361.37 ms +15.92% -17.07% 372.89 ms +32.17% -7.94% -3.09%
domContentLoaded 873.53 ms +1.5% -4.51% 854.23 ms +0.79% -1.68% 2.26%
loaded 874.62 ms +1.5% -4.51% 855.49 ms +0.79% -1.69% 2.24%
firstContentfulPaint 523.89 ms +5.03% -7.63% 495.41 ms +1.48% -2.21% 5.75%
firstBlock 2184.55 ms +1% -2.12% 2186.65 ms +0.88% -1.26% -0.1%
type 18.55 ms +4.53% -11.7% 16.63 ms +2.59% -7.7% 11.55%
typeWithoutInspector 17.42 ms +5.74% -6.2% 16.4 ms +16.34% -6.16% 6.22%
typeWithTopToolbar 22.01 ms +12.77% -2% 23.16 ms +6.82% -4.15% -4.97%
typeContainer 8.34 ms +7.43% -9.71% 8.16 ms +13.11% -10.05% 2.21%
focus 117.62 ms +6.46% -5.55% 114.8 ms +7.66% -3.59% 2.46%
firstFocus 287.82 ms +0% -0% 247.01 ms +0% -0% 16.52%
selectAll 403.19 ms +2.13% -0.03% 391.42 ms +4.9% -0.91% 3.01%
undo 28.63 ms +9.54% -4.68% 29.46 ms +5.67% -7.88% -2.82%
listViewOpen 80.02 ms +5.07% -5.44% 74.5 ms +8.86% -8.64% 7.41%
inserterOpen 42.01 ms +7.05% -5.09% 40.49 ms +9.41% -8.72% 3.75%
inserterHover 11.23 ms +6.86% -12.38% 10.92 ms +9.07% -13.28% 2.84%
inserterSearch 8.04 ms +5.22% -3.73% 8.01 ms +15.61% -4.12% 0.37%
loadPatterns 610.86 ms +7.94% -4.01% 602.62 ms +7.84% -3.73% 1.37%
wpTotal 445.25 ms +5.86% -5.31% 448.86 ms +4.6% -6.27% -0.8%
wpMemoryUsage 14.78 MB +0% -0% 14.74 MB +0% -0% 0.24%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 990668e trunk % Change
serverResponse 298.82 ms +5.79% -4.84% 320.29 ms +0.48% -9.56% -6.7%
firstPaint 294.85 ms +7.67% -16.44% 303.92 ms +31.34% -11.6% -2.98%
domContentLoaded 676.45 ms +2.26% -1% 703.41 ms +3.01% -0.95% -3.83%
loaded 677.25 ms +2.27% -1% 704.29 ms +3.03% -0.95% -3.84%
firstContentfulPaint 390.83 ms +2% -1.15% 411.5 ms +0.84% -1.65% -5.02%
firstBlock 1998.35 ms +0.78% -0.77% 2039.11 ms +1.18% -0.51% -2%
type 15.14 ms +3.04% -12.75% 14.67 ms +11.25% -2.73% 3.2%
navigate 90.05 ms +11.94% -4.28% 86.14 ms +7.86% -3.75% 4.54%
loadPatterns 1103.04 ms +7.16% -18.58% 1024.95 ms +8.75% -14.54% 7.62%
loadPages 1011.93 ms +3.01% -3.97% 1037.18 ms +1.82% -2.76% -2.43%
wpTotal 290.56 ms +5.93% -5.02% 311.86 ms +0.55% -9.8% -6.83%
wpMemoryUsage 12.79 MB +0% -0% 12.76 MB +0% -0% 0.27%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

50450d2 Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

Actions are reachable via RIGHT/LEFT arrow keys in /test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  getByRole('row', { name: 'Page One Edit Actions' }).getByRole('button', { name: 'Edit' })
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" getByRole('row', { name: 'Page One Edit Actions' }).getByRole('button', { name: 'Edit' }) with timeout 5000ms
  - waiting for getByRole('row', { name: 'Page One Edit Actions' }).getByRole('button', { name: 'Edit' })
    14 × locator resolved to <button type="button" tabindex="-1" class="components-button is-small" id="view-list-0-184-primary-action-edit-post">Edit</button>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js:172:5
Page List converts to Navigation Links with entity bindings in /test/e2e/specs/editor/blocks/navigation.spec.js, passed after 1 failed attempt.
Error: expect(locator).toContainText(expected) failed

Locator: getByRole('region', { name: 'Editor settings' }).getByRole('tabpanel', { name: 'Content' }).getByRole('button', { name: /Link to:/ })
Expected substring: "test-page-1"
Received string:    "Link to:Cat/catPagePublished"
Timeout: 5000ms

Call log:
  - Expect "toContainText" getByRole('region', { name: 'Editor settings' }).getByRole('tabpanel', { name: 'Content' }).getByRole('button', { name: /Link to:/ }) with timeout 5000ms
  - waiting for getByRole('region', { name: 'Editor settings' }).getByRole('tabpanel', { name: 'Content' }).getByRole('button', { name: /Link to:/ })
    14 × locator resolved to <button type="button" aria-expanded="false" aria-haspopup="dialog" class="components-button link-preview-button is-next-40px-default-size is-secondary">…</button>
       - unexpected value "Link to:Cat/catPagePublished"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/navigation.spec.js:1949:31
Undo restores the post selection when another synced entity is loaded (RTC WebSocket) in /test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 2
+ Received  + 2

  Object {
    "attributeKey": "content",
    "blockIndex": 0,
    "content": "abcdef",
-   "endOffset": 3,
-   "offset": 3,
+   "endOffset": 2,
+   "offset": 2,
  }

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts:363:5
a navigation superseded by the traversal discharges to idle in /test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts, passed after 1 failed attempt.
SyntaxError: Unexpected token 'o', "not hydrated" is not valid JSON
    at readLog (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts:28:14)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts:47:24
    at waitForLogLength (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts:46:2)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts:693:5
inserts a block should show a blue line indicator in /test/e2e/specs/editor/various/inserting-blocks.spec.js, passed after 1 failed attempt.
TypeError: Cannot read properties of null (reading 'y')
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/inserting-blocks.spec.js:681:32
should place the caret at the click position when clicking a block that is not selected in /test/e2e/specs/editor/various/writing-flow.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 1
+ Received  + 1

@@ -1,9 +1,9 @@
  Array [
    Object {
      "attributes": Object {
-       "content": "First!",
+       "content": "First",
      },
      "name": "core/paragraph",
    },
    Object {
      "attributes": Object {

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/writing-flow.spec.js:952:41
templates can be registered and edited (Site Editor v2) in /test/e2e/specs/site-editor/template-registration.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeVisible() failed

Locator: getByText('AuthorGutenberg')
Expected: visible
Error: strict mode violation: getByText('AuthorGutenberg') resolved to 3 elements:
    1) <div data-wp-c16t="true" data-wp-component="Flex" class="_463056a1846babdd__flex eefcc0383f58d3a1__items-row _8a741740b23dfb57__expanded-row components-flex dataviews-view-grid__field">…</div> aka getByRole('row', { name: 'Row 1' }).getByText('AuthorGutenberg')
    2) <div data-wp-c16t="true" data-wp-component="Flex" class="_463056a1846babdd__flex eefcc0383f58d3a1__items-row _8a741740b23dfb57__expanded-row components-flex dataviews-view-grid__field">…</div> aka locator('[id="emptytheme//page"]').getByText('AuthorGutenberg')
    3) <div data-wp-c16t="true" data-wp-component="Flex" class="_463056a1846babdd__flex eefcc0383f58d3a1__items-row _8a741740b23dfb57__expanded-row components-flex dataviews-view-grid__field">…</div> aka locator('[id="emptytheme//plugin-template"]').getByText('AuthorGutenberg')

Call log:
  - Expect "toBeVisible" getByText('AuthorGutenberg') with timeout 5000ms
  - waiting for getByText('AuthorGutenberg')

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/template-registration.spec.js:60:55

50450d2 Run

@andrewserong
andrewserong force-pushed the add/post-actions-to-new-media-editor branch from 068ef59 to 9d4ab72 Compare November 6, 2026 02:08
@andrewserong
andrewserong force-pushed the add/post-actions-to-new-media-editor branch 2 times, most recently from a4f022e to 50603e7 Compare November 6, 2026 04:27
Comment on lines +331 to +333
// A copy of the `ActionModal` in `@wordpress/dataviews`, which isn't
// exported. It could be replaced if dataviews exports it.
function MediaActionModal( {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've basically copied how DataViews handles modal actions. Given we're behind an experiment I figured copy/pasting is probably a good way to go until we're settled on an overall design / UX for the dedicated media editor route

item?: Media;
}

function MoreMenu( { actions = [], item }: MoreMenuProps ) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy for feedback on this: the idea of the API change here is that the MoreMenu should optionally accept actions (and the media item). It could be that the media editor might wind up placing these elsewhere at some point. Does this seem a reasonable home for now?

@andrewserong
andrewserong marked this pull request as ready for review November 6, 2026 05:31
@andrewserong
andrewserong force-pushed the add/post-actions-to-new-media-editor branch from 01ac85f to 51f7cbc Compare November 8, 2026 23:21
@github-actions github-actions Bot removed the [Package] Core data /packages/core-data label Nov 8, 2026

@ramonjd ramonjd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. I am liking these small iterations on functionality.

Very helpful to test and work these things out early.

Cheers!

? sprintf(
/* translators: %s: Action label. Use the ellipsis and spacing appropriate for your language. */
_x(
'%s…',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

I see that #81994 added ellipses for actions that trigger a modal.

There was probably a good reason or it's following loose reference to https://www.w3.org/WAI/ARIA/apg/patterns/menubar/, but I'll play keyboard hero right here and say that, on the surface, it looks weird and appears superfluous to requirements.

Nothing to do here though. Bye!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't love it either. A bit further down the track (from the media editor perspective), I think we could do a pass on all these. I also don't like that "View" is just that single word. It makes me think "View what"?

But yes, I won't let these questions hold up this PR, just stuff for us to think through when we review the overall editor, its actions and behaviours.

* @param referrer The referring URL, usually `document.referrer`.
* @param currentUrl The URL of the current page.
*/
export function isAdminReferrer( referrer: string, currentUrl: string ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to check, this is just for cancel and not for the new delete functionality?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also for the new delete functionality (navigateBack, which calls this function gets called at the end of onActionPerformed). My thinking here is that in both cases (cancel and delete) if the user has come to the media editor directly (e.g. by copy + pasting the url in a different tab) then when the action is complete we only want to redirect to history.back() if the previous page they were on really was in this site's admin.

Comment thread routes/media-editor/stage.tsx Resolved
Comment thread routes/media-editor/stage.tsx Resolved
Comment on lines +237 to +243
if ( isStandaloneAdminPage ) {
// The action has just shown its snackbar. Remove it so it
// doesn't show while the page unloads.
removeAllNotices( 'snackbar' );
window.location.assign(
getMediaLibraryUrlAfterDelete( actionId, attachmentId )
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trash also uses this callback, right?

Image

I tested by dropping the MEDIA_TRASH check here: https://github.com/WordPress/gutenberg/blob/add/post-actions-to-new-media-editor/lib/compat/wordpress-7.2/rest-api.php#L333

I'm not sure anything happens in that case.

Not a big deal, maybe something to note.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I tested by dropping the MEDIA_TRASH check here:

I think that'll result in a failed trash state (since internally MEDIA_TRASH will need to be true in order for the trashing to succeed), so I've added a guard here in case the deletion has failed, so we don't redirect 👍

In terms of the happy path for MEDIA_TRASH, if I set MEDIA_TRASH to true in wp-config, e.g. via npm run env -- run cli wp config set MEDIA_TRASH true --raw the flow seems to work pretty well:

2026-11-09.13.07.03.mp4

And here's how it looks when the trashing fails (just the default error message from the REST API, again I think we can look at this separately in the core-actions package if need be):

image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good one. Thanks for checking! 🚢

@andrewserong
andrewserong merged commit 920e47d into trunk Nov 9, 2026
99 checks passed
@andrewserong
andrewserong deleted the add/post-actions-to-new-media-editor branch November 9, 2026 02:54
@github-actions github-actions Bot added this to the Gutenberg 24.5 milestone Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Media Anything that impacts the experience of managing media [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants