-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the image sizes names filter (#11356)
- Loading branch information
1 parent
cbbf22e
commit 8322628
Showing
3 changed files
with
67 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1325,6 +1325,35 @@ function gutenberg_load_locale_data() { | |
); | ||
} | ||
|
||
/** | ||
* Retrieve The available image sizes for a post | ||
* | ||
* @return array | ||
*/ | ||
function gutenberg_get_available_image_sizes() { | ||
$sizes = get_intermediate_image_sizes(); | ||
$sizes[] = 'full'; | ||
$size_names = apply_filters( | ||
'image_size_names_choose', | ||
array( | ||
'thumbnail' => __( 'Thumbnail', 'gutenberg' ), | ||
'medium' => __( 'Medium', 'gutenberg' ), | ||
'large' => __( 'Large', 'gutenberg' ), | ||
'full' => __( 'Full Size', 'gutenberg' ), | ||
) | ||
); | ||
|
||
$all_sizes = array(); | ||
foreach ( $sizes as $size_slug ) { | ||
$all_sizes[] = array( | ||
'slug' => $size_slug, | ||
'name' => isset( $size_names[ $size_slug ] ) ? $size_names[ $size_slug ] : $size_slug, | ||
This comment has been minimized.
Sorry, something went wrong. |
||
); | ||
} | ||
|
||
return $all_sizes; | ||
} | ||
|
||
/** | ||
* Scripts & Styles. | ||
* | ||
|
@@ -1602,6 +1631,7 @@ function gutenberg_editor_scripts_and_styles( $hook ) { | |
'maxUploadFileSize' => $max_upload_size, | ||
'allowedMimeTypes' => get_allowed_mime_types(), | ||
'styles' => $styles, | ||
'availableImageSizes' => gutenberg_get_available_image_sizes(), | ||
This comment has been minimized.
Sorry, something went wrong.
azaozz
Contributor
|
||
|
||
// Ideally, we'd remove this and rely on a REST API endpoint. | ||
'postLock' => $lock_details, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If I understand the issue, we want "labels" for selected sizes only, not for all sizes. Then we "filter" all available image sizes (from the image meta) in the client, and display only sizes that have a label.
So why do we output the slug when there is no label? The fact that a (translatable) label is missing means that the image size is "non-displayable". Adding the slug instead of a label stops this from working well?