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 / compatibilities / spectra.php

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

61 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class Optml_spectra
5 *
6 * @reason Optimizing Block images when saved to a CSS file.
7 */
8 class Optml_spectra extends Optml_compatibility {
9
10 /**
11 * Should we load the integration logic.
12 *
13 * @return bool Should we load.
14 */
15 function should_load() {
16 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
17 return is_plugin_active( 'ultimate-addons-for-gutenberg/ultimate-addons-for-gutenberg.php' ) && 'enabled' === get_option( '_uagb_allow_file_generation', 'enabled' );
18 }
19
20 /**
21 * Register integration details.
22 */
23 public function register() {
24 add_filter( 'uagb_block_attributes_for_css_and_js', [ $this, 'optimize_src' ], PHP_INT_MAX, 2 );
25 }
26
27 /**
28 * Optimize the src attribute.
29 *
30 * @param array $attrs Array of attributes.
31 * @param string $name Name of the block.
32 *
33 * @return array
34 */
35 public function optimize_src( $attrs, $name ) {
36 $attrs = $this->iterate_array( $attrs );
37
38 return $attrs;
39 }
40
41 /**
42 * Iterate through the array and replace the url.
43 *
44 * @param array $attrs Array of attributes.
45 * @return array
46 */
47 public function iterate_array( $attrs ) {
48 foreach ( $attrs as $key => $value ) {
49 if ( is_array( $value ) ) {
50 $attrs[ $key ] = $this->iterate_array( $value );
51 }
52
53 if ( is_string( $value ) && preg_match( '/(http|https):\/\/.*\.(?:png|jpg|jpeg|gif|webp)/i', $value ) ) {
54 $attrs[ $key ] = Optml_Main::instance()->manager->url_replacer->build_url( $value );
55 }
56 }
57
58 return $attrs;
59 }
60 }
61