-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Use the image sizes names filter #11356
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
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.
I added the following filter:
function my_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
'full' => __('My Custom Full Size'),
) );
}
add_filter( 'image_size_names_choose', 'my_custom_sizes' );
And the full label was successfully changed. I think we need to switch id to slug on the editor defaults but besides that things look good to me 👍
| ], | ||
|
|
||
| availableImageSizes: [ | ||
| { id: 'thumbnail', label: __( 'Thumbnail' ) }, |
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 here we should use slug instead of id, otherwise const availableImageSizesBySlug = keyBy( availableImageSizes, 'slug' );is not going to work.
| $sizes[] = 'full'; | ||
| $size_names = apply_filters( | ||
| 'image_size_names_choose', | ||
| array( |
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.
We already have this array duplicated in many places of the WordPress codebase. When backporting this, it may make sense to check if we can use a constant or another approach to avoid this duplication.
|
Out of curiosity, do you have any idea how does it relate to the existing filter for the size of the featured image: const mediaSize = applyFilters( 'editor.PostFeaturedImage.imageSize', 'post-thumbnail', media.id, currentPostId ); |
ca05381 to
c57cc66
Compare
|
@gziolo It doesn't seem like the filter is directly related. Not that I like the idea of a filter, I think we should remove all frontend filters 🤷♂️ but it's addressing another use-case. |
closes #8219
Add a new editor config: "availableImageSizes" to be able to display the image sizes labels properly in the image block's inspector.
(Needs to be backported to Core once merged cc @pento)
Testing instructions