-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Include all image sizes on the media upload object (if they exist) #7605
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
Conversation
dseidl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
works for me - thanks!
utils/mediaupload.js
Outdated
| id: savedMedia.id, | ||
| link: savedMedia.link, | ||
| url: savedMedia.source_url, | ||
| sizes: get( savedMedia, [ 'media_details', 'sizes' ], {} ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just leave the value undefined when sizes are not available? sizes: get( savedMedia, [ 'media_details', 'sizes' ] ). I think we don't need to return an empty object when sizes are not relevant.
This issue makes me question if mediaUpload should not just return the objects it receives from the server
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This issue makes me question if mediaUpload should not just return the objects it receives from the server
Yes, I'm curious whether there was a deliberate decision to limit the object size. My preference would be to return the entire object (particularly because different media types have different attributes)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My preference would be to return the entire object (particularly because different media types have different attributes)
Although, if we do this now, we change the shape of the data returned to the callback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option: create savedMedia.mediaDetails = {}, and the only include a sizes attribute for images with sizes. I think this is my preferred middle ground.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b9038b9 to
94412ab
Compare
utils/mediaupload.js
Outdated
| return createMediaFromFile( mediaFile, additionalData ).then( | ||
| ( savedMedia ) => { | ||
| const mediaObject = { | ||
| let mediaObject = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can still use const, we are not changing the mediaObject reference we are just changing a key in the object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can still use const, we are not changing the mediaObject reference we are just changing a key in the object.
This is bizarre and seems like a bug. Constant means constant, or unchanging. Reassignment, even to some subset of the data, isn't permitted in PHP.
I've made the change regardless 4f3acb7
jorgefilipecosta
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to work correctly thank you for iterating on this @danielbachhuber 👍
|
Correct me if I'm wrong but I can't see the utils folder anymore on current version 4.3, so this merge by @danielbachhuber is not there. Hope to get those custom image sizes back. Maybe I'm doing it wrong and I should get custom sizes with another object? |
|
Hello, is this solution available in latest release of Gutenberg? I am using Wordpress 5.0.3 (Gutenberg plugin is inacive), but media object which is returned via My MediaUpload component is pretty simple so far: Thanks, Ivan. |
|
@ihdk I noticed there are some code examples at #11356 (and in the issue linked there) which look related. Can you try checking those and if you find you still need help may I please ask that you post to what you have tried to https://wordpress.org/support/forum/wp-advanced/ or https://wordpress.stackexchange.com/ as a starting point for a help request and if you confirm there that some functionality is missing can you please open a feature request at https://github.com/WordPress/gutenberg/issues/new?template=Feature_request.md ? |
|
Hello, thanks for response. I found that use of |
|
@ihdk Can you clarify your solution? I'm seeing this issue on the |
|
In my case was missing only simple filter which define the readable name of my custom image size. Without this definition of name in filter
|
|
To leave some more direct code here for someone looking for this later. Also, the URL changed (but does redirect) From: https://developer.wordpress.org/reference/hooks/image_size_names_choose/ Code formatted like the following would go in your So after adding these, you would include the new names into WordPress admin. I was trying to set the custom sizes from a gutenberg return object, and my custom sizes were not available until I added this code. |
Fixes #7483