-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Media Modal (wp.media) hooks not working in some instances #9340
Comments
I came here with a same problem, I wanna refresh the modal content but I can't because wp.media.frame.content.get().collection doesn't exist, however, the wp.media.frame.content.get().controller has the collection but it doesn't refresh, I'm try to figure out how do it, the documentation that I found is here: https://atimmer.github.io/wordpress-jsdoc/index.html I hope it helps. |
I'm having an issue too. I know this is not a problem with my blocks, because the stack trace is from the WP js code. If I remove all blocks on the screen except this one, the modal works. At a completely unrelated block, now the modal won't open. This happens the moment I call "open" <MediaUpload
allowedTypes={['image']}
value={attributes[name]}
render={({ open }) => (
<Button isPrimary onClick={open}>
{label || 'Open Media Library'}
</Button>
)}
onSelect={media =>
console.log(media)
}
/> |
Using the classic editor, I am able to update the media library by resetting the props on the Collection as seen below. wp.media.frame.content.get().collection.props.set({ignore: (+ new Date())}); First please note that I am a beginner with JavaScript. I am wondering if you need to enqueue media as a dependency explicitly in the case of Gutenberg? I couldn't find anything directly related in the handbook, but I did noticed in the Create Meta Block doc it says
Since it mentions a few Past that, I also know there's an open issue showing that adding an image to the gallery via the "Upload an image" button below the block doesn't add it to the media modal and that there's an open PR pending for that at #9073 and I was thinking the #12367 might also be worth a look. If you're keen!, and digging around in those issues anyway, and if they help you, you might consider testing the branch for each and leaving a note saying whether they work for you. 😊 I know in #13441 they are looking for more reviewers, wanting to get more people involved, and reviewing those things will also work to make your own issue more visible (or even help you solve the problem along the way if the code you're reviewing does similar things to what you want! this is always a nice thing if it happens). |
Same for me, on WP 5.0.3. Originally, I was working on a script that uses : |
Hi @chibani , I've tried the all event. Is it true like that, or it's just in my local? |
@praditha Previously (pre-guteberg), the frame events where fired on every interaction with the featuredImage frame (open, close, upload, select the featured image, etc...). |
I've just re-tested this, and confirmed that this does appear to continue to be a bug; it does not appear possible to consistently access events on |
I haven't looked into it too deeply and there's a caveat that I'm no backbone expert, but it may be related to the way in which the block editor constructs and destroys the media frame as needed. The code is in this file: My guess is that the calls to It was noted on this trac ticket that the classic and block editor behave differently in the way they handle initializing, so that could also be affecting the hooks: |
The issue still remains in WP 5.8.3. EDIT: it seems to happen only when there's an empty image block (without selected image) in a saved post and you reload the page. When I add new empty image block, or if the image block has selected image, |
Looks to still be a bug in 6.3. I can confirm that the previous information posted by @carnilino still holds true: if you have an image from the library on the page the |
@talldan Hey any chance you know who owns this code? Thanks. |
@gziolo Hey any chance you know who, if anyone, owns this code/package? Thanks. Parson my @, just going off of who last committed to this package and after having a second look your commits might just automated. |
I have several plugins that hook into the Media Modal to accomplish things like pre-selecting an image on modal
open()
and resetting the media library collection after a dynamic image upload.Using the classic editor, I am able to update the media library by resetting the props on the Collection as seen below.
wp.media.frame.content.get().collection.props.set({ignore: (+ new Date())});
With Gutenberg, when attempting to hook into the wp.media Modal using the core Image Block,
wp.media.frame.content.get()
returns null.I realize get() and set() are Backbone methods so they may not work with the new object or schema of Gutenberg, but I am unable to find any documentation on what may have changed with the Media Modal window.
Expected behavior
It doesn't appear the Media Modal has changed with Gutenberg, so I would expect the methods to function as they did previously.
Desktop:
Additional context
The text was updated successfully, but these errors were encountered: