Skip to content

Commit

Permalink
Carousel: disable WordPress Core' Lightbox option (#36565)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jeherve authored Mar 28, 2024
1 parent 0dd9d79 commit 972ec82
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: compat

Carousel: disable WordPress' lightbox option when Jetpack's Carousel feature is activated.
29 changes: 29 additions & 0 deletions projects/plugins/jetpack/modules/carousel/jetpack-carousel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 972ec82

Please sign in to comment.