From 43535fd4d1a7f80d4f7e3b3e3a03adc84bca289a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ce=CC=81dric=20Andrietti?= Date: Fri, 18 Sep 2026 11:34:12 +0200 Subject: [PATCH] feat(Theme): add base custom image sizes for Gutenberg support - Introduced new image sizes 'landscape' and 'landscape-2x' for use in Gutenberg. - Updated the text domain for translations to 'beapi-frontend-framework'. - Added a filter to display custom image sizes in the Gutenberg editor. --- inc/Services/Theme.php | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/inc/Services/Theme.php b/inc/Services/Theme.php index 996e9fdc..c7b02375 100644 --- a/inc/Services/Theme.php +++ b/inc/Services/Theme.php @@ -36,6 +36,12 @@ public function after_setup_theme(): void { */ $this->add_theme_supports(); $this->remove_theme_supports(); + $this->add_images_sizes(); + + /** + * Load images sizes in Gutenberg. + */ + add_filter( 'image_size_names_choose', [ $this, 'image_size_names_choose' ] ); /** * Load translations. @@ -71,6 +77,31 @@ private function remove_theme_supports(): void { */ private function i18n(): void { // Load theme texdomain - load_theme_textdomain( 'framework-textdomain', \get_theme_file_path( '/languages' ) ); + load_theme_textdomain( 'beapi-frontend-framework', \get_theme_file_path( '/languages' ) ); + } + + /** + * Add images sizes for Gutenberg + */ + private function add_images_sizes(): void { + add_image_size( 'landscape', 600, 400, true ); + add_image_size( 'landscape-2x', 1200, 800, true ); + } + + /** + * Display custom image sizes in Gutenberg + * If you use the WP-THUMB plugin, force to Generate this images (bypass the bea-wp-thumb mu-plugin to restart the generation) + * + * @param array $sizes + * + * @return array + */ + public function image_size_names_choose( array $sizes ): array { + return array_merge( + $sizes, + [ + 'landscape' => __( 'Landscape - 600 x 400', 'beapi-frontend-framework' ), + ] + ); } }