From 1806b1798db7eb8b9539e24cccea7bcefdf10e74 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Mon, 19 Aug 2024 14:59:14 +0200 Subject: [PATCH] Slideshows: don't attempt to use the block when not available (#38744) * Slideshows: don't attempt to use the block when not available Fixes #38742 * Load the slideshow block manually if needed. --- .../fix-slideshow-block-non-existing-shortcode | 4 ++++ .../jetpack/modules/shortcodes/slideshow.php | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 projects/plugins/jetpack/changelog/fix-slideshow-block-non-existing-shortcode diff --git a/projects/plugins/jetpack/changelog/fix-slideshow-block-non-existing-shortcode b/projects/plugins/jetpack/changelog/fix-slideshow-block-non-existing-shortcode new file mode 100644 index 0000000000000..db9a16b32e8cb --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-slideshow-block-non-existing-shortcode @@ -0,0 +1,4 @@ +Significance: patch +Type: compat + +AMP: avoid errors when using Jetpack's classic slideshows on a site where Jetpack blocks are disabled. diff --git a/projects/plugins/jetpack/modules/shortcodes/slideshow.php b/projects/plugins/jetpack/modules/shortcodes/slideshow.php index 6f4ac91e6f03b..81fffbb0a26cf 100644 --- a/projects/plugins/jetpack/modules/shortcodes/slideshow.php +++ b/projects/plugins/jetpack/modules/shortcodes/slideshow.php @@ -183,7 +183,10 @@ public function shortcode_callback( $attr ) { ); } - if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) { + if ( + class_exists( 'Jetpack_AMP_Support' ) + && Jetpack_AMP_Support::is_amp_request() + ) { // Load the styles and use the rendering method from the Slideshow block. Jetpack_Gutenberg::load_styles_as_required( 'slideshow' ); @@ -195,6 +198,14 @@ public function shortcode_callback( $attr ) { $amp_args['autoplay'] = true; } + /* + * Blocks can be disabled in Jetpack Settings. + * If that's the case, we need to include the slideshow block manually. + */ + if ( ! class_exists( 'Automattic\Jetpack\Extensions\Slideshow' ) ) { + require_once JETPACK__PLUGIN_DIR . 'extensions/blocks/slideshow/slideshow.php'; + } + return Slideshow\render_amp( $amp_args ); }