From 972ec8229a724e8f9ffc7e90945906759701587c Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Thu, 28 Mar 2024 15:16:37 +0100 Subject: [PATCH] Carousel: disable WordPress Core' Lightbox option (#36565) Fixes #32668 It's best to keep only one lightbox option, to avoid any confusion. Since Jetpack's Carousel feature currently offers more features, let's keep ours in favor of Core's for now. In the future, when core's lightbox option becomes more robust, we can consider deprecating Jetpack's Carousel feature altogether. --- .../changelog/fix-carousel-lightbox-disable | 4 +++ .../modules/carousel/jetpack-carousel.php | 29 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 projects/plugins/jetpack/changelog/fix-carousel-lightbox-disable diff --git a/projects/plugins/jetpack/changelog/fix-carousel-lightbox-disable b/projects/plugins/jetpack/changelog/fix-carousel-lightbox-disable new file mode 100644 index 0000000000000..c874fe587656a --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-carousel-lightbox-disable @@ -0,0 +1,4 @@ +Significance: patch +Type: compat + +Carousel: disable WordPress' lightbox option when Jetpack's Carousel feature is activated. diff --git a/projects/plugins/jetpack/modules/carousel/jetpack-carousel.php b/projects/plugins/jetpack/modules/carousel/jetpack-carousel.php index b486d3e99f19b..cac86b3a6d466 100644 --- a/projects/plugins/jetpack/modules/carousel/jetpack-carousel.php +++ b/projects/plugins/jetpack/modules/carousel/jetpack-carousel.php @@ -83,6 +83,9 @@ public function init() { $this->single_image_gallery_enabled = ! $this->maybe_disable_jp_carousel_single_images(); $this->single_image_gallery_enabled_media_file = $this->maybe_enable_jp_carousel_single_images_media_file(); + // Disable core lightbox when Carousel is enabled. + add_action( 'wp_theme_json_data_theme', array( $this, 'disable_core_lightbox' ) ); + if ( is_admin() ) { // Register the Carousel-related related settings. add_action( 'admin_init', array( $this, 'register_settings' ), 5 ); @@ -206,6 +209,32 @@ public function maybe_enable_jp_carousel_single_images_media_file() { return apply_filters( 'jp_carousel_load_for_images_linked_to_file', false ); } + /** + * Disable the "Lightbox" option offered in WordPress core + * whenever Jetpack's Carousel feature is enabled. + * + * @since $$next-version$$ + * + * @param WP_Theme_JSON_Data $theme_json Class to access and update theme.json data. + */ + public function disable_core_lightbox( $theme_json ) { + return $theme_json->update_with( + array( + 'version' => 2, + 'settings' => array( + 'blocks' => array( + 'core/image' => array( + 'lightbox' => array( + 'allowEditing' => false, + 'enabled' => false, + ), + ), + ), + ), + ) + ); + } + /** * Returns the value of the applied jp_carousel_asset_version filter *