Repository navigation
Media Editor Route: Add actions so that a media item can be deleted - #86349
Conversation
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: +359 B (0%) Total Size: 8.61 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome 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
|
068ef59 to
9d4ab72
Compare
a4f022e to
50603e7
Compare
| // A copy of the `ActionModal` in `@wordpress/dataviews`, which isn't | ||
| // exported. It could be replaced if dataviews exports it. | ||
| function MediaActionModal( { |
There was a problem hiding this comment.
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 ) { |
There was a problem hiding this comment.
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?
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
01ac85f to
51f7cbc
Compare
ramonjd
left a comment
There was a problem hiding this comment.
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…', |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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 ) { |
There was a problem hiding this comment.
Just to check, this is just for cancel and not for the new delete functionality?
There was a problem hiding this comment.
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.
| 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 ) | ||
| ); |
There was a problem hiding this comment.
Trash also uses this callback, right?
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.
There was a problem hiding this comment.
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):
There was a problem hiding this comment.
Ah good one. Thanks for checking! 🚢
Co-authored-by: Ramon <ramonjd@users.noreply.github.com>
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?
usePostActionsMoreMenuof the media editor, borrowing basically the same rendering logic from DataViews for the actionsTesting Instructions
Screenshots or screencast
2026-11-06.12.54.34.mp4
Use of AI Tools
Claude Code (Opus 5.5)