PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / 3.11.2
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization v3.11.2
4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 2.5.5 2.5.6 2.5.7 3.0.0 3.0.1 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.11.0 3.11.1 3.11.2 3.11.3 3.12.0 3.12.1 All 134 releases
optimole-wp / inc / dam.php

dam.php in Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization 3.11.2, at inc/dam.php

821 lines 20.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Dam class.
4 *
5 * Author: Andrei Baicus <andrei@themeisle.com>
6 * Created on: 04/07/2023
7 *
8 * @package \Optimole\Inc
9 * @author Optimole <friends@optimole.com>
10 */
11
12 /**
13 * Class Optml_Dam
14 */
15 class Optml_Dam {
16 use Optml_Dam_Offload_Utils;
17 use Optml_Normalizer;
18
19 /**
20 * Hold the settings object.
21 *
22 * @var Optml_Settings Settings object.
23 */
24 private $settings;
25
26 /**
27 * The dam endpoint.
28 *
29 * @var string
30 */
31 private $dam_endpoint = 'https://dashboard.optimole.com/dam';
32
33 const OM_DAM_IMPORTED_FLAG = 'om-dam-imported';
34 const URL_DAM_FLAG = '/dam:1';
35 const IS_EDIT_FLAG = 'om-dam-edit';
36
37 /**
38 * Optml_Dam constructor.
39 */
40 public function __construct() {
41 $this->settings = Optml_Main::instance()->admin->settings;
42
43 if ( ! $this->settings->is_connected() ) {
44 return;
45 }
46
47 if ( $this->settings->get( 'cloud_images' ) === 'enabled' ) {
48 add_action( 'admin_menu', [ $this, 'add_menu' ] );
49 add_action( 'print_media_templates', [ $this, 'print_media_template' ] );
50 add_action( 'wp_enqueue_media', [ $this, 'enqueue_media_scripts' ] );
51 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_page_scripts' ] );
52 }
53
54 if ( defined( 'OPTML_DAM_ENDPOINT' ) && constant( 'OPTML_DAM_ENDPOINT' ) ) {
55 $this->dam_endpoint = constant( 'OPTML_DAM_ENDPOINT' );
56 }
57
58 add_filter( 'wp_get_attachment_image_src', [ $this, 'alter_attachment_image_src' ], 10, 4 );
59 add_filter( 'wp_get_attachment_metadata', [ $this, 'alter_attachment_metadata' ], 10, 2 );
60 add_filter( 'image_downsize', [ $this, 'catch_downsize' ], 10, 3 );
61 add_filter( 'wp_prepare_attachment_for_js', [$this, 'alter_attachment_for_js'], 10, 3 );
62 add_filter( 'wp_image_src_get_dimensions', [$this, 'alter_img_tag_w_h'], 10, 4 );
63 add_filter( 'get_attached_file', [$this, 'alter_attached_file_response'], 10, 2 );
64 add_filter( 'wp_calculate_image_srcset', [$this, 'disable_dam_images_srcset'], 1, 5 );
65
66 add_filter(
67 'elementor/image_size/get_attachment_image_html',
68 [
69 $this,
70 'alter_elementor_image_size',
71 ],
72 10,
73 4
74 );
75 }
76
77 /**
78 * Catch image downsize for the DAM imported images.
79 *
80 * @param array $image {
81 * Array of image data.
82 *
83 * @type string $0 Image source URL.
84 * @type int $1 Image width in pixels.
85 * @type int $2 Image height in pixels.
86 * @type bool $3 Whether the image is a resized image.
87 *
88 * @param int $id attachment id.
89 * @param string|int[] $size image size.
90 *
91 * @return array $image.
92 */
93 public function catch_downsize( $image, $id, $size ) {
94 return $this->alter_attachment_image_src( $image, $id, $size, false );
95 }
96
97 /**
98 * Insert attachments.
99 *
100 * @param array $images Images array.
101 *
102 * @return array
103 */
104 public function insert_attachments( $images ) {
105 $ids = [];
106
107 $existing = $this->check_existing_attachments( $images );
108
109 foreach ( $images as $image ) {
110 if ( ! isset( $image['isEdit'] ) && array_key_exists( $image['meta']['resourceS3'], $existing ) ) {
111 $ids[] = $existing[ $image['meta']['resourceS3'] ];
112
113 continue;
114 }
115
116 $id = $this->insert_attachment( $image );
117
118 if ( $id === 0 ) {
119 continue;
120 }
121 $ids[] = $id;
122 }
123
124 return $ids;
125 }
126
127 /**
128 * Insert single attachment
129 *
130 * @param array $image Image data.
131 *
132 * @return int
133 */
134 private function insert_attachment( $image ) {
135 $filename = basename( $image['url'] );
136 $name = pathinfo( $filename, PATHINFO_FILENAME );
137
138 $args = [
139 'post_title' => $name,
140 'post_type' => 'attachment',
141 'post_mime_type' => $image['meta']['mimeType'],
142 'guid' => $image['url'],
143 ];
144
145 $id = wp_insert_attachment( $args );
146
147 if ( $id === 0 ) {
148 return $id;
149 }
150
151 update_post_meta( $id, self::OM_DAM_IMPORTED_FLAG, $image['meta']['resourceS3'] );
152
153 if ( isset( $image['isEdit'] ) ) {
154 update_post_meta( $id, self::IS_EDIT_FLAG, true );
155 }
156
157 $metadata = [];
158
159 $metadata['file'] = '/id:' . $image['meta']['resourceS3'] . '/' . get_home_url() . '/' . $filename;
160 $metadata['mime-type'] = $image['meta']['mimeType'];
161
162 if ( isset( $image['meta']['filesize'] ) ) {
163 $metadata['filesize'] = $image['meta']['fileSize'];
164 }
165
166 if ( isset( $image['meta']['originalWidth'] ) && isset( $image['meta']['originalHeight'] ) ) {
167 $metadata['width'] = $image['meta']['originalWidth'];
168 $metadata['height'] = $image['meta']['originalHeight'];
169 }
170
171 wp_update_attachment_metadata( $id, $metadata );
172
173 return $id;
174 }
175
176 /**
177 * Alter attachment image src for DAM imported images.
178 *
179 * @param array|false $image {
180 * Array of image data.
181 *
182 * @type string $0 Image source URL.
183 * @type int $1 Image width in pixels.
184 * @type int $2 Image height in pixels.
185 * @type bool $3 Whether the image is a resized image.
186 * }
187 *
188 * @param int $attachment_id attachment id.
189 * @param string|int[] $size image size.
190 * @param bool $icon Whether the image should be treated as an icon.
191 *
192 * @return array $image.
193 */
194 public function alter_attachment_image_src( $image, $attachment_id, $size, $icon ) {
195 // Skip if not DAM image.
196 if ( ! $this->is_dam_imported_image( $attachment_id ) ) {
197 return $image;
198 }
199
200 $image_url = wp_get_attachment_url( $attachment_id );
201 $incoming_size = $this->parse_dimension_from_optimized_url( $image_url );
202 $width = $incoming_size[0];
203 $height = $incoming_size[1];
204
205 // Skip resize in single attachment view on backend.
206 if ( $this->is_attachment_edit_page( $attachment_id ) ) {
207 return [
208 $image_url,
209 $width,
210 $height,
211 false,
212 ];
213 }
214
215 // Use the original size if the requested size is full.
216 if ( $size === 'full' ) {
217 $metadata = wp_get_attachment_metadata( $attachment_id );
218
219 $image_url = $this->replace_dam_url_args(
220 [
221 'width' => $metadata['width'],
222 'height' => $metadata['height'],
223 'crop' => false,
224 ],
225 $image_url
226 );
227
228 return [
229 $image_url,
230 $metadata['width'],
231 $metadata['height'],
232 false,
233 ];
234 }
235
236 $crop = false;
237
238 // Size can be int [] containing width and height.
239 if ( is_array( $size ) ) {
240 $width = $size[0];
241 $height = $size[1];
242 $crop = true;
243 } else {
244 $sizes = $this->get_all_image_sizes();
245
246 if ( ! isset( $sizes[ $size ] ) ) {
247 return [
248 $image_url,
249 $width,
250 $height,
251 false,
252 ];
253 }
254
255 $width = $sizes[ $size ]['width'];
256 $height = $sizes[ $size ]['height'];
257 $crop = (bool) $sizes[ $size ]['crop'];
258 }
259
260 $image_url = $this->replace_dam_url_args(
261 [
262 'width' => $width,
263 'height' => $height,
264 'crop' => $crop,
265 ],
266 $image_url
267 );
268
269 return [
270 $image_url,
271 $width,
272 $height,
273 $crop,
274 ];
275 }
276
277 /**
278 * Alter the attachment metadata.
279 *
280 * @param array $metadata attachment metadata.
281 * @param int $id attachment ID.
282 *
283 * @return array
284 */
285 public function alter_attachment_metadata( $metadata, $id ) {
286 if ( ! $this->is_dam_imported_image( $id ) ) {
287 return $metadata;
288 }
289
290 return $this->get_altered_metadata_for_remote_images( $metadata, $id );
291 }
292
293 /**
294 * Check if the images are already imported.
295 *
296 * @param array $images List of images to check.
297 *
298 * @return array List of images that are already imported.
299 */
300 private function check_existing_attachments( $images ) {
301 $already_imported = $this->get_dam_imported_attachments( $images );
302
303 // All DAM imports are already in the DB.
304 if ( count( $already_imported ) === count( $images ) ) {
305 return $already_imported;
306 }
307
308 // Get the remaining images.
309 $remaining = array_filter(
310 $images,
311 function ( $image ) use ( $already_imported ) {
312 return ! array_key_exists( $image['meta']['resourceS3'], $already_imported );
313 }
314 );
315
316 // Offloaded images.
317 if ( $this->settings->get( 'offload_media' ) === 'enabled' ) {
318 $offloaded = $this->get_offloaded_attachments( $remaining );
319
320 $already_imported = array_merge( $already_imported, $offloaded );
321 }
322
323 return $already_imported;
324 }
325
326 /**
327 * Check if the images are already imported.
328 *
329 * @param array $images List of images to check.
330 *
331 * @return array
332 */
333 private function get_dam_imported_attachments( $images ) {
334 global $wpdb;
335
336 $s3_ids = [];
337
338 foreach ( $images as $image ) {
339 $s3_ids[] = esc_sql( strval( $image['meta']['resourceS3'] ) );
340 }
341
342 $meta_values_str = "'" . join( "', '", $s3_ids ) . "'";
343
344 // Select all the posts that have the flag and are in the list of images.
345 $found_attachments = $wpdb->get_results(
346 $wpdb->prepare(
347 // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- This query cannot use interpolation.
348 "SELECT post_id, meta_value FROM {$wpdb->postmeta} WHERE meta_key = %s AND meta_value IN ( {$meta_values_str} )",
349 self::OM_DAM_IMPORTED_FLAG
350 )
351 );
352
353 if ( empty( $found_attachments ) ) {
354 return [];
355 }
356
357 $map = [];
358
359 // Remap this in a key/value array.
360 // Also ensures that if there are multiple attachments with the same S3 ID, we only get the one.
361 // Shouldn't happen, but just in case.
362 foreach ( $found_attachments as $attachment ) {
363 // Skip edits.
364 if ( ! empty( get_post_meta( $attachment->post_id, self::IS_EDIT_FLAG, true ) ) ) {
365 continue;
366 }
367
368 $map[ $attachment->meta_value ] = (int) $attachment->post_id;
369 }
370
371 return $map;
372 }
373
374 /**
375 * Get the offloaded attachments.
376 *
377 * [ S3 ID => Attachment Post ID ]
378 *
379 * @param array $images List of images to check.
380 *
381 * @return array
382 */
383 private function get_offloaded_attachments( $images ) {
384 global $wpdb;
385
386 $map = [];
387
388 foreach ( $images as $image ) {
389 $like = '%id:' . $image['meta']['resourceS3'] . '%';
390
391 $found_attachments = $wpdb->get_results(
392 $wpdb->prepare(
393 "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = %s AND meta_value LIKE %s",
394 '_wp_attachment_metadata',
395 $like
396 )
397 );
398
399 if ( empty( $found_attachments ) ) {
400 return [];
401 }
402
403 $map[ $image['meta']['resourceS3'] ] = (int) $found_attachments[0]->post_id;
404 }
405
406 return $map;
407 }
408
409 /**
410 * Adds menu item for DAM.
411 *
412 * @return void
413 */
414 public function add_menu() {
415 if ( defined( 'OPTIOMLE_HIDE_ADMIN_AREA' ) && OPTIOMLE_HIDE_ADMIN_AREA ) {
416 return;
417 }
418
419 add_submenu_page(
420 'optimole',
421 __( 'Cloud Library', 'optimole-wp' ),
422 __( 'Cloud Library', 'optimole-wp' ),
423 'manage_options',
424 'optimole-dam',
425 [ $this, 'render_dashboard_page' ]
426 );
427 }
428
429 /**
430 * Add media template to be used in the media library.
431 *
432 * @return void
433 */
434 public function print_media_template() {
435 ?>
436 <script type="text/html" id="tmpl-optimole-dam">
437 <?php $this->render_dashboard_page(); ?>
438 </script>
439 <?php
440 }
441
442 /**
443 * Render the dashboard page.
444 *
445 * @return void
446 */
447 public function render_dashboard_page() {
448 ?>
449 <style>
450 .notice:not(.optml-notice-optin){
451 display: none !important;
452 }
453 </style>
454 <iframe id="om-dam" style="display: none;" src="<?php echo( $this->build_iframe_url() ); ?>"></iframe>
455 <div class="om-dam-loader">
456 <img src="<?php echo esc_url( OPTML_URL . 'assets/img/logo.png' ); ?>" alt="Optimole Logo"
457 class="om-dam-logo">
458 <p><?php echo esc_html__( 'Loading', 'optimole-wp' ); ?>...</p>
459 </div>
460 <?php
461 }
462
463 /**
464 * Build the iFrame URL.
465 *
466 * @return string
467 */
468 public function build_iframe_url() {
469 $api_key = $this->settings->get( 'api_key' );
470 $connected_sites = $this->settings->get( 'cloud_sites' );
471
472 if ( empty( $api_key ) ) {
473 return '';
474 }
475
476 if ( isset( $connected_sites['all'] ) && $connected_sites['all'] === 'true' ) {
477 $connected_sites = [];
478 } else {
479 foreach ( $connected_sites as $site => $status ) {
480 if ( $status !== 'true' ) {
481 unset( $connected_sites[ $site ] );
482 }
483 }
484 }
485
486 $data = [
487 'site' => get_site_url(),
488 'token' => $api_key,
489 'sites' => array_keys( $connected_sites ),
490 ];
491
492 $data = json_encode( $data );
493 $data = rtrim( base64_encode( $data ), '=' );
494
495 return add_query_arg(
496 [
497 'data' => $data,
498 ],
499 $this->dam_endpoint
500 );
501 }
502
503 /**
504 * Enqueue script for generating cloud media tab.
505 *
506 * @return void
507 */
508 public function enqueue_media_scripts() {
509 $asset_file = include OPTML_PATH . 'assets/build/media/media-modal.asset.php';
510
511 wp_register_script(
512 OPTML_NAMESPACE . '-media-modal',
513 OPTML_URL . 'assets/build/media/media-modal.js',
514 $asset_file['dependencies'],
515 $asset_file['version'],
516 true
517 );
518
519 wp_localize_script( OPTML_NAMESPACE . '-media-modal', 'optmlMediaModal', $this->get_localized_vars() );
520 wp_enqueue_script( OPTML_NAMESPACE . '-media-modal' );
521 wp_enqueue_style( OPTML_NAMESPACE . '-media-modal', OPTML_URL . 'assets/build/media/media-modal.css' );
522 }
523
524 /**
525 * Enqueue script for generating admin page.
526 *
527 * @return void
528 */
529 public function enqueue_admin_page_scripts() {
530 $screen = get_current_screen();
531
532 if ( $screen->id !== 'optimole_page_optimole-dam' ) {
533 return;
534 }
535
536 $asset_file = include OPTML_PATH . 'assets/build/media/admin-page.asset.php';
537
538 wp_register_script(
539 OPTML_NAMESPACE . '-admin-page',
540 OPTML_URL . 'assets/build/media/admin-page.js',
541 $asset_file['dependencies'],
542 $asset_file['version'],
543 true
544 );
545
546 wp_localize_script(
547 OPTML_NAMESPACE . '-admin-page',
548 'optmlAdminPage',
549 [
550 'siteUrl' => get_site_url(),
551 ]
552 );
553
554 wp_enqueue_script( OPTML_NAMESPACE . '-admin-page' );
555
556 wp_enqueue_style( OPTML_NAMESPACE . '-admin-page', OPTML_URL . 'assets/build/media/admin-page.css' );
557 }
558
559 /**
560 * Get localized variables for the media modal.
561 *
562 * @return array
563 */
564 private function get_localized_vars() {
565 $routes = array_keys( Optml_Rest::$rest_routes['dam_routes'] );
566
567 foreach ( $routes as $route ) {
568 $routes[ $route ] = OPTML_NAMESPACE . '/v1/' . $route;
569 }
570
571 return [
572 'nonce' => wp_create_nonce( 'wp_rest' ),
573 'routes' => $routes,
574 ];
575 }
576
577 /**
578 * Alter the image size for the image widget.
579 *
580 * @param string $html the attachment image HTML string.
581 * @param array $settings Control settings.
582 * @param string $image_size_key Optional. Settings key for image size.
583 * Default is `image`.
584 * @param string $image_key Optional. Settings key for image. Default
585 * is null. If not defined uses image size key
586 * as the image key.
587 *
588 * @return string
589 */
590 public function alter_elementor_image_size( $html, $settings, $image_size_key, $image_key ) {
591 if ( ! isset( $settings['image'] ) ) {
592 return $html;
593 }
594
595 $image = $settings['image'];
596
597 if ( ! isset( $image['id'] ) ) {
598 return $html;
599 }
600
601 if ( ! $this->is_dam_imported_image( $image['id'] ) ) {
602 return $html;
603 }
604
605 if ( ! isset( $settings['image_size'] ) ) {
606 return $html;
607 }
608
609 if ( $settings['image_size'] === 'custom' ) {
610 if ( ! isset( $settings['image_custom_dimension'] ) ) {
611 return $html;
612 }
613
614 $custom_dimensions = $settings['image_custom_dimension'];
615
616 if ( ! isset( $custom_dimensions['width'] ) || ! isset( $custom_dimensions['height'] ) ) {
617 return $html;
618 }
619
620 return $this->replace_dam_url_args( $custom_dimensions, $html );
621 }
622
623 $all_sizes = $this->get_all_image_sizes();
624
625 if ( ! isset( $all_sizes[ $settings['image_size'] ] ) ) {
626 return $html;
627 }
628
629 return $this->replace_dam_url_args( $all_sizes[ $settings['image_size'] ], $html );
630 }
631
632 /**
633 * Needed as some blocks might use the image sizes.
634 *
635 * @param array $response Array of prepared attachment data. @see wp_prepare_attachment_for_js().
636 * @param WP_Post $attachment Attachment object.
637 * @param array|false $meta Array of attachment meta data, or false if there is none.
638 *
639 * @return array
640 */
641 public function alter_attachment_for_js( $response, $attachment, $meta ) {
642 if ( ! $this->is_dam_imported_image( $attachment->ID ) ) {
643 return $response;
644 }
645
646 $sizes = $this->get_all_image_sizes();
647
648 foreach ( $sizes as $size => $args ) {
649 if ( isset( $response['sizes'][ $size ] ) ) {
650 continue;
651 }
652
653 $args = [
654 'height' => $args['height'],
655 'width' => $args['width'],
656 'crop' => true,
657 ];
658
659 $response['sizes'][ $size ] = array_merge(
660 $args,
661 [
662 'url' => $this->replace_dam_url_args( $args, $response['url'] ),
663 'orientation' => ( $args['height'] > $args['width'] ) ? 'portrait' : 'landscape',
664 ]
665 );
666 }
667
668 $url_args = [
669 'height' => $response['height'],
670 'width' => $response['width'],
671 'crop' => false,
672 ];
673
674 $response['url'] = $this->replace_dam_url_args( $url_args, $response['url'] );
675
676 return $response;
677 }
678
679 /**
680 * We have to short-circuit the logic that adds width and height to the img tag.
681 * It compares the URL basename, and the `file` param for each image.
682 * This happens for any image that gets its size set non-explicitly
683 * e.g. an image block with its size set from the sidebar to `thumbnail`).
684 *
685 * Optimole has a single basename for all image resizes in its URL.
686 *
687 * @param array|false $dimensions Array with first element being the width
688 * and second element being the height, or
689 * false if dimensions could not be determined.
690 * @param string $image_src The image URL (will be Optimole URL).
691 * @param array $image_meta The image metadata.
692 * @param int $attachment_id The image attachment ID. Default 0.
693 */
694 public function alter_img_tag_w_h( $dimensions, $image_src, $image_meta, $attachment_id ) {
695 if ( ! $this->is_dam_imported_image( $attachment_id ) ) {
696 return $dimensions;
697 }
698
699 // Get the dimensions from the optimized URL.
700 $incoming_size = $this->parse_dimension_from_optimized_url( $image_src );
701 $width = $incoming_size[0];
702 $height = $incoming_size[1];
703
704 $sizes = $this->get_all_image_sizes();
705
706 // If this is an image size. Return its dimensions.
707 foreach ( $sizes as $size => $args ) {
708 if ( (int) $args['width'] !== (int) $width ) {
709 continue;
710 }
711
712 if ( (int) $args['height'] !== (int) $height ) {
713 continue;
714 }
715
716 return [
717 $args['width'],
718 $args['height'],
719 ];
720 }
721
722 // Fall-through with the original dimensions.
723 return $dimensions;
724 }
725
726 /**
727 * Replace the image size params in DAM URLs inside a string.
728 *
729 * @param array $args The arguments to replace.
730 * - width: The width of the image.
731 * - height: The height of the image.
732 * - crop: Whether to crop the image.
733 * @param string $subject The string to replace the arguments in.
734 *
735 * @return string
736 */
737 public function replace_dam_url_args( $args, $subject ) {
738 $args = wp_parse_args( $args, [ 'width' => 'auto', 'height' => 'auto', 'crop' => false, 'dam' => true] );
739
740 $width = $args['width'];
741 $height = $args['height'];
742 $crop = (bool) $args['crop'];
743
744 $gravity = Optml_Resize::GRAVITY_CENTER;
745
746 if ( $this->settings->get( 'resize_smart' ) === 'enabled' ) {
747 $gravity = Optml_Resize::GRAVITY_SMART;
748 }
749
750 if ( $width === 0 ) {
751 $width = 'auto';
752 }
753
754 if ( $height === 0 ) {
755 $height = 'auto';
756 }
757
758 // Use the proper replacement for the image size.
759 $replacement = '/w:' . $width . '/h:' . $height;
760
761 if ( $crop ) {
762 $replacement .= '/g:' . $gravity . '/rt:fill';
763 }
764
765 $replacement .= '/q:';
766
767 if ( $args['dam'] ) {
768 $replacement = self::URL_DAM_FLAG . $replacement;
769 }
770
771 return preg_replace( '/\/w:(.*)\/h:(.*)\/q:/', $replacement, $subject );
772 }
773
774 /**
775 * Elementor checks if the file exists before requesting a specific image size.
776 *
777 * Needed because otherwise there won't be any width/height on the `img` tags, breaking lazyload.
778 *
779 * Also needed because some
780 *
781 * @param string $file The file path.
782 * @param int $id The attachment ID.
783 *
784 * @return bool|string
785 */
786 public function alter_attached_file_response( $file, $id ) {
787 if ( ! $this->is_dam_imported_image( $id ) ) {
788 return $file;
789 }
790
791 $metadata = wp_get_attachment_metadata( $id );
792
793 if ( isset( $metadata['file'] ) ) {
794 $uploads = wp_get_upload_dir();
795
796 return $uploads['basedir'] . '/' . $metadata['file'];
797 }
798
799 return true;
800 }
801
802 /**
803 * Alter the srcSet for DAM images.
804 *
805 * @param array $sources Initial source array.
806 * @param array $size_array Requested size.
807 * @param string $image_src Image source URL.
808 * @param array $image_meta Image meta data.
809 * @param int $attachment_id Image attachment ID.
810 *
811 * @return array
812 */
813 public function disable_dam_images_srcset( $sources, $size_array, $image_src, $image_meta, $attachment_id ) {
814 if ( ! $this->is_dam_imported_image( $attachment_id ) ) {
815 return $sources;
816 }
817
818 return [];
819 }
820 }
821