PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 13.7.2
Jetpack – WP Security, Backup, Speed, & Growth v13.7.2
12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 14.5.1 14.6.1 14.7.1 14.8.1 14.9.2 15.0.3 15.1.2 15.2.1 15.3.2 15.4.1 15.5.1 15.6.1 15.7.2 15.8.1 15.9.2 16.0.2 16.1.3 16.2-a.5 16.2-a.3 16.1.2 16.2-a.1 16.1.1 16.1 16.1-beta 16.1-beta.2 16.1-beta.3 16.1-a.5 16.1-a.3 16.0.1 16.1-a.1 16.0 16.0-beta 16.0-a.7 16.0-a.5 15.9.1 16.0-a.3 16.0-a.1 15.9 15.9-beta 15.9-a.7 15.9-a.5 15.9-a.3 15.9-a.1 15.8 15.8-beta 15.8-a.7 15.8-a.5 5.2.5 5.3.4 5.4.4 5.5.5 5.6.5 5.7.5 5.8.4 5.9.4 6.0.4 6.1 6.1.1 6.1.2 6.1.3 6.1.4 6.1.5 6.2 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.3 6.3.1 6.3.2 6.3.3 6.3.4 6.3.5 6.3.6 6.3.7 6.4 6.4.1 6.4.2 6.4.3 6.4.4 6.4.5 6.4.6 6.5 6.5.1 6.5.2 6.5.3 6.5.4 6.6 6.6.1 6.6.2 6.6.3 6.6.4 6.6.5 6.7 6.7.1 6.7.2 6.7.3 6.7.4 6.8 6.8.1 6.8.2 6.8.3 6.8.4 6.8.5 6.9 6.9.1 6.9.2 6.9.3 6.9.4 7.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2 7.2.1 7.2.1.1 7.2.2 7.2.3 7.2.4 7.2.5 7.3 7.3.0.1 7.3.1 7.3.1.1 7.3.2 7.3.3 7.3.4 7.3.5 7.4 7.4.1 7.4.2 7.4.3 7.4.4 7.4.5 7.5 7.5.0.1 7.5.1 7.5.2 7.5.3 7.5.4 7.5.5 7.5.6 7.5.7 7.6 7.6.1 7.6.2 7.6.3 7.6.4 7.7 7.7.1 7.7.2 7.7.3 7.7.4 7.7.5 7.7.6 7.8 7.8.1 7.8.2 7.8.3 7.8.4 7.9 7.9.1 7.9.2 7.9.3 7.9.4 8.0 8.0.1 8.0.2 8.0.3 8.1 8.1.1 8.1.2 8.1.3 8.1.4 8.2 8.2.0.1 8.2.1 8.2.2 8.2.3 8.2.4 8.2.5 8.2.6 8.3 8.3.1 8.3.2 8.3.3 8.4 8.4.1 8.4.2 8.4.3 8.4.4 8.4.5 8.5 8.5.1 8.5.2 8.5.3 8.6 8.6.1 8.6.2 8.6.3 8.6.4 8.7 8.7.0.1 8.7.1 8.7.2 8.7.3 8.7.4 8.8 8.8.1 8.8.2 8.8.3 8.8.4 8.8.5 8.9 8.9.1 8.9.2 8.9.3 8.9.4 9.0 9.0.1 9.0.2 9.0.3 9.0.4 9.0.5 9.1 9.1.1 9.1.2 9.1.3 9.2 9.2.1 9.2.2 9.2.3 9.2.4 9.3 9.3.1 9.3.2 9.3.3 9.3.4 9.3.5 9.4 9.4.1 9.4.2 9.4.3 9.4.4 9.5 9.5.1 9.5.2 9.5.3 9.5.4 9.5.5 9.6 9.6.1 9.6.2 9.6.3 9.6.4 9.7 9.7.1 9.7.2 15.7-beta.2 9.7.3 15.7.1 9.8 15.8-a.1 9.8.1 15.8-a.3 9.8.2 2.0.9 9.8.3 2.1.7 9.9 2.2.10 9.9.1 2.3.10 9.9.2 2.4.7 9.9.3 2.5.5 2.6.6 2.7.5 2.8.5 2.9.6 3.0.6 3.1.5 3.2.5 3.3.6 3.4.6 3.5.6 3.6.4 3.7.5 3.8.5 3.9.10 4.0.7 4.1.4 4.2.5 4.3.5 4.4.5 4.5.3 4.6.3 4.7.4 4.8.5 4.9.3 5.0.3 5.1.4 trunk 10.0 10.0.1 10.0.2 10.1 10.1.1 10.1.2 10.2 10.2.1 10.2.2 10.2.3 10.3 10.3.1 10.3.2 10.4 10.4.1 10.4.2 10.5 10.5.1 10.5.2 10.5.3 10.6 10.6.1 10.6.2 10.7 10.7.1 10.7.2 10.8 10.8.1 10.8.2 10.9 10.9.1 10.9.2 10.9.3 11.0 11.0.1 11.0.2 11.1 11.1.1 11.1.2 11.1.3 11.1.4 11.2 11.2.1 11.2.2 11.3 11.3.1 11.3.2 11.3.3 11.3.4 11.4 11.4.1 11.4.2 11.5 11.5.1 11.5.2 11.5.3 11.6 11.6.1 11.6.2 11.7 11.7.1 11.7.2 11.7.3 11.8 11.8.3 11.8.4 11.8.5 11.8.6 11.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / modules / widgets / gallery.php
jetpack / modules / widgets Last commit date
authors 8 years ago contact-info 5 years ago eu-cookie-law 2 years ago facebook-likebox 11 years ago flickr 2 years ago gallery 2 years ago goodreads 2 years ago google-translate 4 years ago image-widget 8 years ago instagram 6 years ago internet-defense-league 2 years ago migrate-to-core 3 years ago milestone 2 years ago my-community 8 years ago simple-payments 2 years ago social-icons 4 years ago social-media-icons 5 years ago top-posts 8 years ago wordpress-post-widget 2 years ago authors.php 3 years ago blog-stats.php 2 years ago class-jetpack-eu-cookie-law-widget.php 2 years ago class-jetpack-instagram-widget.php 2 years ago contact-info.php 2 years ago customizer-controls.css 9 years ago customizer-utils.js 6 years ago facebook-likebox.php 2 years ago flickr.php 2 years ago gallery.php 2 years ago goodreads.php 2 years ago google-translate.php 2 years ago gravatar-profile.css 10 years ago gravatar-profile.php 2 years ago image-widget.php 3 years ago internet-defense-league.php 3 years ago mailchimp.php 3 years ago milestone.php 5 years ago my-community.php 2 years ago rsslinks-widget.php 3 years ago simple-payments.php 2 years ago social-icons.php 2 years ago social-media-icons.php 2 years ago top-posts.php 2 years ago twitter-timeline-admin.js 6 years ago twitter-timeline.php 3 years ago upcoming-events.php 2 years ago wordpress-post-widget.php 4 years ago
gallery.php
523 lines
1 <?php // phpcs:ignore eWordPress.Files.FileName.InvalidClassFileName
2 /**
3 * Module Name: Gallery widget
4 *
5 * @package automattic/jetpack
6 */
7
8 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
9
10 use Automattic\Jetpack\Assets;
11 use Automattic\Jetpack\Image_CDN\Image_CDN_Core;
12
13 /**
14 * Jetpack_Gallery_Widget main class.
15 */
16 class Jetpack_Gallery_Widget extends WP_Widget {
17 const THUMB_SIZE = 45;
18 const DEFAULT_WIDTH = 265;
19
20 /**
21 * The width of the gallery widget.
22 * May be customized by the 'gallery_widget_content_width' filter.
23 *
24 * @var int
25 */
26 protected $instance_width;
27
28 /**
29 * Jetpack_Gallery_Widget constructor.
30 */
31 public function __construct() {
32 $widget_ops = array(
33 'classname' => 'widget-gallery',
34 'description' => __( 'Display a photo gallery or slideshow', 'jetpack' ),
35 'customize_selective_refresh' => true,
36 );
37
38 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
39
40 parent::__construct(
41 'gallery',
42 /** This filter is documented in modules/widgets/facebook-likebox.php */
43 apply_filters( 'jetpack_widget_name', __( 'Gallery', 'jetpack' ) ),
44 $widget_ops
45 );
46
47 if ( is_customize_preview() ) {
48 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend_scripts' ) );
49
50 if ( class_exists( 'Jetpack_Tiled_Gallery' ) ) {
51 add_action( 'wp_enqueue_scripts', array( 'Jetpack_Tiled_Gallery', 'default_scripts_and_styles' ) );
52 }
53
54 if ( class_exists( 'Jetpack_Slideshow_Shortcode' ) ) {
55 $slideshow = new Jetpack_Slideshow_Shortcode();
56 add_action( 'wp_enqueue_scripts', array( $slideshow, 'enqueue_scripts' ) );
57 }
58
59 if ( class_exists( 'Jetpack_Carousel' ) ) {
60 $carousel = new Jetpack_Carousel();
61 add_action( 'wp_enqueue_scripts', array( $carousel, 'enqueue_assets' ) );
62 }
63 }
64 }
65
66 /**
67 * Display the widget.
68 *
69 * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
70 * @param array $instance The settings for the particular instance of the widget.
71 */
72 public function widget( $args, $instance ) {
73 $instance = wp_parse_args( (array) $instance, $this->defaults() );
74
75 $this->enqueue_frontend_scripts();
76
77 $before_widget = isset( $args['before_widget'] ) ? $args['before_widget'] : '';
78 $before_title = isset( $args['before_title'] ) ? $args['before_title'] : '';
79 $after_title = isset( $args['after_title'] ) ? $args['after_title'] : '';
80 $after_widget = isset( $args['after_widget'] ) ? $args['after_widget'] : '';
81
82 $instance['attachments'] = $this->get_attachments( $instance );
83
84 $classes = array();
85
86 $classes[] = 'widget-gallery-' . $instance['type'];
87
88 /*
89 * Due to a bug in the carousel plugin,
90 * carousels will be triggered for all tiled galleries that exist on a page with other tiled galleries,
91 * regardless of whether or not the widget was set to Carousel mode.
92 * The onClick selector is simply too broad, since it was not written with widgets in mind.
93 * This special class prevents that behavior, via an override handler in gallery.js.
94 */
95 if ( 'carousel' !== $instance['link'] && 'slideshow' !== $instance['type'] ) {
96 $classes[] = 'no-carousel';
97 } else {
98 $classes[] = 'carousel';
99 }
100
101 $classes = implode( ' ', $classes );
102
103 if ( 'carousel' === $instance['link'] ) {
104 require_once plugin_dir_path( realpath( __DIR__ . '/../carousel/jetpack-carousel.php' ) ) . 'jetpack-carousel.php';
105
106 if ( class_exists( 'Jetpack_Carousel' ) ) {
107 // Create new carousel so we can use the enqueue_assets() method. Not ideal, but there is a decent amount
108 // of logic in that method that shouldn't be duplicated.
109 $carousel = new Jetpack_Carousel();
110
111 // First parameter is $output, which comes from filters, and causes bypass of the asset enqueuing. Passing null is correct.
112 $carousel->enqueue_assets( null );
113 }
114 }
115
116 echo $before_widget . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
117
118 /** This filter is documented in core/src/wp-includes/default-widgets.php */
119 $title = apply_filters( 'widget_title', $instance['title'] );
120
121 if ( $title ) {
122 echo $before_title . $title . $after_title . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
123 }
124
125 echo '<div class="' . esc_attr( $classes ) . '">' . "\n";
126
127 $method = $instance['type'] . '_widget';
128
129 /**
130 * Allow the width of a gallery to be altered by themes or other code.
131 *
132 * @module widgets
133 *
134 * @since 2.5.0
135 *
136 * @param int self::DEFAULT_WIDTH Default gallery width. Default is 265.
137 * @param string $args Display arguments including before_title, after_title, before_widget, and after_widget.
138 * @param array $instance The settings for the particular instance of the widget.
139 */
140 $this->instance_width = apply_filters( 'gallery_widget_content_width', self::DEFAULT_WIDTH, $args, $instance );
141
142 // Register a filter to modify the tiled_gallery_content_width, so Jetpack_Tiled_Gallery
143 // can appropriately size the tiles.
144 add_filter( 'tiled_gallery_content_width', array( $this, 'tiled_gallery_content_width' ) );
145
146 if ( method_exists( $this, $method ) ) {
147 echo $this->$method( $args, $instance ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
148 }
149
150 // Remove the stored $instance_width, as it is no longer needed.
151 $this->instance_width = null;
152
153 // Remove the filter, so any Jetpack_Tiled_Gallery in a post is not affected.
154 remove_filter( 'tiled_gallery_content_width', array( $this, 'tiled_gallery_content_width' ) );
155
156 echo "\n" . '</div>'; // .widget-gallery-$type
157
158 echo "\n" . $after_widget; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
159
160 /** This action is documented in modules/widgets/gravatar-profile.php */
161 do_action( 'jetpack_stats_extra', 'widget_view', 'gallery' );
162 }
163
164 /**
165 * Fetch the images attached to the gallery Widget
166 *
167 * @param array $instance The Widget instance for which you'd like attachments.
168 * @return array Array of attachment objects for the Widget in $instance
169 */
170 public function get_attachments( $instance ) {
171 $ids = explode( ',', $instance['ids'] );
172
173 if ( isset( $instance['random'] ) && 'on' === $instance['random'] ) {
174 shuffle( $ids );
175 }
176
177 $attachments_query = new WP_Query(
178 array(
179 'post__in' => $ids,
180 'post_status' => 'inherit',
181 'post_type' => 'attachment',
182 'post_mime_type' => 'image',
183 'posts_per_page' => -1,
184 'orderby' => 'post__in',
185 )
186 );
187
188 $attachments = $attachments_query->get_posts();
189
190 wp_reset_postdata();
191
192 return $attachments;
193 }
194
195 /**
196 * Generate HTML for a rectangular, tiled Widget
197 *
198 * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
199 * @param array $instance The Widget instance to generate HTML for.
200 * @return string String of HTML representing a rectangular gallery
201 */
202 public function rectangular_widget( $args, $instance ) {
203 if ( ! class_exists( 'Jetpack_Tiled_Gallery' )
204 && ! class_exists( 'Jetpack_Tiled_Gallery_Layout_Rectangular' ) ) {
205 return;
206 }
207
208 Jetpack_Tiled_Gallery::default_scripts_and_styles();
209
210 $layout = new Jetpack_Tiled_Gallery_Layout_Rectangular( $instance['attachments'], $instance['link'], false, 3 );
211 return $layout->HTML();
212 }
213
214 /**
215 * Generate HTML for a square (grid style) Widget
216 *
217 * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
218 * @param array $instance The Widget instance to generate HTML for.
219 * @return string String of HTML representing a square gallery
220 */
221 public function square_widget( $args, $instance ) {
222 if ( ! class_exists( 'Jetpack_Tiled_Gallery' )
223 && ! class_exists( 'Jetpack_Tiled_Gallery_Layout_Square' ) ) {
224 return;
225 }
226
227 Jetpack_Tiled_Gallery::default_scripts_and_styles();
228
229 $layout = new Jetpack_Tiled_Gallery_Layout_Square( $instance['attachments'], $instance['link'], false, 3 );
230 return $layout->HTML();
231 }
232
233 /**
234 * Generate HTML for a circular (grid style) Widget
235 *
236 * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
237 * @param array $instance The Widget instance to generate HTML for.
238 * @return string String of HTML representing a circular gallery
239 */
240 public function circle_widget( $args, $instance ) {
241 if ( ! class_exists( 'Jetpack_Tiled_Gallery' )
242 && ! class_exists( 'Jetpack_Tiled_Gallery_Layout_Circle' ) ) {
243 return;
244 }
245
246 Jetpack_Tiled_Gallery::default_scripts_and_styles();
247
248 $layout = new Jetpack_Tiled_Gallery_Layout_Circle( $instance['attachments'], $instance['link'], false, 3 );
249 return $layout->HTML();
250 }
251
252 /**
253 * Generate HTML for a slideshow Widget
254 *
255 * @todo Is slideshow_widget() still used?
256 *
257 * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
258 * @param array $instance The Widget instance to generate HTML for.
259 * @return string String of HTML representing a slideshow gallery
260 */
261 public function slideshow_widget( $args, $instance ) {
262 global $content_width;
263
264 require_once plugin_dir_path( realpath( __DIR__ . '/../shortcodes/slideshow.php' ) ) . 'slideshow.php';
265
266 if ( ! class_exists( 'Jetpack_Slideshow_Shortcode' ) ) {
267 return;
268 }
269
270 if ( count( $instance['attachments'] ) < 1 ) {
271 return;
272 }
273
274 $slideshow = new Jetpack_Slideshow_Shortcode();
275
276 $slideshow->enqueue_scripts();
277
278 $gallery_instance = 'widget-' . $args['widget_id'];
279
280 $gallery = array();
281
282 foreach ( $instance['attachments'] as $attachment ) {
283 $attachment_image_src = wp_get_attachment_image_src( $attachment->ID, 'full' );
284 $attachment_image_src = Image_CDN_Core::cdn_url( $attachment_image_src[0], array( 'w' => $this->instance_width ) ); /** [url, width, height] */
285
286 $caption = wptexturize( wp_strip_all_tags( $attachment->post_excerpt ) );
287
288 $gallery[] = (object) array(
289 'src' => (string) esc_url_raw( $attachment_image_src ),
290 'id' => (string) $attachment->ID,
291 'caption' => (string) $caption,
292 );
293 }
294
295 $max_width = (int) get_option( 'large_size_w' );
296 $max_height = 175;
297
298 if ( (int) $content_width > 0 ) {
299 $max_width = min( (int) $content_width, $max_width );
300 }
301
302 $color = Jetpack_Options::get_option( 'slideshow_background_color', 'black' );
303 $js_attr = array(
304 'gallery' => $gallery,
305 'selector' => $gallery_instance,
306 'width' => $max_width,
307 'height' => $max_height,
308 'trans' => 'fade',
309 'color' => $color,
310 'autostart' => true,
311 );
312
313 $html = $slideshow->slideshow_js( $js_attr );
314
315 return $html;
316 }
317
318 /**
319 * Used to adjust the content width of Jetpack_Tiled_Gallery's in sidebars
320 *
321 * $this->instance_width is filtered in widget() and this filter is added then removed in widget()
322 *
323 * @return int The filtered width
324 */
325 public function tiled_gallery_content_width() {
326 return $this->instance_width;
327 }
328
329 /**
330 * Outputs the widget settings form.
331 *
332 * @html-template-var array $instance
333 * @html-template-var array<string,array<string|int,string|int>> $allowed_values
334 *
335 * @param array $instance Current settings.
336 */
337 public function form( $instance ) {
338 $defaults = $this->defaults();
339 $allowed_values = $this->allowed_values(); // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Used in included form template.
340
341 $instance = wp_parse_args( (array) $instance, $defaults );
342
343 include __DIR__ . '/gallery/templates/form.php';
344 }
345
346 /**
347 * Save the widget options.
348 *
349 * @param array $new_instance The new instance options.
350 * @param array $old_instance The old instance options.
351 * @return array The saved options.
352 */
353 public function update( $new_instance, $old_instance ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
354 $instance = $this->sanitize( $new_instance );
355
356 return $instance;
357 }
358
359 /**
360 * Sanitize the $instance's values to the set of allowed values. If a value is not acceptable,
361 * it is set to its default.
362 *
363 * Helps keep things nice and secure by listing only allowed values.
364 *
365 * @param array $instance The Widget instance to sanitize values for.
366 * @return array $instance The Widget instance with values sanitized
367 */
368 public function sanitize( $instance ) {
369 $allowed_values = $this->allowed_values();
370 $defaults = $this->defaults();
371
372 foreach ( $instance as $key => $value ) {
373 if ( ! is_scalar( $value ) ) {
374 // $instance may hold an Array value type for the Jetpack widget visibility feature.
375 continue;
376 }
377
378 $value = trim( $value );
379
380 if ( isset( $allowed_values[ $key ] ) && $allowed_values[ $key ] && ! array_key_exists( $value, $allowed_values[ $key ] ) ) {
381 $instance[ $key ] = $defaults[ $key ];
382 } else {
383 $instance[ $key ] = sanitize_text_field( $value );
384 }
385 }
386
387 return $instance;
388 }
389
390 /**
391 * Return a multi-dimensional array of allowed values (and their labels) for all widget form
392 * elements
393 *
394 * To allow all values on an input, omit it from the returned array
395 *
396 * @return array Array of allowed values for each option
397 */
398 public function allowed_values() {
399 $max_columns = 5;
400
401 // Create an associative array of allowed column values. This just automates the generation of
402 // column <option>s, from 1 to $max_columns.
403 $allowed_columns = array_combine( range( 1, $max_columns ), range( 1, $max_columns ) );
404
405 return array(
406 'type' => array(
407 'rectangular' => __( 'Tiles', 'jetpack' ),
408 'square' => __( 'Square Tiles', 'jetpack' ),
409 'circle' => __( 'Circles', 'jetpack' ),
410 'slideshow' => __( 'Slideshow', 'jetpack' ),
411 ),
412 'columns' => $allowed_columns,
413 'link' => array(
414 'carousel' => __( 'Carousel', 'jetpack' ),
415 'post' => __( 'Attachment Page', 'jetpack' ),
416 'file' => __( 'Media File', 'jetpack' ),
417 ),
418 );
419 }
420
421 /**
422 * Return an associative array of default values
423 *
424 * These values are used in new widgets as well as when sanitizing input. If a given value is not allowed,
425 * as defined in allowed_values(), that input is set to the default value defined here.
426 *
427 * @return array Array of default values for the Widget's options
428 */
429 public function defaults() {
430 return array(
431 'title' => '',
432 'type' => 'rectangular',
433 'ids' => '',
434 'columns' => 3,
435 'link' => 'carousel',
436 );
437 }
438
439 /**
440 * Enqueue frontend scripts.
441 */
442 public function enqueue_frontend_scripts() {
443 wp_register_script(
444 'gallery-widget',
445 Assets::get_file_url_for_environment(
446 '_inc/build/widgets/gallery/js/gallery.min.js',
447 'modules/widgets/gallery/js/gallery.js'
448 ),
449 array( 'jquery' ),
450 JETPACK__VERSION,
451 false
452 );
453
454 wp_enqueue_script( 'gallery-widget' );
455 }
456
457 /**
458 * Enqueue admin scripts and styles.
459 */
460 public function enqueue_admin_scripts() {
461 global $pagenow;
462
463 if ( 'widgets.php' === $pagenow || 'customize.php' === $pagenow ) {
464 wp_enqueue_media();
465
466 wp_enqueue_script(
467 'gallery-widget-admin',
468 Assets::get_file_url_for_environment(
469 '_inc/build/widgets/gallery/js/admin.min.js',
470 'modules/widgets/gallery/js/admin.js'
471 ),
472 array(
473 'jquery',
474 'media-models',
475 'media-views',
476 ),
477 '20150501',
478 false
479 );
480
481 $js_settings = array(
482 'thumbSize' => self::THUMB_SIZE,
483 );
484
485 wp_localize_script( 'gallery-widget-admin', '_wpGalleryWidgetAdminSettings', $js_settings );
486 wp_enqueue_style(
487 'gallery-widget-admin',
488 plugins_url( '/gallery/css/admin.css', __FILE__ ),
489 array(),
490 JETPACK__VERSION
491 );
492 wp_style_add_data( 'gallery-widget-admin', 'rtl', 'replace' );
493 }
494 }
495 }
496
497 add_action( 'widgets_init', 'jetpack_gallery_widget_init' );
498
499 /**
500 * Jetpack Gallery widget init; the widget is conditionally registered.
501 */
502 function jetpack_gallery_widget_init() {
503 /**
504 * Allow the Gallery Widget to be enabled even when Core supports the Media Gallery Widget
505 *
506 * @module widgets
507 *
508 * @since 5.5.0
509 *
510 * @param bool false Whether to force-enable the gallery widget
511 */
512 if (
513 ! apply_filters( 'jetpack_force_enable_gallery_widget', false )
514 && class_exists( 'WP_Widget_Media_Gallery' )
515 && Jetpack_Options::get_option( 'gallery_widget_migration' )
516 ) {
517 return;
518 }
519 if ( ! method_exists( 'Jetpack', 'is_module_active' ) || Jetpack::is_module_active( 'tiled-gallery' ) ) {
520 register_widget( 'Jetpack_Gallery_Widget' );
521 }
522 }
523