| @@ -1,9 +1,5 @@ | ||
| 1 | 1 | <?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | - | |
| 3 | -use Automattic\Jetpack\Assets; | |
| 4 | -use Automattic\Jetpack\Extensions\Slideshow; | |
| 5 | - | |
| 6 | 2 | /** |
| 7 | 3 | * Slideshow shortcode. |
| 8 | 4 | * Adds a new "slideshow" gallery type when adding a gallery using the classic editor. |
| 9 | 5 | * |
| @@ -9,10 +5,19 @@ | ||
| 9 | 5 | * |
| 10 | 6 | * @package automattic/jetpack |
| 11 | 7 | */ |
| 12 | 8 | |
| 9 | +use Automattic\Jetpack\Assets; | |
| 10 | +use Automattic\Jetpack\Extensions\Slideshow; | |
| 11 | + | |
| 12 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 13 | + exit( 0 ); | |
| 14 | +} | |
| 15 | + | |
| 13 | 16 | /** |
| 14 | 17 | * Slideshow shortcode usage: [gallery type="slideshow"] or the older [slideshow] |
| 18 | + * | |
| 19 | + * @phan-constructor-used-for-side-effects | |
| 15 | 20 | */ |
| 16 | 21 | class Jetpack_Slideshow_Shortcode { |
| 17 | 22 | /** |
| 18 | 23 | * Number of slideshows on a page. |
| @@ -138,9 +143,9 @@ | ||
| 138 | 143 | |
| 139 | 144 | $gallery = array(); |
| 140 | 145 | foreach ( $attachments as $attachment ) { |
| 141 | 146 | $attachment_image_src = wp_get_attachment_image_src( $attachment->ID, $attr['size'] ); |
| 142 | - $attachment_image_src = $attachment_image_src[0]; // [url, width, height]. | |
| 147 | + $attachment_image_src = false !== $attachment_image_src ? $attachment_image_src[0] : ''; // [url, width, height]. | |
| 143 | 148 | $attachment_image_title = get_the_title( $attachment->ID ); |
| 144 | 149 | $attachment_image_alt = get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ); |
| 145 | 150 | /** |
| 146 | 151 | * Filters the Slideshow slide caption. |
| @@ -200,11 +205,13 @@ | ||
| 200 | 205 | |
| 201 | 206 | /* |
| 202 | 207 | * Blocks can be disabled in Jetpack Settings. |
| 203 | 208 | * If that's the case, we need to include the slideshow block manually. |
| 209 | + * render_amp() lives in the block's render.php, which is loaded lazily, | |
| 210 | + * so make sure it is available before calling it. | |
| 204 | 211 | */ |
| 205 | - if ( ! class_exists( 'Automattic\Jetpack\Extensions\Slideshow' ) ) { | |
| 206 | - require_once JETPACK__PLUGIN_DIR . 'extensions/blocks/slideshow/slideshow.php'; | |
| 212 | + if ( ! function_exists( 'Automattic\Jetpack\Extensions\Slideshow\render_amp' ) ) { | |
| 213 | + require_once JETPACK__PLUGIN_DIR . 'extensions/blocks/slideshow/render.php'; | |
| 207 | 214 | } |
| 208 | 215 | |
| 209 | 216 | return Slideshow\render_amp( $amp_args ); |
| 210 | 217 | } |
| @@ -258,13 +265,20 @@ | ||
| 258 | 265 | * Actually enqueues the scripts and styles. |
| 259 | 266 | */ |
| 260 | 267 | public function enqueue_scripts() { |
| 261 | 268 | |
| 262 | - wp_enqueue_script( 'jquery-cycle', plugins_url( '/js/jquery.cycle.min.js', __FILE__ ), array( 'jquery' ), '20161231', true ); | |
| 269 | + wp_register_script( | |
| 270 | + 'jetpack-shortcode-deps', | |
| 271 | + plugins_url( '_inc/build/shortcodes/js/dependencies.min.js', JETPACK__PLUGIN_FILE ), | |
| 272 | + array( 'jquery' ), | |
| 273 | + '20250905', | |
| 274 | + true | |
| 275 | + ); | |
| 276 | + | |
| 263 | 277 | wp_enqueue_script( |
| 264 | 278 | 'jetpack-slideshow', |
| 265 | 279 | Assets::get_file_url_for_environment( '_inc/build/shortcodes/js/slideshow-shortcode.min.js', 'modules/shortcodes/js/slideshow-shortcode.js' ), |
| 266 | - array( 'jquery', 'jquery-cycle' ), | |
| 280 | + array( 'jquery', 'jetpack-shortcode-deps' ), | |
| 267 | 281 | '20160119.1', |
| 268 | 282 | true |
| 269 | 283 | ); |
| 270 | 284 | wp_enqueue_style( |
| @@ -274,8 +288,9 @@ | ||
| 274 | 288 | JETPACK__VERSION |
| 275 | 289 | ); |
| 276 | 290 | wp_style_add_data( 'jetpack-slideshow', 'rtl', 'replace' ); |
| 277 | 291 | |
| 292 | + require_once JETPACK__PLUGIN_DIR . '_inc/lib/class-jetpack-spinner.php'; | |
| 278 | 293 | wp_localize_script( |
| 279 | 294 | 'jetpack-slideshow', |
| 280 | 295 | 'jetpackSlideshowSettings', |
| 281 | 296 | /** |
| @@ -295,9 +310,9 @@ | ||
| 295 | 310 | */ |
| 296 | 311 | apply_filters( |
| 297 | 312 | 'jetpack_js_slideshow_settings', |
| 298 | 313 | array( |
| 299 | - 'spinner' => plugins_url( '/img/slideshow-loader.gif', __FILE__ ), | |
| 314 | + 'spinner' => 'data:image/svg+xml,' . rawurlencode( Jetpack_Spinner::render( 24 ) ), | |
| 300 | 315 | 'speed' => '4000', |
| 301 | 316 | 'label_prev' => __( 'Previous Slide', 'jetpack' ), |
| 302 | 317 | 'label_stop' => __( 'Pause Slideshow', 'jetpack' ), |
| 303 | 318 | 'label_next' => __( 'Next Slide', 'jetpack' ), |