Opened 8 years ago
Last modified 4 years ago
#40427 new enhancement
Expose a JavaScript API to extend the Media Manager
Reported by: | jonathanbardo | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 4.8 |
Component: | Media | Keywords: | |
Focuses: | javascript | Cc: |
Description
After talking with @mikeschroder as Pressnomics about how hard it was to extend the media manager, I wanted to open the discussion here for ways we could improve that.
One way I made it work for the Stock Photo plugins at GoDaddy was to override core bindHandlers (see https://github.com/godaddy/wp-stock-photos/blob/master/assets/js/stock-photos.manifest.js#L13) and register my new view. One problem with that approach is that it makes it hard for anyone else to extend it for themselves.
I'm turning out to the community so we can discuss ways we could expose hooks that would let anyone extend any part of the media manager experience. This could pave the way for awesome new plugins.
Change History (8)
#1
@
8 years ago
- Summary changed from Expose an API to extend the Media Manager to Expose a JavaScript API to extend the Media Manager
This ticket was mentioned in Slack in #core-media by joemcgill. View the logs.
8 years ago
This ticket was mentioned in Slack in #core-media by westonruter. View the logs.
8 years ago
#5
@
8 years ago
I am very excited to see this ticket and the prospect of a better way to work with and extend the Media Manager. My plugin (Media Library Assistant), like many others, adds features to the Media Manager and I have found it a very frustrating experience. My JavaScript skills lag well behind my PHP skills, but I know that a better API would be a big improvement.
Here are the kinds of changes I've made:
- Add one or more controls to the toolbar. For example, a dropdown control to filter the attachments by taxonomy term (my plugin adds taxonomy support to attachments).
- Modify or replace an existing toolbar control. For example, add more choices to the MIME Type "views" dropdown control.
- Add elements to the "query attachments" action and submit a new query when an element's value has changed.
- Add or replace elements in the ATTACHMENT DETAILS pane (some support exists). For example, replace the text box controls for taxonomies with true meta boxes like those in the full screen Media/Edit Media submenu.
- Supply initial/default values for the Alignment, Link to and Size controls in the ATTACHMENT DETAILS pane.
Adding/changing the toolbar has been a real challenge because several plugins do it and there is no way to coordinate the results, especially in a "responsive" way that adapts to changing browser window width.
Here are changes I have not been able to make:
- Change the sort order of the items in the attachments returned from the query and in the attachments browser window. The sort order is hard-coded in the script (or was the last time I checked).
- Change the information displayed in the attachments browser window. I've had very well-reasoned support requests for this, proposing more of a "list view" with something other than thumbnail images to identify items.
- Change the toolbar controls on the "Create Gallery" or "Set Featured Image" windows. Unlike the main "Add Media" window, toolbar controls for these windows are hard-coded.
I'm happy to help in any way I can and I look forward to the results of this important effort. Thanks for undertaking it!
#6
@
8 years ago
One pain point I think is worth bringing up from the Media Widgets project was the inability to write qunit tests for any of the functionality we were building around the Media Manager. Since the Media Manager is a pretty key piece to the flow in the Media Widgets, we had attempted to simulate the flow of selecting an image via the Media Modal and asserting model attributes in the widget and previews were rendered as expected.
Seems if a new API was built to interface with the Media Manager, we could have likely structured our code in such a way that we wouldn't have to write tests that deal with the media modal interactions. Additionally a new API itself would ideally be written with its own test coverage.
This ticket was mentioned in Slack in #core by timmyc. View the logs.
8 years ago
#8
@
4 years ago
Seconding this idea. If this is WordPress, the interface needs to be well documented, extensible and customizable.
As I see it there are three major dysfunctional aspects of Media Manager.
- Lack of documentation
- Lack of extensibility
- Dependency on an obscure, nearly-undocumented framework (backbone.js)
Although I'm no Gutenberg fan, and prefer Svelte, it seems like MM could be rebuilt in React and use similar code patterns, so developers would have a single framework to become proficient in. Unit tests could probably parallel some of the testing code for Gutenberg.
I'll comment here as well with some learnings from working with the media manager JS for the media widgets. We had to extend the media modal JS a few times to get it to behave the way we needed. I'll list out the reasons for extending here and perhaps they indicate areas where more configuration (
options
) are needed when invoking the media modal, or perhaps changes to the default behavior.wp.media()
to pass in the desiredLibrary
instead of having a fixed set in that largeif
/else
statement. (ref)options
. refSome of these already have tickets, while others should get their own tickets.