Image optimization & Lazy Load by Optimole - Version 2.5.7

Version Description

Download this release

Release Info

Developer optimole
Plugin Icon 128x128 Image optimization & Lazy Load by Optimole
Version 2.5.7
Comparing to
See all releases

Code changes from version 2.5.6 to 2.5.7

CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
1
  ##### [Version 2.5.6](https://github.com/Codeinwp/optimole-wp/compare/v2.5.5...v2.5.6) (2020-10-19)
2
 
3
  * Fixed regression on image lazyload after version v2.5.5
1
+ ##### [Version 2.5.7](https://github.com/Codeinwp/optimole-wp/compare/v2.5.6...v2.5.7) (2020-12-17)
2
+
3
+ #### Fixes
4
+ * Adds iframe style for lazyloading only when the iframe is used on the current page
5
+ * Improve lazyload CLS web vital
6
+ * Adds compatibility with Smart Search for Woocommerce
7
+
8
+ #### Features
9
+ * Adds option to set the plugin settings via [wp-config](https://docs.optimole.com/article/1316-setting-plugin-options-via-wp-config)constants
10
+ * Adds more option to set plugin settings via [wp cli](https://docs.optimole.com/article/1202-plugin-cli-commands)
11
+
12
  ##### [Version 2.5.6](https://github.com/Codeinwp/optimole-wp/compare/v2.5.5...v2.5.6) (2020-10-19)
13
 
14
  * Fixed regression on image lazyload after version v2.5.5
inc/admin.php CHANGED
@@ -27,18 +27,18 @@ class Optml_Admin {
27
  */
28
  public function __construct() {
29
  $this->settings = new Optml_Settings();
30
- add_action( 'plugin_action_links_' . plugin_basename( OPTML_BASEFILE ), array( $this, 'add_action_links' ) );
31
- add_action( 'admin_menu', array( $this, 'add_dashboard_page' ) );
32
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ), PHP_INT_MIN );
33
- add_action( 'admin_notices', array( $this, 'add_notice' ) );
34
- add_action( 'admin_notices', array( $this, 'add_notice_upgrade' ) );
35
- add_filter( 'admin_body_class', array( $this, 'add_body_class' ) );
36
- add_action( 'optml_daily_sync', array( $this, 'daily_sync' ) );
37
- add_action( 'admin_init', array( $this, 'maybe_redirect' ) );
38
  if ( ! is_admin() && $this->settings->is_connected() && ! wp_next_scheduled( 'optml_daily_sync' ) ) {
39
- wp_schedule_event( time() + 10, 'daily', 'optml_daily_sync', array() );
40
  }
41
- add_action( 'optml_after_setup', array( $this, 'register_public_actions' ), 999999 );
42
 
43
  }
44
 
@@ -49,18 +49,18 @@ class Optml_Admin {
49
  global $wp_admin_bar;
50
 
51
  $wp_admin_bar->add_node(
52
- array(
53
  'id' => 'optml_report_script',
54
  'href' => '#',
55
  'title' => '<span class="ab-icon"></span>Optimole ' . __( 'debugger', 'optimole-wp' ),
56
- )
57
  );
58
  $wp_admin_bar->add_menu(
59
- array(
60
  'id' => 'optml_status',
61
  'title' => __( 'Troubleshoot this page', 'optimole-wp' ),
62
  'parent' => 'optml_report_script',
63
- )
64
  );
65
  }
66
 
@@ -133,24 +133,36 @@ class Optml_Admin {
133
  * Register public actions.
134
  */
135
  public function register_public_actions() {
136
- add_action( 'wp_head', array( $this, 'generator' ) );
137
- add_filter( 'wp_resource_hints', array( $this, 'add_dns_prefetch' ), 10, 2 );
138
 
139
  if ( Optml_Manager::should_ignore_image_tags() ) {
140
  return;
141
  }
142
  if ( ! is_admin() && $this->settings->get( 'report_script' ) === 'enabled' && current_user_can( 'manage_options' ) ) {
143
 
144
- add_action( 'wp_head', array( $this, 'print_report_css' ) );
145
- add_action( 'wp_before_admin_bar_render', array( $this, 'add_report_menu' ) );
146
- add_action( 'wp_enqueue_scripts', array( $this, 'add_diagnosis_script' ) );
147
  }
148
  if ( ! $this->settings->use_lazyload() ) {
149
  return;
150
  }
151
- add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
152
- add_action( 'wp_head', array( $this, 'inline_bootstrap_script' ) );
153
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  }
155
 
156
  /**
@@ -194,17 +206,10 @@ class Optml_Admin {
194
  animation: 0.1s ease-in;
195
  -webkit-transform: translate3d(0, 0, 0);
196
  }
197
- iframe[data-opt-src]:not([data-opt-lazy-loaded]) {
198
- background-color: #ffffff;
199
- background-image: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/Pgo8IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPgo8c3ZnIHdpZHRoPSI0MHB4IiBoZWlnaHQ9IjQwcHgiIHZpZXdCb3g9IjAgMCA0MCA0MCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4bWw6c3BhY2U9InByZXNlcnZlIiBzdHlsZT0iZmlsbC1ydWxlOmV2ZW5vZGQ7Y2xpcC1ydWxlOmV2ZW5vZGQ7c3Ryb2tlLWxpbmVqb2luOnJvdW5kO3N0cm9rZS1taXRlcmxpbWl0OjEuNDE0MjE7IiB4PSIwcHgiIHk9IjBweCI+CiAgICA8ZGVmcz4KICAgICAgICA8c3R5bGUgdHlwZT0idGV4dC9jc3MiPjwhW0NEQVRBWwogICAgICAgICAgICBALXdlYmtpdC1rZXlmcmFtZXMgc3BpbiB7CiAgICAgICAgICAgICAgZnJvbSB7CiAgICAgICAgICAgICAgICAtd2Via2l0LXRyYW5zZm9ybTogcm90YXRlKDBkZWcpCiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHRvIHsKICAgICAgICAgICAgICAgIC13ZWJraXQtdHJhbnNmb3JtOiByb3RhdGUoLTM1OWRlZykKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgQGtleWZyYW1lcyBzcGluIHsKICAgICAgICAgICAgICBmcm9tIHsKICAgICAgICAgICAgICAgIHRyYW5zZm9ybTogcm90YXRlKDBkZWcpCiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHRvIHsKICAgICAgICAgICAgICAgIHRyYW5zZm9ybTogcm90YXRlKC0zNTlkZWcpCiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHN2ZyB7CiAgICAgICAgICAgICAgICAtd2Via2l0LXRyYW5zZm9ybS1vcmlnaW46IDUwJSA1MCU7CiAgICAgICAgICAgICAgICAtd2Via2l0LWFuaW1hdGlvbjogc3BpbiAxLjVzIGxpbmVhciBpbmZpbml0ZTsKICAgICAgICAgICAgICAgIC13ZWJraXQtYmFja2ZhY2UtdmlzaWJpbGl0eTogaGlkZGVuOwogICAgICAgICAgICAgICAgYW5pbWF0aW9uOiBzcGluIDEuNXMgbGluZWFyIGluZmluaXRlOwogICAgICAgICAgICB9CiAgICAgICAgXV0+PC9zdHlsZT4KICAgIDwvZGVmcz4KICAgIDxnIGlkPSJvdXRlciI+CiAgICAgICAgPGc+CiAgICAgICAgICAgIDxwYXRoIGQ9Ik0yMCwwQzIyLjIwNTgsMCAyMy45OTM5LDEuNzg4MTMgMjMuOTkzOSwzLjk5MzlDMjMuOTkzOSw2LjE5OTY4IDIyLjIwNTgsNy45ODc4MSAyMCw3Ljk4NzgxQzE3Ljc5NDIsNy45ODc4MSAxNi4wMDYxLDYuMTk5NjggMTYuMDA2MSwzLjk5MzlDMTYuMDA2MSwxLjc4ODEzIDE3Ljc5NDIsMCAyMCwwWiIgc3R5bGU9ImZpbGw6YmxhY2s7Ii8+CiAgICAgICAgPC9nPgogICAgICAgIDxnPgogICAgICAgICAgICA8cGF0aCBkPSJNNS44NTc4Niw1Ljg1Nzg2QzcuNDE3NTgsNC4yOTgxNSA5Ljk0NjM4LDQuMjk4MTUgMTEuNTA2MSw1Ljg1Nzg2QzEzLjA2NTgsNy40MTc1OCAxMy4wNjU4LDkuOTQ2MzggMTEuNTA2MSwxMS41MDYxQzkuOTQ2MzgsMTMuMDY1OCA3LjQxNzU4LDEzLjA2NTggNS44NTc4NiwxMS41MDYxQzQuMjk4MTUsOS45NDYzOCA0LjI5ODE1LDcuNDE3NTggNS44NTc4Niw1Ljg1Nzg2WiIgc3R5bGU9ImZpbGw6cmdiKDIxMCwyMTAsMjEwKTsiLz4KICAgICAgICA8L2c+CiAgICAgICAgPGc+CiAgICAgICAgICAgIDxwYXRoIGQ9Ik0yMCwzMi4wMTIyQzIyLjIwNTgsMzIuMDEyMiAyMy45OTM5LDMzLjgwMDMgMjMuOTkzOSwzNi4wMDYxQzIzLjk5MzksMzguMjExOSAyMi4yMDU4LDQwIDIwLDQwQzE3Ljc5NDIsNDAgMTYuMDA2MSwzOC4yMTE5IDE2LjAwNjEsMzYuMDA2MUMxNi4wMDYxLDMzLjgwMDMgMTcuNzk0MiwzMi4wMTIyIDIwLDMyLjAxMjJaIiBzdHlsZT0iZmlsbDpyZ2IoMTMwLDEzMCwxMzApOyIvPgogICAgICAgIDwvZz4KICAgICAgICA8Zz4KICAgICAgICAgICAgPHBhdGggZD0iTTI4LjQ5MzksMjguNDkzOUMzMC4wNTM2LDI2LjkzNDIgMzIuNTgyNCwyNi45MzQyIDM0LjE0MjEsMjguNDkzOUMzNS43MDE5LDMwLjA1MzYgMzUuNzAxOSwzMi41ODI0IDM0LjE0MjEsMzQuMTQyMUMzMi41ODI0LDM1LjcwMTkgMzAuMDUzNiwzNS43MDE5IDI4LjQ5MzksMzQuMTQyMUMyNi45MzQyLDMyLjU4MjQgMjYuOTM0MiwzMC4wNTM2IDI4LjQ5MzksMjguNDkzOVoiIHN0eWxlPSJmaWxsOnJnYigxMDEsMTAxLDEwMSk7Ii8+CiAgICAgICAgPC9nPgogICAgICAgIDxnPgogICAgICAgICAgICA8cGF0aCBkPSJNMy45OTM5LDE2LjAwNjFDNi4xOTk2OCwxNi4wMDYxIDcuOTg3ODEsMTcuNzk0MiA3Ljk4NzgxLDIwQzcuOTg3ODEsMjIuMjA1OCA2LjE5OTY4LDIzLjk5MzkgMy45OTM5LDIzLjk5MzlDMS43ODgxMywyMy45OTM5IDAsMjIuMjA1OCAwLDIwQzAsMTcuNzk0MiAxLjc4ODEzLDE2LjAwNjEgMy45OTM5LDE2LjAwNjFaIiBzdHlsZT0iZmlsbDpyZ2IoMTg3LDE4NywxODcpOyIvPgogICAgICAgIDwvZz4KICAgICAgICA8Zz4KICAgICAgICAgICAgPHBhdGggZD0iTTUuODU3ODYsMjguNDkzOUM3LjQxNzU4LDI2LjkzNDIgOS45NDYzOCwyNi45MzQyIDExLjUwNjEsMjguNDkzOUMxMy4wNjU4LDMwLjA1MzYgMTMuMDY1OCwzMi41ODI0IDExLjUwNjEsMzQuMTQyMUM5Ljk0NjM4LDM1LjcwMTkgNy40MTc1OCwzNS43MDE5IDUuODU3ODYsMzQuMTQyMUM0LjI5ODE1LDMyLjU4MjQgNC4yOTgxNSwzMC4wNTM2IDUuODU3ODYsMjguNDkzOVoiIHN0eWxlPSJmaWxsOnJnYigxNjQsMTY0LDE2NCk7Ii8+CiAgICAgICAgPC9nPgogICAgICAgIDxnPgogICAgICAgICAgICA8cGF0aCBkPSJNMzYuMDA2MSwxNi4wMDYxQzM4LjIxMTksMTYuMDA2MSA0MCwxNy43OTQyIDQwLDIwQzQwLDIyLjIwNTggMzguMjExOSwyMy45OTM5IDM2LjAwNjEsMjMuOTkzOUMzMy44MDAzLDIzLjk5MzkgMzIuMDEyMiwyMi4yMDU4IDMyLjAxMjIsMjBDMzIuMDEyMiwxNy43OTQyIDMzLjgwMDMsMTYuMDA2MSAzNi4wMDYxLDE2LjAwNjFaIiBzdHlsZT0iZmlsbDpyZ2IoNzQsNzQsNzQpOyIvPgogICAgICAgIDwvZz4KICAgICAgICA8Zz4KICAgICAgICAgICAgPHBhdGggZD0iTTI4LjQ5MzksNS44NTc4NkMzMC4wNTM2LDQuMjk4MTUgMzIuNTgyNCw0LjI5ODE1IDM0LjE0MjEsNS44NTc4NkMzNS43MDE5LDcuNDE3NTggMzUuNzAxOSw5Ljk0NjM4IDM0LjE0MjEsMTEuNTA2MUMzMi41ODI0LDEzLjA2NTggMzAuMDUzNiwxMy4wNjU4IDI4LjQ5MzksMTEuNTA2MUMyNi45MzQyLDkuOTQ2MzggMjYuOTM0Miw3LjQxNzU4IDI4LjQ5MzksNS44NTc4NloiIHN0eWxlPSJmaWxsOnJnYig1MCw1MCw1MCk7Ii8+CiAgICAgICAgPC9nPgogICAgPC9nPgo8L3N2Zz4K");
200
- background-repeat: no-repeat;
201
- background-position: 50%% 50%%;
202
- }
203
-
204
-
205
  </style>
206
  <script type="application/javascript">
207
- document.documentElement.className += " optimole_has_js";
208
  (function(w, d){
209
  var b = d.getElementsByTagName("head")[0];
210
  var s = d.createElement("script");
@@ -238,6 +243,7 @@ class Optml_Admin {
238
  }
239
  } );
240
  </script>',
 
241
  esc_url( $domain ),
242
  $min,
243
  $bgclasses,
@@ -258,15 +264,15 @@ class Optml_Admin {
258
  public function add_diagnosis_script() {
259
 
260
  wp_enqueue_script( 'optml-report', OPTML_URL . 'assets/js/report_script.js' );
261
- $ignoredDomains = [ 'gravatar.com', 'instagram.com', 'fbcdn' ];
262
- $report_script = array(
263
  'optmlCdn' => $this->settings->get_cdn_url(),
264
  'restUrl' => untrailingslashit( rest_url( OPTML_NAMESPACE . '/v1' ) ) . '/check_redirects',
265
  'nonce' => wp_create_nonce( 'wp_rest' ),
266
- 'ignoredDomains' => $ignoredDomains,
267
  'wait' => __( 'We are checking the current page for any issues with optimized images ...', 'optimole-wp' ),
268
  'description' => __( 'Optimole page analyzer', 'optimole-wp' ),
269
- );
270
  wp_localize_script( 'optml-report', 'reportScript', $report_script );
271
  }
272
 
@@ -284,9 +290,9 @@ class Optml_Admin {
284
 
285
  return array_merge(
286
  $links,
287
- array(
288
  '<a href="' . admin_url( 'upload.php?page=optimole' ) . '">' . __( 'Settings', 'optimole-wp' ) . '</a>',
289
- )
290
  );
291
  }
292
 
@@ -320,13 +326,13 @@ class Optml_Admin {
320
  return false;
321
  }
322
 
323
- static $allowed_base = array(
324
  'plugins' => true,
325
  'upload' => true,
326
  'media' => true,
327
  'themes' => true,
328
  'appearance_page_tgmpa-install-plugins' => true,
329
- );
330
 
331
  $screen_slug = '';
332
  if ( isset( $current_screen->base ) ) {
@@ -363,7 +369,7 @@ class Optml_Admin {
363
  class="dashicons dashicons-external"></span><?php _e( 'Check upgrade plans', 'optimole-wp' ); ?>
364
  </a>
365
  <a class="button"
366
- href="<?php echo wp_nonce_url( add_query_arg( array( 'optml_hide_upg' => 'yes' ) ), 'hide_nonce', 'optml_nonce' ); ?>"><?php _e( 'I\'ve done this', 'optimole-wp' ); ?></a>
367
  </p>
368
  </div>
369
  <?php
@@ -423,7 +429,7 @@ class Optml_Admin {
423
  <a href="<?php echo esc_url( admin_url( 'upload.php?page=optimole' ) ); ?>"
424
  class="button button-primary"><?php _e( 'Connect to OptiMole', 'optimole-wp' ); ?></a>
425
  <a class="button"
426
- href="<?php echo wp_nonce_url( add_query_arg( array( 'optml_hide_optin' => 'yes' ) ), 'hide_nonce', 'optml_nonce' ); ?>"><?php _e( 'I will do it later', 'optimole-wp' ); ?></a>
427
  </p>
428
  </div>
429
  <?php
@@ -438,7 +444,7 @@ class Optml_Admin {
438
 
439
  $css = [];
440
  foreach ( $watchers as $selector ) {
441
- $css[] = 'html.optimole_has_js ' . $selector . ':not(.optml-bg-lazyloaded)';
442
  }
443
  if ( empty( $css ) ) {
444
  return '';
@@ -457,7 +463,7 @@ class Optml_Admin {
457
 
458
  wp_register_style( 'optm_lazyload_noscript_style', false );
459
  wp_enqueue_style( 'optm_lazyload_noscript_style' );
460
- wp_add_inline_style( 'optm_lazyload_noscript_style', "html:not(.optimole_has_js) img[data-opt-src] { display: none !important; } \n " . $bg_css );
461
  }
462
 
463
  /**
@@ -563,7 +569,7 @@ class Optml_Admin {
563
  if ( defined( 'OPTIOMLE_HIDE_ADMIN_AREA' ) && OPTIOMLE_HIDE_ADMIN_AREA ) {
564
  return;
565
  }
566
- add_media_page( 'Optimole', 'Optimole', 'manage_options', 'optimole', array( $this, 'render_dashboard_page' ) );
567
  }
568
 
569
  /**
@@ -592,10 +598,10 @@ class Optml_Admin {
592
  if ( ! isset( $current_screen->id ) ) {
593
  return;
594
  }
595
- if ( $current_screen->id != 'media_page_optimole' ) {
596
  return;
597
  }
598
- wp_register_script( OPTML_NAMESPACE . '-admin', OPTML_URL . 'assets/js/bundle' . ( ! OPTML_DEBUG ? '.min' : '' ) . '.js', array(), OPTML_VERSION );
599
  wp_localize_script( OPTML_NAMESPACE . '-admin', 'optimoleDashboardApp', $this->localize_dashboard_app() );
600
  wp_enqueue_script( OPTML_NAMESPACE . '-admin' );
601
  }
@@ -611,7 +617,7 @@ class Optml_Admin {
611
  $service_data = $this->settings->get( 'service_data' );
612
  $user = get_userdata( get_current_user_id() );
613
 
614
- return array(
615
  'strings' => $this->get_dashboard_strings(),
616
  'assets_url' => OPTML_URL . 'assets/',
617
  'connection_status' => empty( $service_data ) ? 'no' : 'yes',
@@ -621,12 +627,12 @@ class Optml_Admin {
621
  'nonce' => wp_create_nonce( 'wp_rest' ),
622
  'user_data' => $service_data,
623
  'remove_latest_images' => defined( 'OPTML_REMOVE_LATEST_IMAGES' ) && constant( 'OPTML_REMOVE_LATEST_IMAGES' ) ? ( OPTML_REMOVE_LATEST_IMAGES ? 'yes' : 'no' ) : 'no',
624
- 'current_user' => array(
625
  'email' => $user->user_email,
626
- ),
627
  'site_settings' => $this->settings->get_site_settings(),
628
  'home_url' => home_url(),
629
- );
630
  }
631
 
632
  /**
@@ -636,7 +642,7 @@ class Optml_Admin {
636
  * @return array
637
  */
638
  private function get_dashboard_strings() {
639
- return array(
640
  'optimole' => 'Optimole',
641
  'version' => OPTML_VERSION,
642
  'terms_menu' => __( 'Terms', 'optimole-wp' ),
@@ -708,21 +714,21 @@ The root cause might be either a security plugin which blocks this feature or so
708
  'lazyload_settings_menu_item' => __( 'Lazyload', 'optimole-wp' ),
709
  'watermarks_menu_item' => __( 'Watermark', 'optimole-wp' ),
710
  'conflicts_menu_item' => __( 'Possible issues', 'optimole-wp' ),
711
- 'conflicts' => array(
712
  'title' => __( 'We might have some possible conflicts with the plugins that you use. In order to benefit from Optimole\'s full potential you will need to address this issues.', 'optimole-wp' ),
713
  'message' => __( 'Details', 'optimole-wp' ),
714
  'conflict_close' => __( 'I\'ve done this.', 'optimole-wp' ),
715
  'no_conflicts_found' => __( 'No conflicts found. We are all peachy now. 🍑', 'optimole-wp' ),
716
- ),
717
- 'upgrade' => array(
718
  'title' => __( 'Upgrade to Pro', 'optimole-wp' ),
719
  'reason_1' => __( 'Priority & Live Chat support', 'optimole-wp' ),
720
  'reason_2' => __( 'Extend visits limit', 'optimole-wp' ),
721
  'reason_3' => __( 'Custom domain', 'optimole-wp' ),
722
  'reason_4' => __( 'Site audit', 'optimole-wp' ),
723
  'cta' => __( 'View plans', 'optimole-wp' ),
724
- ),
725
- 'options_strings' => array(
726
  'add_filter' => __( 'Add filter', 'optimole-wp' ),
727
  'admin_bar_desc' => __( 'Show in the WordPress admin bar the available quota from Optimole service.', 'optimole-wp' ),
728
  'auto_q_title' => __( 'Auto', 'optimole-wp' ),
@@ -802,8 +808,8 @@ The root cause might be either a security plugin which blocks this feature or so
802
  'css_minify_desc' => __( 'Once Optimole will serve your CSS files, it will also minify the files and serve them via CDN.', 'optimole-wp' ),
803
  'enable_js_minify_title' => __( 'Minify JS files', 'optimole-wp' ),
804
  'js_minify_desc' => __( 'Once Optimole will serve your JS files, it will also minify the files and serve them via CDN.', 'optimole-wp' ),
805
- ),
806
- 'watermarks' => array(
807
  'image' => __( 'Image', 'optimole-wp' ),
808
  'loading_remove_watermark' => __( 'Removing watermark resource ...', 'optimole-wp' ),
809
  'max_allowed' => __( 'You are allowed to save maximum 5 images.', 'optimole-wp' ),
@@ -840,8 +846,8 @@ The root cause might be either a security plugin which blocks this feature or so
840
  'scale_title' => __( 'Watermark scale', 'optimole-wp' ),
841
  'scale_desc' => __( 'A value between 0 and 300 for the scale of the watermark (100 is the original size and 300 is 3x the size) relative to the resulting image size. If set to 0 it will default to the original size.', 'optimole-wp' ),
842
  'save_changes' => __( 'Save changes', 'optimole-wp' ),
843
- ),
844
- 'latest_images' => array(
845
  'image' => __( 'Image', 'optimole-wp' ),
846
  'no_images_found' => sprintf( __( 'We are currently optimizing your images. Meanwhile you can visit your %1$shomepage%2$s and check how our plugin performs. ', 'optimole-wp' ), '<a href="' . esc_url( home_url() ) . '" target="_blank" >', '</a>' ),
847
  'compression' => __( 'Optimization', 'optimole-wp' ),
@@ -852,8 +858,8 @@ The root cause might be either a security plugin which blocks this feature or so
852
  'small_optimization' => __( '😬 Not that much, just <strong>{ratio}</strong> smaller.', 'optimole-wp' ),
853
  'medium_optimization' => __( '🤓 We are on the right track, <strong>{ratio}</strong> squeezed.', 'optimole-wp' ),
854
  'big_optimization' => __( '❤️❤️❤️ Our moles just nailed it, this one is <strong>{ratio}</strong> smaller. ', 'optimole-wp' ),
855
- ),
856
- );
857
  }
858
 
859
  }
27
  */
28
  public function __construct() {
29
  $this->settings = new Optml_Settings();
30
+ add_action( 'plugin_action_links_' . plugin_basename( OPTML_BASEFILE ), [ $this, 'add_action_links' ] );
31
+ add_action( 'admin_menu', [ $this, 'add_dashboard_page' ] );
32
+ add_action( 'admin_enqueue_scripts', [ $this, 'enqueue' ], PHP_INT_MIN );
33
+ add_action( 'admin_notices', [ $this, 'add_notice' ] );
34
+ add_action( 'admin_notices', [ $this, 'add_notice_upgrade' ] );
35
+ add_filter( 'admin_body_class', [ $this, 'add_body_class' ] );
36
+ add_action( 'optml_daily_sync', [ $this, 'daily_sync' ] );
37
+ add_action( 'admin_init', [ $this, 'maybe_redirect' ] );
38
  if ( ! is_admin() && $this->settings->is_connected() && ! wp_next_scheduled( 'optml_daily_sync' ) ) {
39
+ wp_schedule_event( time() + 10, 'daily', 'optml_daily_sync', [] );
40
  }
41
+ add_action( 'optml_after_setup', [ $this, 'register_public_actions' ], 999999 );
42
 
43
  }
44
 
49
  global $wp_admin_bar;
50
 
51
  $wp_admin_bar->add_node(
52
+ [
53
  'id' => 'optml_report_script',
54
  'href' => '#',
55
  'title' => '<span class="ab-icon"></span>Optimole ' . __( 'debugger', 'optimole-wp' ),
56
+ ]
57
  );
58
  $wp_admin_bar->add_menu(
59
+ [
60
  'id' => 'optml_status',
61
  'title' => __( 'Troubleshoot this page', 'optimole-wp' ),
62
  'parent' => 'optml_report_script',
63
+ ]
64
  );
65
  }
66
 
133
  * Register public actions.
134
  */
135
  public function register_public_actions() {
136
+ add_action( 'wp_head', [ $this, 'generator' ] );
137
+ add_filter( 'wp_resource_hints', [ $this, 'add_dns_prefetch' ], 10, 2 );
138
 
139
  if ( Optml_Manager::should_ignore_image_tags() ) {
140
  return;
141
  }
142
  if ( ! is_admin() && $this->settings->get( 'report_script' ) === 'enabled' && current_user_can( 'manage_options' ) ) {
143
 
144
+ add_action( 'wp_head', [ $this, 'print_report_css' ] );
145
+ add_action( 'wp_before_admin_bar_render', [ $this, 'add_report_menu' ] );
146
+ add_action( 'wp_enqueue_scripts', [ $this, 'add_diagnosis_script' ] );
147
  }
148
  if ( ! $this->settings->use_lazyload() ) {
149
  return;
150
  }
151
+ add_action( 'wp_enqueue_scripts', [ $this, 'frontend_scripts' ] );
152
+ add_action( 'wp_head', [ $this, 'inline_bootstrap_script' ] );
153
 
154
+ add_filter( 'optml_additional_html_classes', [ $this, 'add_no_js_class_to_html_tag' ], 10, 1 );
155
+ }
156
+
157
+ /**
158
+ * Use filter to add additional class to html tag.
159
+ *
160
+ * @param array $classes The classes to be added.
161
+ *
162
+ * @return array
163
+ */
164
+ public function add_no_js_class_to_html_tag( $classes ) {
165
+ return array_merge( $classes, [ 'optml_no_js' ] );
166
  }
167
 
168
  /**
206
  animation: 0.1s ease-in;
207
  -webkit-transform: translate3d(0, 0, 0);
208
  }
209
+ %s
 
 
 
 
 
 
 
210
  </style>
211
  <script type="application/javascript">
212
+ document.documentElement.className = document.documentElement.className.replace(/\boptml_no_js\b/g, "");
213
  (function(w, d){
214
  var b = d.getElementsByTagName("head")[0];
215
  var s = d.createElement("script");
243
  }
244
  } );
245
  </script>',
246
+ Optml_Lazyload_Replacer::IFRAME_TEMP_COMMENT,
247
  esc_url( $domain ),
248
  $min,
249
  $bgclasses,
264
  public function add_diagnosis_script() {
265
 
266
  wp_enqueue_script( 'optml-report', OPTML_URL . 'assets/js/report_script.js' );
267
+ $ignored_domains = [ 'gravatar.com', 'instagram.com', 'fbcdn' ];
268
+ $report_script = [
269
  'optmlCdn' => $this->settings->get_cdn_url(),
270
  'restUrl' => untrailingslashit( rest_url( OPTML_NAMESPACE . '/v1' ) ) . '/check_redirects',
271
  'nonce' => wp_create_nonce( 'wp_rest' ),
272
+ 'ignoredDomains' => $ignored_domains,
273
  'wait' => __( 'We are checking the current page for any issues with optimized images ...', 'optimole-wp' ),
274
  'description' => __( 'Optimole page analyzer', 'optimole-wp' ),
275
+ ];
276
  wp_localize_script( 'optml-report', 'reportScript', $report_script );
277
  }
278
 
290
 
291
  return array_merge(
292
  $links,
293
+ [
294
  '<a href="' . admin_url( 'upload.php?page=optimole' ) . '">' . __( 'Settings', 'optimole-wp' ) . '</a>',
295
+ ]
296
  );
297
  }
298
 
326
  return false;
327
  }
328
 
329
+ static $allowed_base = [
330
  'plugins' => true,
331
  'upload' => true,
332
  'media' => true,
333
  'themes' => true,
334
  'appearance_page_tgmpa-install-plugins' => true,
335
+ ];
336
 
337
  $screen_slug = '';
338
  if ( isset( $current_screen->base ) ) {
369
  class="dashicons dashicons-external"></span><?php _e( 'Check upgrade plans', 'optimole-wp' ); ?>
370
  </a>
371
  <a class="button"
372
+ href="<?php echo wp_nonce_url( add_query_arg( [ 'optml_hide_upg' => 'yes' ] ), 'hide_nonce', 'optml_nonce' ); ?>"><?php _e( 'I\'ve done this', 'optimole-wp' ); ?></a>
373
  </p>
374
  </div>
375
  <?php
429
  <a href="<?php echo esc_url( admin_url( 'upload.php?page=optimole' ) ); ?>"
430
  class="button button-primary"><?php _e( 'Connect to OptiMole', 'optimole-wp' ); ?></a>
431
  <a class="button"
432
+ href="<?php echo wp_nonce_url( add_query_arg( [ 'optml_hide_optin' => 'yes' ] ), 'hide_nonce', 'optml_nonce' ); ?>"><?php _e( 'I will do it later', 'optimole-wp' ); ?></a>
433
  </p>
434
  </div>
435
  <?php
444
 
445
  $css = [];
446
  foreach ( $watchers as $selector ) {
447
+ $css[] = 'html ' . $selector . ':not(.optml-bg-lazyloaded)';
448
  }
449
  if ( empty( $css ) ) {
450
  return '';
463
 
464
  wp_register_style( 'optm_lazyload_noscript_style', false );
465
  wp_enqueue_style( 'optm_lazyload_noscript_style' );
466
+ wp_add_inline_style( 'optm_lazyload_noscript_style', "html.optml_no_js img[data-opt-src] { display: none !important; } \n " . $bg_css );
467
  }
468
 
469
  /**
569
  if ( defined( 'OPTIOMLE_HIDE_ADMIN_AREA' ) && OPTIOMLE_HIDE_ADMIN_AREA ) {
570
  return;
571
  }
572
+ add_media_page( 'Optimole', 'Optimole', 'manage_options', 'optimole', [ $this, 'render_dashboard_page' ] );
573
  }
574
 
575
  /**
598
  if ( ! isset( $current_screen->id ) ) {
599
  return;
600
  }
601
+ if ( $current_screen->id !== 'media_page_optimole' ) {
602
  return;
603
  }
604
+ wp_register_script( OPTML_NAMESPACE . '-admin', OPTML_URL . 'assets/js/bundle' . ( ! OPTML_DEBUG ? '.min' : '' ) . '.js', [], OPTML_VERSION );
605
  wp_localize_script( OPTML_NAMESPACE . '-admin', 'optimoleDashboardApp', $this->localize_dashboard_app() );
606
  wp_enqueue_script( OPTML_NAMESPACE . '-admin' );
607
  }
617
  $service_data = $this->settings->get( 'service_data' );
618
  $user = get_userdata( get_current_user_id() );
619
 
620
+ return [
621
  'strings' => $this->get_dashboard_strings(),
622
  'assets_url' => OPTML_URL . 'assets/',
623
  'connection_status' => empty( $service_data ) ? 'no' : 'yes',
627
  'nonce' => wp_create_nonce( 'wp_rest' ),
628
  'user_data' => $service_data,
629
  'remove_latest_images' => defined( 'OPTML_REMOVE_LATEST_IMAGES' ) && constant( 'OPTML_REMOVE_LATEST_IMAGES' ) ? ( OPTML_REMOVE_LATEST_IMAGES ? 'yes' : 'no' ) : 'no',
630
+ 'current_user' => [
631
  'email' => $user->user_email,
632
+ ],
633
  'site_settings' => $this->settings->get_site_settings(),
634
  'home_url' => home_url(),
635
+ ];
636
  }
637
 
638
  /**
642
  * @return array
643
  */
644
  private function get_dashboard_strings() {
645
+ return [
646
  'optimole' => 'Optimole',
647
  'version' => OPTML_VERSION,
648
  'terms_menu' => __( 'Terms', 'optimole-wp' ),
714
  'lazyload_settings_menu_item' => __( 'Lazyload', 'optimole-wp' ),
715
  'watermarks_menu_item' => __( 'Watermark', 'optimole-wp' ),
716
  'conflicts_menu_item' => __( 'Possible issues', 'optimole-wp' ),
717
+ 'conflicts' => [
718
  'title' => __( 'We might have some possible conflicts with the plugins that you use. In order to benefit from Optimole\'s full potential you will need to address this issues.', 'optimole-wp' ),
719
  'message' => __( 'Details', 'optimole-wp' ),
720
  'conflict_close' => __( 'I\'ve done this.', 'optimole-wp' ),
721
  'no_conflicts_found' => __( 'No conflicts found. We are all peachy now. 🍑', 'optimole-wp' ),
722
+ ],
723
+ 'upgrade' => [
724
  'title' => __( 'Upgrade to Pro', 'optimole-wp' ),
725
  'reason_1' => __( 'Priority & Live Chat support', 'optimole-wp' ),
726
  'reason_2' => __( 'Extend visits limit', 'optimole-wp' ),
727
  'reason_3' => __( 'Custom domain', 'optimole-wp' ),
728
  'reason_4' => __( 'Site audit', 'optimole-wp' ),
729
  'cta' => __( 'View plans', 'optimole-wp' ),
730
+ ],
731
+ 'options_strings' => [
732
  'add_filter' => __( 'Add filter', 'optimole-wp' ),
733
  'admin_bar_desc' => __( 'Show in the WordPress admin bar the available quota from Optimole service.', 'optimole-wp' ),
734
  'auto_q_title' => __( 'Auto', 'optimole-wp' ),
808
  'css_minify_desc' => __( 'Once Optimole will serve your CSS files, it will also minify the files and serve them via CDN.', 'optimole-wp' ),
809
  'enable_js_minify_title' => __( 'Minify JS files', 'optimole-wp' ),
810
  'js_minify_desc' => __( 'Once Optimole will serve your JS files, it will also minify the files and serve them via CDN.', 'optimole-wp' ),
811
+ ],
812
+ 'watermarks' => [
813
  'image' => __( 'Image', 'optimole-wp' ),
814
  'loading_remove_watermark' => __( 'Removing watermark resource ...', 'optimole-wp' ),
815
  'max_allowed' => __( 'You are allowed to save maximum 5 images.', 'optimole-wp' ),
846
  'scale_title' => __( 'Watermark scale', 'optimole-wp' ),
847
  'scale_desc' => __( 'A value between 0 and 300 for the scale of the watermark (100 is the original size and 300 is 3x the size) relative to the resulting image size. If set to 0 it will default to the original size.', 'optimole-wp' ),
848
  'save_changes' => __( 'Save changes', 'optimole-wp' ),
849
+ ],
850
+ 'latest_images' => [
851
  'image' => __( 'Image', 'optimole-wp' ),
852
  'no_images_found' => sprintf( __( 'We are currently optimizing your images. Meanwhile you can visit your %1$shomepage%2$s and check how our plugin performs. ', 'optimole-wp' ), '<a href="' . esc_url( home_url() ) . '" target="_blank" >', '</a>' ),
853
  'compression' => __( 'Optimization', 'optimole-wp' ),
858
  'small_optimization' => __( '😬 Not that much, just <strong>{ratio}</strong> smaller.', 'optimole-wp' ),
859
  'medium_optimization' => __( '🤓 We are on the right track, <strong>{ratio}</strong> squeezed.', 'optimole-wp' ),
860
  'big_optimization' => __( '❤️❤️❤️ Our moles just nailed it, this one is <strong>{ratio}</strong> smaller. ', 'optimole-wp' ),
861
+ ],
862
+ ];
863
  }
864
 
865
  }
inc/api.php CHANGED
@@ -56,7 +56,7 @@ final class Optml_Api {
56
  if ( $lock === 'yes' ) {
57
  return new WP_Error( 'cache_throttle', __( 'You can clear cache only once per 5 minutes.', 'optimole-wp' ) );
58
  }
59
- return $this->request( '/optml/v1/cache/tokens', 'POST', array( 'token' => $token ) );
60
  }
61
 
62
  /**
@@ -68,13 +68,13 @@ final class Optml_Api {
68
  *
69
  * @return array|boolean Api data.
70
  */
71
- private function request( $path, $method = 'GET', $params = array(), $extra_headers = [] ) {
72
 
73
  // Grab the url to which we'll be making the request.
74
  $url = $this->api_root;
75
- $headers = array(
76
  'Optml-Site' => get_home_url(),
77
- );
78
  if ( ! empty( $this->api_key ) ) {
79
  $headers['Authorization'] = 'Bearer ' . $this->api_key;
80
  }
@@ -85,7 +85,7 @@ final class Optml_Api {
85
  // If there is a extra, add that as a url var.
86
  if ( 'GET' === $method && ! empty( $params ) ) {
87
  foreach ( $params as $key => $val ) {
88
- $url = add_query_arg( array( $key => $val ), $url );
89
  }
90
  }
91
  $url = trailingslashit( $this->api_root ) . ltrim( $path, '/' );
@@ -129,13 +129,13 @@ final class Optml_Api {
129
  * @return array
130
  */
131
  private function build_args( $method, $url, $headers, $params ) {
132
- $args = array(
133
  'method' => $method,
134
  'timeout' => 45,
135
  'user-agent' => 'Optimle WP (v' . OPTML_VERSION . ') ',
136
  'sslverify' => false,
137
  'headers' => $headers,
138
- );
139
  if ( $method !== 'GET' ) {
140
  $args['body'] = $params;
141
  }
@@ -154,11 +154,11 @@ final class Optml_Api {
154
  return $this->request(
155
  'optml/v1/user/register-remote',
156
  'POST',
157
- array(
158
  'email' => $email,
159
  'version' => OPTML_VERSION,
160
  'site' => get_home_url(),
161
- )
162
  );
163
  }
164
 
@@ -205,7 +205,7 @@ final class Optml_Api {
205
  $this->api_key = $api_key;
206
  }
207
 
208
- return $this->request( '/optml/v1/settings/watermark', 'DELETE', array( 'watermark' => $post_id ) );
209
  }
210
 
211
  /**
56
  if ( $lock === 'yes' ) {
57
  return new WP_Error( 'cache_throttle', __( 'You can clear cache only once per 5 minutes.', 'optimole-wp' ) );
58
  }
59
+ return $this->request( '/optml/v1/cache/tokens', 'POST', [ 'token' => $token ] );
60
  }
61
 
62
  /**
68
  *
69
  * @return array|boolean Api data.
70
  */
71
+ private function request( $path, $method = 'GET', $params = [], $extra_headers = [] ) {
72
 
73
  // Grab the url to which we'll be making the request.
74
  $url = $this->api_root;
75
+ $headers = [
76
  'Optml-Site' => get_home_url(),
77
+ ];
78
  if ( ! empty( $this->api_key ) ) {
79
  $headers['Authorization'] = 'Bearer ' . $this->api_key;
80
  }
85
  // If there is a extra, add that as a url var.
86
  if ( 'GET' === $method && ! empty( $params ) ) {
87
  foreach ( $params as $key => $val ) {
88
+ $url = add_query_arg( [ $key => $val ], $url );
89
  }
90
  }
91
  $url = trailingslashit( $this->api_root ) . ltrim( $path, '/' );
129
  * @return array
130
  */
131
  private function build_args( $method, $url, $headers, $params ) {
132
+ $args = [
133
  'method' => $method,
134
  'timeout' => 45,
135
  'user-agent' => 'Optimle WP (v' . OPTML_VERSION . ') ',
136
  'sslverify' => false,
137
  'headers' => $headers,
138
+ ];
139
  if ( $method !== 'GET' ) {
140
  $args['body'] = $params;
141
  }
154
  return $this->request(
155
  'optml/v1/user/register-remote',
156
  'POST',
157
+ [
158
  'email' => $email,
159
  'version' => OPTML_VERSION,
160
  'site' => get_home_url(),
161
+ ]
162
  );
163
  }
164
 
205
  $this->api_key = $api_key;
206
  }
207
 
208
+ return $this->request( '/optml/v1/settings/watermark', 'DELETE', [ 'watermark' => $post_id ] );
209
  }
210
 
211
  /**
inc/app_replacer.php CHANGED
@@ -19,13 +19,13 @@ abstract class Optml_App_Replacer {
19
  *
20
  * @var array
21
  */
22
- protected static $image_sizes = array();
23
  /**
24
  * Holds width/height to crop array based on possible image sizes.
25
  *
26
  * @var array
27
  */
28
- protected static $size_to_crop = array();
29
  /**
30
  * Holds possible src attributes.
31
  *
@@ -92,19 +92,19 @@ abstract class Optml_App_Replacer {
92
  *
93
  * @var array Domains.
94
  */
95
- protected $possible_sources = array();
96
  /**
97
  * Possible custom sizes definitions.
98
  *
99
  * @var array Custom sizes definitions.
100
  */
101
- private static $custom_size_buffer = array();
102
  /**
103
  * Whitelisted domains sources to optimize from, according to optimole service.
104
  *
105
  * @var array Domains.
106
  */
107
- protected $allowed_sources = array();
108
 
109
  /**
110
  * Holds site mapping array,
@@ -113,13 +113,13 @@ abstract class Optml_App_Replacer {
113
  *
114
  * @var array Site mappings.
115
  */
116
- protected $site_mappings = array();
117
  /**
118
  * Whether the site is whitelisted or not. Used when signing the urls.
119
  *
120
  * @var bool Domains.
121
  */
122
- protected $is_allowed_site = array();
123
 
124
  /**
125
  * Holds the most recent value for the cache buster.
@@ -133,7 +133,7 @@ abstract class Optml_App_Replacer {
133
  *
134
  * @var array
135
  */
136
- protected static $ignored_url_map = array();
137
 
138
  /**
139
  * Returns possible src attributes.
@@ -142,7 +142,7 @@ abstract class Optml_App_Replacer {
142
  */
143
  public static function possible_src_attributes() {
144
 
145
- if ( null != self::$possible_src_attributes && is_array( self::$possible_src_attributes ) ) {
146
  return self::$possible_src_attributes;
147
  }
148
 
@@ -158,7 +158,7 @@ abstract class Optml_App_Replacer {
158
  */
159
  public static function possible_lazyload_flags() {
160
 
161
- if ( null != self::$ignore_lazyload_strings && is_array( self::$ignore_lazyload_strings ) ) {
162
  return self::$ignore_lazyload_strings;
163
  }
164
 
@@ -173,7 +173,7 @@ abstract class Optml_App_Replacer {
173
  */
174
  public static function possible_tag_flags() {
175
 
176
- if ( null != self::$ignore_tag_strings && is_array( self::$ignore_tag_strings ) ) {
177
  return self::$ignore_tag_strings;
178
  }
179
 
@@ -188,7 +188,7 @@ abstract class Optml_App_Replacer {
188
  */
189
  public static function possible_data_ignore_flags() {
190
 
191
- if ( null != self::$ignore_data_opt_attribute && is_array( self::$ignore_data_opt_attribute ) ) {
192
  return self::$ignore_data_opt_attribute;
193
  }
194
 
@@ -203,7 +203,7 @@ abstract class Optml_App_Replacer {
203
  * @return array Size mapping.
204
  */
205
  protected static function size_to_crop() {
206
- if ( null != self::$size_to_crop && is_array( self::$size_to_crop ) ) {
207
  return self::$size_to_crop;
208
  }
209
 
@@ -250,35 +250,35 @@ abstract class Optml_App_Replacer {
250
  */
251
  protected static function image_sizes() {
252
 
253
- if ( null != self::$image_sizes && is_array( self::$image_sizes ) ) {
254
  return self::$image_sizes;
255
  }
256
 
257
  global $_wp_additional_image_sizes;
258
 
259
  // Populate an array matching the data structure of $_wp_additional_image_sizes so we have a consistent structure for image sizes
260
- $images = array(
261
- 'thumb' => array(
262
  'width' => intval( get_option( 'thumbnail_size_w' ) ),
263
  'height' => intval( get_option( 'thumbnail_size_h' ) ),
264
  'crop' => (bool) get_option( 'thumbnail_crop', false ),
265
- ),
266
- 'medium' => array(
267
  'width' => intval( get_option( 'medium_size_w' ) ),
268
  'height' => intval( get_option( 'medium_size_h' ) ),
269
  'crop' => false,
270
- ),
271
- 'large' => array(
272
  'width' => intval( get_option( 'large_size_w' ) ),
273
  'height' => intval( get_option( 'large_size_h' ) ),
274
  'crop' => false,
275
- ),
276
- 'full' => array(
277
  'width' => null,
278
  'height' => null,
279
  'crop' => false,
280
- ),
281
- );
282
 
283
  // Compatibility mapping as found in wp-includes/media.php
284
  $images['thumbnail'] = $images['thumb'];
@@ -304,7 +304,7 @@ abstract class Optml_App_Replacer {
304
  self::$image_sizes
305
  );
306
 
307
- return is_array( self::$image_sizes ) ? self::$image_sizes : array();
308
  }
309
 
310
  /**
@@ -317,7 +317,7 @@ abstract class Optml_App_Replacer {
317
  self::$filters = $this->settings->get_filters();
318
  add_filter(
319
  'optml_possible_lazyload_flags',
320
- function ( $strings = array() ) {
321
  foreach ( self::$filters[ Optml_Settings::FILTER_TYPE_LAZYLOAD ][ Optml_Settings::FILTER_CLASS ] as $rule_flag => $status ) {
322
  $strings[] = $rule_flag;
323
  }
@@ -329,7 +329,7 @@ abstract class Optml_App_Replacer {
329
  );
330
  add_filter(
331
  'optml_skip_optimizations_css_classes',
332
- function ( $strings = array() ) {
333
  foreach ( self::$filters[ Optml_Settings::FILTER_TYPE_OPTIMIZE ][ Optml_Settings::FILTER_CLASS ] as $rule_flag => $status ) {
334
  $strings[] = $rule_flag;
335
  }
@@ -347,10 +347,10 @@ abstract class Optml_App_Replacer {
347
  public function set_properties() {
348
 
349
  $upload_data = wp_upload_dir();
350
- $this->upload_resource = array(
351
- 'url' => str_replace( array( 'https://', 'http://' ), '', $upload_data['baseurl'] ),
352
  'directory' => $upload_data['basedir'],
353
- );
354
  $this->upload_resource['url_length'] = strlen( $this->upload_resource['url'] );
355
 
356
  $content_parts = parse_url( content_url() );
@@ -363,10 +363,10 @@ abstract class Optml_App_Replacer {
363
  $service_data = $this->settings->get( 'service_data' );
364
 
365
  Optml_Config::init(
366
- array(
367
  'key' => $service_data['cdn_key'],
368
  'secret' => $service_data['cdn_secret'],
369
- )
370
  );
371
 
372
  if ( defined( 'OPTML_SITE_MIRROR' ) && constant( 'OPTML_SITE_MIRROR' ) ) {
@@ -375,7 +375,7 @@ abstract class Optml_App_Replacer {
375
 
376
  $this->possible_sources = $this->extract_domain_from_urls(
377
  array_merge(
378
- array( get_home_url() ),
379
  array_values( $this->site_mappings ),
380
  array_keys( $this->site_mappings )
381
  )
@@ -438,7 +438,7 @@ abstract class Optml_App_Replacer {
438
  *
439
  * @return array Array of domains as keys.
440
  */
441
- protected function extract_domain_from_urls( $urls = array() ) {
442
  if ( ! is_array( $urls ) ) {
443
  return [];
444
  }
@@ -526,17 +526,17 @@ abstract class Optml_App_Replacer {
526
  * @return array An array consisting of width and height.
527
  */
528
  protected function parse_dimensions_from_filename( $src ) {
529
- $width_height_string = array();
530
  $extensions = array_keys( Optml_Config::$image_extensions );
531
  if ( preg_match( '#-(\d+)x(\d+)(:?_c)?\.(?:' . implode( '|', $extensions ) . '){1}$#i', $src, $width_height_string ) ) {
532
  $width = (int) $width_height_string[1];
533
  $height = (int) $width_height_string[2];
534
  $crop = ( isset( $width_height_string[3] ) && $width_height_string[3] === '_c' );
535
  if ( $width && $height ) {
536
- return array( $width, $height, $crop );
537
  }
538
  }
539
 
540
- return array( false, false, false );
541
  }
542
  }
19
  *
20
  * @var array
21
  */
22
+ protected static $image_sizes = [];
23
  /**
24
  * Holds width/height to crop array based on possible image sizes.
25
  *
26
  * @var array
27
  */
28
+ protected static $size_to_crop = [];
29
  /**
30
  * Holds possible src attributes.
31
  *
92
  *
93
  * @var array Domains.
94
  */
95
+ protected $possible_sources = [];
96
  /**
97
  * Possible custom sizes definitions.
98
  *
99
  * @var array Custom sizes definitions.
100
  */
101
+ private static $custom_size_buffer = [];
102
  /**
103
  * Whitelisted domains sources to optimize from, according to optimole service.
104
  *
105
  * @var array Domains.
106
  */
107
+ protected $allowed_sources = [];
108
 
109
  /**
110
  * Holds site mapping array,
113
  *
114
  * @var array Site mappings.
115
  */
116
+ protected $site_mappings = [];
117
  /**
118
  * Whether the site is whitelisted or not. Used when signing the urls.
119
  *
120
  * @var bool Domains.
121
  */
122
+ protected $is_allowed_site = [];
123
 
124
  /**
125
  * Holds the most recent value for the cache buster.
133
  *
134
  * @var array
135
  */
136
+ protected static $ignored_url_map = [];
137
 
138
  /**
139
  * Returns possible src attributes.
142
  */
143
  public static function possible_src_attributes() {
144
 
145
+ if ( ! empty( self::$possible_src_attributes ) && is_array( self::$possible_src_attributes ) ) {
146
  return self::$possible_src_attributes;
147
  }
148
 
158
  */
159
  public static function possible_lazyload_flags() {
160
 
161
+ if ( ! empty( self::$ignore_lazyload_strings ) && is_array( self::$ignore_lazyload_strings ) ) {
162
  return self::$ignore_lazyload_strings;
163
  }
164
 
173
  */
174
  public static function possible_tag_flags() {
175
 
176
+ if ( ! empty( self::$ignore_tag_strings ) && is_array( self::$ignore_tag_strings ) ) {
177
  return self::$ignore_tag_strings;
178
  }
179
 
188
  */
189
  public static function possible_data_ignore_flags() {
190
 
191
+ if ( ! empty( self::$ignore_data_opt_attribute ) && is_array( self::$ignore_data_opt_attribute ) ) {
192
  return self::$ignore_data_opt_attribute;
193
  }
194
 
203
  * @return array Size mapping.
204
  */
205
  protected static function size_to_crop() {
206
+ if ( ! empty( self::$size_to_crop ) && is_array( self::$size_to_crop ) ) {
207
  return self::$size_to_crop;
208
  }
209
 
250
  */
251
  protected static function image_sizes() {
252
 
253
+ if ( ! empty( self::$image_sizes ) && is_array( self::$image_sizes ) ) {
254
  return self::$image_sizes;
255
  }
256
 
257
  global $_wp_additional_image_sizes;
258
 
259
  // Populate an array matching the data structure of $_wp_additional_image_sizes so we have a consistent structure for image sizes
260
+ $images = [
261
+ 'thumb' => [
262
  'width' => intval( get_option( 'thumbnail_size_w' ) ),
263
  'height' => intval( get_option( 'thumbnail_size_h' ) ),
264
  'crop' => (bool) get_option( 'thumbnail_crop', false ),
265
+ ],
266
+ 'medium' => [
267
  'width' => intval( get_option( 'medium_size_w' ) ),
268
  'height' => intval( get_option( 'medium_size_h' ) ),
269
  'crop' => false,
270
+ ],
271
+ 'large' => [
272
  'width' => intval( get_option( 'large_size_w' ) ),
273
  'height' => intval( get_option( 'large_size_h' ) ),
274
  'crop' => false,
275
+ ],
276
+ 'full' => [
277
  'width' => null,
278
  'height' => null,
279
  'crop' => false,
280
+ ],
281
+ ];
282
 
283
  // Compatibility mapping as found in wp-includes/media.php
284
  $images['thumbnail'] = $images['thumb'];
304
  self::$image_sizes
305
  );
306
 
307
+ return is_array( self::$image_sizes ) ? self::$image_sizes : [];
308
  }
309
 
310
  /**
317
  self::$filters = $this->settings->get_filters();
318
  add_filter(
319
  'optml_possible_lazyload_flags',
320
+ function ( $strings = [] ) {
321
  foreach ( self::$filters[ Optml_Settings::FILTER_TYPE_LAZYLOAD ][ Optml_Settings::FILTER_CLASS ] as $rule_flag => $status ) {
322
  $strings[] = $rule_flag;
323
  }
329
  );
330
  add_filter(
331
  'optml_skip_optimizations_css_classes',
332
+ function ( $strings = [] ) {
333
  foreach ( self::$filters[ Optml_Settings::FILTER_TYPE_OPTIMIZE ][ Optml_Settings::FILTER_CLASS ] as $rule_flag => $status ) {
334
  $strings[] = $rule_flag;
335
  }
347
  public function set_properties() {
348
 
349
  $upload_data = wp_upload_dir();
350
+ $this->upload_resource = [
351
+ 'url' => str_replace( [ 'https://', 'http://' ], '', $upload_data['baseurl'] ),
352
  'directory' => $upload_data['basedir'],
353
+ ];
354
  $this->upload_resource['url_length'] = strlen( $this->upload_resource['url'] );
355
 
356
  $content_parts = parse_url( content_url() );
363
  $service_data = $this->settings->get( 'service_data' );
364
 
365
  Optml_Config::init(
366
+ [
367
  'key' => $service_data['cdn_key'],
368
  'secret' => $service_data['cdn_secret'],
369
+ ]
370
  );
371
 
372
  if ( defined( 'OPTML_SITE_MIRROR' ) && constant( 'OPTML_SITE_MIRROR' ) ) {
375
 
376
  $this->possible_sources = $this->extract_domain_from_urls(
377
  array_merge(
378
+ [ get_home_url() ],
379
  array_values( $this->site_mappings ),
380
  array_keys( $this->site_mappings )
381
  )
438
  *
439
  * @return array Array of domains as keys.
440
  */
441
+ protected function extract_domain_from_urls( $urls = [] ) {
442
  if ( ! is_array( $urls ) ) {
443
  return [];
444
  }
526
  * @return array An array consisting of width and height.
527
  */
528
  protected function parse_dimensions_from_filename( $src ) {
529
+ $width_height_string = [];
530
  $extensions = array_keys( Optml_Config::$image_extensions );
531
  if ( preg_match( '#-(\d+)x(\d+)(:?_c)?\.(?:' . implode( '|', $extensions ) . '){1}$#i', $src, $width_height_string ) ) {
532
  $width = (int) $width_height_string[1];
533
  $height = (int) $width_height_string[2];
534
  $crop = ( isset( $width_height_string[3] ) && $width_height_string[3] === '_c' );
535
  if ( $width && $height ) {
536
+ return [ $width, $height, $crop ];
537
  }
538
  }
539
 
540
+ return [ false, false, false ];
541
  }
542
  }
inc/asset.php CHANGED
@@ -51,7 +51,7 @@ class Optml_Asset extends Optml_Resource {
51
  *
52
  * @throws \InvalidArgumentException In case that the url is not provided.
53
  */
54
- public function __construct( $url = '', $args = array(), $cache_buster = '', $minify_css = 1, $minify_js = 0 ) {
55
  parent::__construct( $url, $cache_buster );
56
 
57
  $this->minify_css = $minify_css;
@@ -88,7 +88,7 @@ class Optml_Asset extends Optml_Resource {
88
  * @return string Transformed asset url.
89
  */
90
  public function get_url( $params = [] ) {
91
- $path_parts = array();
92
  if ( ! empty( $this->type ) ) {
93
  $path_parts[] = 'f:' . $this->type;
94
  }
51
  *
52
  * @throws \InvalidArgumentException In case that the url is not provided.
53
  */
54
+ public function __construct( $url = '', $args = [], $cache_buster = '', $minify_css = 1, $minify_js = 0 ) {
55
  parent::__construct( $url, $cache_buster );
56
 
57
  $this->minify_css = $minify_css;
88
  * @return string Transformed asset url.
89
  */
90
  public function get_url( $params = [] ) {
91
+ $path_parts = [];
92
  if ( ! empty( $this->type ) ) {
93
  $path_parts[] = 'f:' . $this->type;
94
  }
inc/cli.php CHANGED
@@ -27,9 +27,9 @@ class Optml_Cli {
27
  *
28
  * @var array List of CLI controllers.
29
  */
30
- private $commands = array(
31
  'setting',
32
- );
33
 
34
  /**
35
  * Optml_Cli constructor.
27
  *
28
  * @var array List of CLI controllers.
29
  */
30
+ private $commands = [
31
  'setting',
32
+ ];
33
 
34
  /**
35
  * Optml_Cli constructor.
inc/cli/cli_setting.php CHANGED
@@ -11,18 +11,6 @@ if ( ! class_exists( 'WP_CLI' ) ) {
11
  * Class Optml_Cli_Setting
12
  */
13
  class Optml_Cli_Setting extends WP_CLI_Command {
14
- /**
15
- * Holds an array of possible settings to alter.
16
- *
17
- * @var array Whitelisted settings.
18
- */
19
- public static $whitelisted_settings = [
20
- 'image_replacer' => 'bool',
21
- 'quality' => 'int',
22
- 'lazyload' => 'bool',
23
- 'lazyload_placeholder' => 'bool',
24
- ];
25
-
26
  /**
27
  * Connect to service
28
  * <apikey>
@@ -80,29 +68,30 @@ class Optml_Cli_Setting extends WP_CLI_Command {
80
  * : The setting value to update.
81
  */
82
  public function update( $args ) {
83
- if ( empty( $args ) || ! isset( self::$whitelisted_settings[ $args[0] ] ) ) {
84
- \WP_CLI::error( sprintf( 'Setting must be one of: %s', implode( ',', array_keys( self::$whitelisted_settings ) ) ) );
85
 
86
  return false;
87
  }
88
 
89
- if ( self::$whitelisted_settings[ $args[0] ] === 'bool' && ( empty( $args ) || ! isset( $args[1] ) || $args[1] === '' || ! in_array(
90
  $args[1],
91
- array(
92
  'on',
93
  'off',
94
- )
 
95
  ) ) ) {
96
  return \WP_CLI::error( 'No argument passed. Required one argument ( on/off )' );
97
  }
98
 
99
- if ( self::$whitelisted_settings[ $args[0] ] === 'int' && ( empty( $args ) || ! isset( $args[1] ) || $args[1] === '' || (int) $args[1] > 100 || (int) $args[1] < 0 ) ) {
100
  return \WP_CLI::error( 'Invalid argument, must be between 0 and 100.' );
101
  }
102
 
103
- $value = ( self::$whitelisted_settings[ $args[0] ] === 'bool' ) ? ( $args[1] === 'on' ? 'enabled' : 'disabled' ) : (int) $args[1];
104
 
105
- $new_value = $this->update_setting( array( $args[0] => $value ) );
106
  \WP_CLI::success( sprintf( 'Setting %s updated to: %s', $args[0], $new_value[ $args[0] ] ) );
107
  }
108
 
@@ -113,8 +102,8 @@ class Optml_Cli_Setting extends WP_CLI_Command {
113
  * : The setting name to check.
114
  */
115
  public function get( $args ) {
116
- if ( empty( $args ) || ! isset( self::$whitelisted_settings[ $args[0] ] ) ) {
117
- \WP_CLI::error( sprintf( 'Setting must be one of: %s', implode( ',', array_keys( self::$whitelisted_settings ) ) ) );
118
 
119
  return false;
120
  }
11
  * Class Optml_Cli_Setting
12
  */
13
  class Optml_Cli_Setting extends WP_CLI_Command {
 
 
 
 
 
 
 
 
 
 
 
 
14
  /**
15
  * Connect to service
16
  * <apikey>
68
  * : The setting value to update.
69
  */
70
  public function update( $args ) {
71
+ if ( empty( $args ) || ! isset( Optml_Settings::$whitelisted_settings[ $args[0] ] ) ) {
72
+ \WP_CLI::error( sprintf( 'Setting must be one of: %s', implode( ',', array_keys( Optml_Settings::$whitelisted_settings ) ) ) );
73
 
74
  return false;
75
  }
76
 
77
+ if ( Optml_Settings::$whitelisted_settings[ $args[0] ] === 'bool' && ( empty( $args ) || ! isset( $args[1] ) || $args[1] === '' || ! in_array(
78
  $args[1],
79
+ [
80
  'on',
81
  'off',
82
+ ],
83
+ true
84
  ) ) ) {
85
  return \WP_CLI::error( 'No argument passed. Required one argument ( on/off )' );
86
  }
87
 
88
+ if ( Optml_Settings::$whitelisted_settings[ $args[0] ] === 'int' && ( empty( $args ) || ! isset( $args[1] ) || $args[1] === '' || (int) $args[1] > 100 || (int) $args[1] < 0 ) ) {
89
  return \WP_CLI::error( 'Invalid argument, must be between 0 and 100.' );
90
  }
91
 
92
+ $value = ( Optml_Settings::$whitelisted_settings[ $args[0] ] === 'bool' ) ? ( $args[1] === 'on' ? 'enabled' : 'disabled' ) : (int) $args[1];
93
 
94
+ $new_value = $this->update_setting( [ $args[0] => $value ] );
95
  \WP_CLI::success( sprintf( 'Setting %s updated to: %s', $args[0], $new_value[ $args[0] ] ) );
96
  }
97
 
102
  * : The setting name to check.
103
  */
104
  public function get( $args ) {
105
+ if ( empty( $args ) || ! isset( Optml_Settings::$whitelisted_settings[ $args[0] ] ) ) {
106
+ \WP_CLI::error( sprintf( 'Setting must be one of: %s', implode( ',', array_keys( Optml_Settings::$whitelisted_settings ) ) ) );
107
 
108
  return false;
109
  }
inc/compatibilities/compatibility.php CHANGED
@@ -14,4 +14,12 @@ abstract class Optml_compatibility {
14
  * @return bool Compatiblity
15
  */
16
  abstract function should_load();
 
 
 
 
 
 
 
 
17
  }
14
  * @return bool Compatiblity
15
  */
16
  abstract function should_load();
17
+ /**
18
+ * Should we early load the compatibility?
19
+ *
20
+ * @return bool Whether to load the compatibility or not.
21
+ */
22
+ public function should_load_early() {
23
+ return false;
24
+ }
25
  }
inc/compatibilities/divi_builder.php CHANGED
@@ -32,6 +32,7 @@ class Optml_divi_builder extends Optml_compatibility {
32
  $all_watchers[] = '.et_pb_video_overlay';
33
  $all_watchers[] = '.et_pb_module:not(.et_pb_blog_grid_wrapper)';
34
  $all_watchers[] = '.et_pb_row';
 
35
  $all_watchers[] = '.et_pb_with_background';
36
  return $all_watchers;
37
  }
32
  $all_watchers[] = '.et_pb_video_overlay';
33
  $all_watchers[] = '.et_pb_module:not(.et_pb_blog_grid_wrapper)';
34
  $all_watchers[] = '.et_pb_row';
35
+ $all_watchers[] = '.et_pb_section.et_pb_section_1';
36
  $all_watchers[] = '.et_pb_with_background';
37
  return $all_watchers;
38
  }
inc/compatibilities/envira.php CHANGED
@@ -37,8 +37,8 @@ class Optml_envira extends Optml_compatibility {
37
  * @return string Original url.
38
  */
39
  function revert_src( $image ) {
40
-
41
- if ( ( $pos = strpos( $image, '/http' ) ) !== false ) {
42
  return ltrim( substr( $image, $pos ), '/' );
43
  }
44
 
@@ -71,7 +71,7 @@ class Optml_envira extends Optml_compatibility {
71
  *
72
  * @return array New flags.
73
  */
74
- function add_lazyflag( $strings = array() ) {
75
 
76
  $strings[] = 'envira-gallery-image';
77
 
37
  * @return string Original url.
38
  */
39
  function revert_src( $image ) {
40
+ $pos = strpos( $image, '/http' );
41
+ if ( $pos !== false ) {
42
  return ltrim( substr( $image, $pos ), '/' );
43
  }
44
 
71
  *
72
  * @return array New flags.
73
  */
74
+ function add_lazyflag( $strings = [] ) {
75
 
76
  $strings[] = 'envira-gallery-image';
77
 
inc/compatibilities/foogallery.php CHANGED
@@ -34,7 +34,7 @@ class Optml_foogallery extends Optml_compatibility {
34
  *
35
  * @return array New src attributes.
36
  */
37
- function add_lazysrc( $attributes = array() ) {
38
 
39
  $attributes[] = 'data-src-fg';
40
 
34
  *
35
  * @return array New src attributes.
36
  */
37
+ function add_lazysrc( $attributes = [] ) {
38
 
39
  $attributes[] = 'data-src-fg';
40
 
inc/compatibilities/give_wp.php CHANGED
@@ -37,7 +37,7 @@ class Optml_give_wp extends Optml_compatibility {
37
  * @return bool If we should lazyload the page.
38
  */
39
  public function check_givewp_page( $old_value ) {
40
- if ( array_key_exists( 'giveDonationFormInIframe', $_GET ) && $_GET['giveDonationFormInIframe'] == '1' ) {
41
  return true;
42
  }
43
  return $old_value;
@@ -50,7 +50,7 @@ class Optml_give_wp extends Optml_compatibility {
50
  *
51
  * @return array New flags.
52
  */
53
- public function add_ignore_lazyload_iframe( $flags = array() ) {
54
  $flags[] = 'give-embed-form';
55
  return $flags;
56
  }
37
  * @return bool If we should lazyload the page.
38
  */
39
  public function check_givewp_page( $old_value ) {
40
+ if ( array_key_exists( 'giveDonationFormInIframe', $_GET ) && $_GET['giveDonationFormInIframe'] === '1' ) {
41
  return true;
42
  }
43
  return $old_value;
50
  *
51
  * @return array New flags.
52
  */
53
+ public function add_ignore_lazyload_iframe( $flags = [] ) {
54
  $flags[] = 'give-embed-form';
55
  return $flags;
56
  }
inc/compatibilities/jet_elements.php CHANGED
@@ -34,7 +34,7 @@ class Optml_jet_elements extends Optml_compatibility {
34
  *
35
  * @return array New flags.
36
  */
37
- public function add_ignore_lazyload( $flags = array() ) {
38
  $flags[] = 'sp-image';
39
 
40
  return $flags;
34
  *
35
  * @return array New flags.
36
  */
37
+ public function add_ignore_lazyload( $flags = [] ) {
38
  $flags[] = 'sp-image';
39
 
40
  return $flags;
inc/compatibilities/metaslider.php CHANGED
@@ -57,7 +57,7 @@ class Optml_metaslider extends Optml_compatibility {
57
  *
58
  * @return array New flags.
59
  */
60
- public function add_ignore_lazyload( $flags = array() ) {
61
  $flags[] = 'no-optml-lazyload';
62
 
63
  return $flags;
@@ -84,7 +84,7 @@ class Optml_metaslider extends Optml_compatibility {
84
  *
85
  * @return array New flags.
86
  */
87
- public function add_noscript_flags( $flags = array() ) {
88
  $flags[] = 'slide-';
89
 
90
  return $flags;
57
  *
58
  * @return array New flags.
59
  */
60
+ public function add_ignore_lazyload( $flags = [] ) {
61
  $flags[] = 'no-optml-lazyload';
62
 
63
  return $flags;
84
  *
85
  * @return array New flags.
86
  */
87
+ public function add_noscript_flags( $flags = [] ) {
88
  $flags[] = 'slide-';
89
 
90
  return $flags;
inc/compatibilities/pinterest.php CHANGED
@@ -22,16 +22,16 @@ class Optml_pinterest extends Optml_compatibility {
22
  include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
23
 
24
  $load = false;
25
- $selectorsArray = array();
26
  if ( $this->isShareaholic() ) {
27
- $selectorsArray[] = 'li.shareaholic-share-button[data-service=\"pinterest\"]';
28
  $load = true;
29
  }
30
  if ( $this->isSassySocialShare() ) {
31
- $selectorsArray[] = '.heateorSssSharing.heateorSssPinterestBackground';
32
  $load = true;
33
  }
34
- $this->selectors = implode( ', ', array_filter( $selectorsArray ) );
35
  return $load;
36
  }
37
 
22
  include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
23
 
24
  $load = false;
25
+ $selectors_array = [];
26
  if ( $this->isShareaholic() ) {
27
+ $selectors_array[] = 'li.shareaholic-share-button[data-service=\"pinterest\"]';
28
  $load = true;
29
  }
30
  if ( $this->isSassySocialShare() ) {
31
+ $selectors_array[] = '.heateorSssSharing.heateorSssPinterestBackground';
32
  $load = true;
33
  }
34
+ $this->selectors = implode( ', ', array_filter( $selectors_array ) );
35
  return $load;
36
  }
37
 
inc/compatibilities/revslider.php CHANGED
@@ -35,7 +35,7 @@ class Optml_revslider extends Optml_compatibility {
35
  *
36
  * @return array New flags.
37
  */
38
- function add_lazyflag( $strings = array() ) {
39
 
40
  $strings[] = 'rev-slidebg';
41
 
@@ -49,7 +49,7 @@ class Optml_revslider extends Optml_compatibility {
49
  *
50
  * @return array New classes.
51
  */
52
- public function add_bg_class( $classes = array() ) {
53
  $classes[] = 'tp-bgimg';
54
 
55
  return $classes;
@@ -62,7 +62,7 @@ class Optml_revslider extends Optml_compatibility {
62
  *
63
  * @return array New flags.
64
  */
65
- public function add_data_ignore( $flags = array() ) {
66
  $flags[] = 'rev-slidebg';
67
 
68
  return $flags;
35
  *
36
  * @return array New flags.
37
  */
38
+ function add_lazyflag( $strings = [] ) {
39
 
40
  $strings[] = 'rev-slidebg';
41
 
49
  *
50
  * @return array New classes.
51
  */
52
+ public function add_bg_class( $classes = [] ) {
53
  $classes[] = 'tp-bgimg';
54
 
55
  return $classes;
62
  *
63
  * @return array New flags.
64
  */
65
+ public function add_data_ignore( $flags = [] ) {
66
  $flags[] = 'rev-slidebg';
67
 
68
  return $flags;
inc/compatibilities/sg_optimizer.php CHANGED
@@ -24,10 +24,10 @@ class Optml_sg_optimizer extends Optml_compatibility {
24
  public function register() {
25
  add_action(
26
  'init',
27
- array(
28
  Optml_Main::instance()->manager,
29
  'process_template_redirect_content',
30
- ),
31
  defined( 'OPTML_SITE_MIRROR' ) ? PHP_INT_MAX : PHP_INT_MIN
32
  );
33
  }
24
  public function register() {
25
  add_action(
26
  'init',
27
+ [
28
  Optml_Main::instance()->manager,
29
  'process_template_redirect_content',
30
+ ],
31
  defined( 'OPTML_SITE_MIRROR' ) ? PHP_INT_MAX : PHP_INT_MIN
32
  );
33
  }
inc/compatibilities/shortcode_ultimate.php CHANGED
@@ -70,9 +70,9 @@ class Optml_shortcode_ultimate extends Optml_compatibility {
70
  * @return array New default cropping.
71
  */
72
  public function change_default_crop() {
73
- return array(
74
  'type' => Optml_Resize::RESIZE_FILL,
75
  'gravity' => Optml_Resize::GRAVITY_CENTER,
76
- );
77
  }
78
  }
70
  * @return array New default cropping.
71
  */
72
  public function change_default_crop() {
73
+ return [
74
  'type' => Optml_Resize::RESIZE_FILL,
75
  'gravity' => Optml_Resize::GRAVITY_CENTER,
76
+ ];
77
  }
78
  }
inc/compatibilities/smart_search_woocommerce.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Optml_smart_search_woocommerce.
5
+ *
6
+ * @reason Smart search by searchanise stores the content of the image urls before they are processed.
7
+ */
8
+ class Optml_smart_search_woocommerce 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( 'smart-search-for-woocommerce/woocommerce-searchanise.php' );
18
+ }
19
+
20
+ /**
21
+ * Register integration details.
22
+ */
23
+ public function register() {
24
+ add_filter( 'se_get_product_image_post', [$this, 'filter_image_url'], 1, 3 );
25
+ }
26
+
27
+ /**
28
+ * Process image url before is send to the server.
29
+ *
30
+ * @param string $image_url The original image url.
31
+ * @param int $image_id The image id .
32
+ * @param int $size The image size.
33
+ * @return string
34
+ */
35
+ public function filter_image_url( $image_url, $image_id, $size ) {
36
+ Optml_Url_Replacer::instance()->init();
37
+ return apply_filters( 'optml_content_url', $image_url );
38
+ }
39
+
40
+ /**
41
+ * Should we early load the compatibility?
42
+ *
43
+ * @return bool Whether to load the compatibility or not.
44
+ */
45
+ public function should_load_early() {
46
+ return true;
47
+ }
48
+ }
inc/compatibilities/translate_press.php CHANGED
@@ -24,10 +24,10 @@ class Optml_translate_press extends Optml_compatibility {
24
  public function register() {
25
  add_action(
26
  'init',
27
- array(
28
  Optml_Main::instance()->manager,
29
  'process_template_redirect_content',
30
- ),
31
  defined( 'OPTML_SITE_MIRROR' ) ? PHP_INT_MAX : PHP_INT_MIN
32
  );
33
  }
24
  public function register() {
25
  add_action(
26
  'init',
27
+ [
28
  Optml_Main::instance()->manager,
29
  'process_template_redirect_content',
30
+ ],
31
  defined( 'OPTML_SITE_MIRROR' ) ? PHP_INT_MAX : PHP_INT_MIN
32
  );
33
  }
inc/config.php CHANGED
@@ -13,7 +13,7 @@ class Optml_Config {
13
  *
14
  * @var array
15
  */
16
- public static $image_extensions = array(
17
  'jpg' => 'image/jpeg',
18
  'jpeg' => 'image/jpeg',
19
  'jpe' => 'image/jpeg',
@@ -21,22 +21,22 @@ class Optml_Config {
21
  'webp' => 'image/webp',
22
  'svg' => 'image/svg+xml',
23
  'gif' => 'image/gif',
24
- );
25
  /**
26
  * CSS/Js mimetypes.
27
  *
28
  * @var string[]
29
  */
30
- public static $assets_extensions = array(
31
  'css' => 'text/css',
32
  'js' => 'text/javascript',
33
- );
34
  /**
35
  * All extensions that Optimole process.
36
  *
37
  * @var string[]
38
  */
39
- public static $all_extensions = array(
40
  'jpg|jpeg|jpe' => 'image/jpeg',
41
  'png' => 'image/png',
42
  'webp' => 'image/webp',
@@ -44,7 +44,7 @@ class Optml_Config {
44
  'gif' => 'image/gif',
45
  'css' => 'text/css',
46
  'js' => 'text/javascript',
47
- );
48
  /**
49
  * A string of allowed chars.
50
  *
@@ -78,7 +78,7 @@ class Optml_Config {
78
  *
79
  * @throws \InvalidArgumentException In case that key or secret is not provided.
80
  */
81
- public static function init( $service_settings = array() ) {
82
 
83
  if ( empty( $service_settings['key'] ) && ! defined( 'OPTML_KEY' ) ) {
84
  throw new \InvalidArgumentException( 'Optimole SDK requires service api key.' ); // @codeCoverageIgnore
13
  *
14
  * @var array
15
  */
16
+ public static $image_extensions = [
17
  'jpg' => 'image/jpeg',
18
  'jpeg' => 'image/jpeg',
19
  'jpe' => 'image/jpeg',
21
  'webp' => 'image/webp',
22
  'svg' => 'image/svg+xml',
23
  'gif' => 'image/gif',
24
+ ];
25
  /**
26
  * CSS/Js mimetypes.
27
  *
28
  * @var string[]
29
  */
30
+ public static $assets_extensions = [
31
  'css' => 'text/css',
32
  'js' => 'text/javascript',
33
+ ];
34
  /**
35
  * All extensions that Optimole process.
36
  *
37
  * @var string[]
38
  */
39
+ public static $all_extensions = [
40
  'jpg|jpeg|jpe' => 'image/jpeg',
41
  'png' => 'image/png',
42
  'webp' => 'image/webp',
44
  'gif' => 'image/gif',
45
  'css' => 'text/css',
46
  'js' => 'text/javascript',
47
+ ];
48
  /**
49
  * A string of allowed chars.
50
  *
78
  *
79
  * @throws \InvalidArgumentException In case that key or secret is not provided.
80
  */
81
+ public static function init( $service_settings = [] ) {
82
 
83
  if ( empty( $service_settings['key'] ) && ! defined( 'OPTML_KEY' ) ) {
84
  throw new \InvalidArgumentException( 'Optimole SDK requires service api key.' ); // @codeCoverageIgnore
inc/conflicts/abstract_conflict.php CHANGED
@@ -90,7 +90,7 @@ abstract class Optml_Abstract_Conflict {
90
  * @since 2.0.6
91
  * @access public
92
  */
93
- public function is_active( $dismissed_conflicts = array() ) {
94
  $conflict_id = $this->get_id();
95
  if ( isset( $dismissed_conflicts[ $conflict_id ] ) && $dismissed_conflicts[ $conflict_id ] === 'true' ) {
96
  return false;
@@ -131,12 +131,12 @@ abstract class Optml_Abstract_Conflict {
131
  * @access public
132
  */
133
  public function get_conflict() {
134
- return array(
135
  'id' => $this->get_id(),
136
  'type' => $this->type,
137
  'priority' => $this->priority,
138
  'severity' => $this->severity,
139
  'message' => $this->message,
140
- );
141
  }
142
  }
90
  * @since 2.0.6
91
  * @access public
92
  */
93
+ public function is_active( $dismissed_conflicts = [] ) {
94
  $conflict_id = $this->get_id();
95
  if ( isset( $dismissed_conflicts[ $conflict_id ] ) && $dismissed_conflicts[ $conflict_id ] === 'true' ) {
96
  return false;
131
  * @access public
132
  */
133
  public function get_conflict() {
134
+ return [
135
  'id' => $this->get_id(),
136
  'type' => $this->type,
137
  'priority' => $this->priority,
138
  'severity' => $this->severity,
139
  'message' => $this->message,
140
+ ];
141
  }
142
  }
inc/conflicts/conflict_manager.php CHANGED
@@ -19,7 +19,7 @@ class Optml_Conflict_Manager {
19
  * @access protected
20
  * @var array $watched_conflicts
21
  */
22
- protected $watched_conflicts = array();
23
  /**
24
  * List of conflicts dismissed by user.
25
  *
@@ -27,7 +27,7 @@ class Optml_Conflict_Manager {
27
  * @access protected
28
  * @var array $dismissed_conflicts
29
  */
30
- protected $dismissed_conflicts = array();
31
 
32
 
33
 
@@ -38,8 +38,8 @@ class Optml_Conflict_Manager {
38
  * @access public
39
  * @param array $register_conflicts A list of conflicts to be registered.
40
  */
41
- public function __construct( $register_conflicts = array() ) {
42
- $this->dismissed_conflicts = get_option( 'optml_dismissed_conflicts', array() );
43
  if ( ! empty( $register_conflicts ) ) {
44
  foreach ( $register_conflicts as $conflict_to_watch ) {
45
  $this->watch( $conflict_to_watch );
@@ -82,7 +82,7 @@ class Optml_Conflict_Manager {
82
  * @return array
83
  */
84
  public function get_conflict_list() {
85
- $conflict_list = array();
86
  if ( empty( $this->watched_conflicts ) ) {
87
  return $conflict_list;
88
  }
@@ -108,11 +108,11 @@ class Optml_Conflict_Manager {
108
  if ( ! isset( $item2['severity'] ) ) {
109
  return -1;
110
  }
111
- $severity_map = array(
112
  'high' => 0,
113
  'medium' => 1,
114
  'low' => 1,
115
- );
116
 
117
  if ( $severity_map[ $item1['severity'] ] === $severity_map[ $item2['severity'] ] ) {
118
  if ( ! isset( $item1['priority'] ) ) {
19
  * @access protected
20
  * @var array $watched_conflicts
21
  */
22
+ protected $watched_conflicts = [];
23
  /**
24
  * List of conflicts dismissed by user.
25
  *
27
  * @access protected
28
  * @var array $dismissed_conflicts
29
  */
30
+ protected $dismissed_conflicts = [];
31
 
32
 
33
 
38
  * @access public
39
  * @param array $register_conflicts A list of conflicts to be registered.
40
  */
41
+ public function __construct( $register_conflicts = [] ) {
42
+ $this->dismissed_conflicts = get_option( 'optml_dismissed_conflicts', [] );
43
  if ( ! empty( $register_conflicts ) ) {
44
  foreach ( $register_conflicts as $conflict_to_watch ) {
45
  $this->watch( $conflict_to_watch );
82
  * @return array
83
  */
84
  public function get_conflict_list() {
85
+ $conflict_list = [];
86
  if ( empty( $this->watched_conflicts ) ) {
87
  return $conflict_list;
88
  }
108
  if ( ! isset( $item2['severity'] ) ) {
109
  return -1;
110
  }
111
+ $severity_map = [
112
  'high' => 0,
113
  'medium' => 1,
114
  'low' => 1,
115
+ ];
116
 
117
  if ( $severity_map[ $item1['severity'] ] === $severity_map[ $item2['severity'] ] ) {
118
  if ( ! isset( $item1['priority'] ) ) {
inc/image.php CHANGED
@@ -49,7 +49,7 @@ class Optml_Image extends Optml_Resource {
49
  *
50
  * @throws \InvalidArgumentException In case that the url is not provided.
51
  */
52
- public function __construct( $url = '', $args = array(), $cache_buster = '' ) {
53
  parent::__construct( $url, $cache_buster );
54
 
55
  $this->width->set( $args['width'] );
@@ -82,7 +82,7 @@ class Optml_Image extends Optml_Resource {
82
  * @return string Transformed image url.
83
  */
84
  public function get_url( $params = [] ) {
85
- $path_parts = array();
86
 
87
  $path_parts[] = $this->width->toString();
88
  $path_parts[] = $this->height->toString();
49
  *
50
  * @throws \InvalidArgumentException In case that the url is not provided.
51
  */
52
+ public function __construct( $url = '', $args = [], $cache_buster = '' ) {
53
  parent::__construct( $url, $cache_buster );
54
 
55
  $this->width->set( $args['width'] );
82
  * @return string Transformed image url.
83
  */
84
  public function get_url( $params = [] ) {
85
+ $path_parts = [];
86
 
87
  $path_parts[] = $this->width->toString();
88
  $path_parts[] = $this->height->toString();
inc/image_properties/resize.php CHANGED
@@ -113,7 +113,7 @@ class Optml_Resize extends Optml_Property_Type {
113
  /**
114
  * Optml_Resize constructor.
115
  */
116
- public function __construct( $value = array() ) {
117
  $this->set( $value );
118
  }
119
 
113
  /**
114
  * Optml_Resize constructor.
115
  */
116
+ public function __construct( $value = [] ) {
117
  $this->set( $value );
118
  }
119
 
inc/lazyload_replacer.php CHANGED
@@ -10,7 +10,24 @@ final class Optml_Lazyload_Replacer extends Optml_App_Replacer {
10
  use Optml_Normalizer;
11
  use Optml_Validator;
12
 
 
 
 
 
 
 
 
 
 
 
 
13
  const SVG_PLACEHOLDER = 'data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%20#width#%20#height#%22%20width%3D%22#width#%22%20height%3D%22#height#%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3C%2Fsvg%3E';
 
 
 
 
 
 
14
  /**
15
  * Cached object instance.
16
  *
@@ -66,7 +83,7 @@ final class Optml_Lazyload_Replacer extends Optml_App_Replacer {
66
  public static function instance() {
67
  if ( null === self::$instance ) {
68
  self::$instance = new self();
69
- add_action( 'optml_replacer_setup', array( self::$instance, 'init' ) );
70
  }
71
 
72
  return self::$instance;
@@ -79,7 +96,7 @@ final class Optml_Lazyload_Replacer extends Optml_App_Replacer {
79
  */
80
  public static function get_background_lazyload_selectors() {
81
 
82
- if ( null != self::$background_lazyload_selectors && is_array( self::$background_lazyload_selectors ) ) {
83
  return self::$background_lazyload_selectors;
84
  }
85
  if ( self::instance()->settings->get( 'bg_replacer' ) === 'disabled' ) {
@@ -118,7 +135,7 @@ final class Optml_Lazyload_Replacer extends Optml_App_Replacer {
118
  */
119
  public static function get_lazyload_bg_classes() {
120
 
121
- if ( null != self::$lazyload_background_classes && is_array( self::$lazyload_background_classes ) ) {
122
  return self::$lazyload_background_classes;
123
  }
124
 
@@ -134,7 +151,7 @@ final class Optml_Lazyload_Replacer extends Optml_App_Replacer {
134
  */
135
  public static function get_watcher_lz_classes() {
136
 
137
- if ( null != self::$lazyload_watcher_classes && is_array( self::$lazyload_watcher_classes ) ) {
138
  return self::$lazyload_watcher_classes;
139
  }
140
 
@@ -164,11 +181,19 @@ final class Optml_Lazyload_Replacer extends Optml_App_Replacer {
164
  );
165
  self::$is_lazyload_placeholder = self::$instance->settings->get( 'lazyload_placeholder' ) === 'enabled';
166
 
167
- add_filter( 'optml_tag_replace', array( $this, 'lazyload_tag_replace' ), 2, 6 );
168
 
169
- add_filter( 'optml_video_replace', array($this, 'lazyload_video_replace'), 2, 1 );
170
 
171
  }
 
 
 
 
 
 
 
 
172
 
173
  /**
174
  * Replaces the tags with lazyload tags.
@@ -258,11 +283,11 @@ final class Optml_Lazyload_Replacer extends Optml_App_Replacer {
258
  * @return string
259
  */
260
  public function lazyload_video_replace( $content ) {
261
- $video_tags = array();
262
- preg_match_all( '#(?:<noscript\s*>(\s*|.*?))?<iframe(.*?)></iframe>#is', $content, $video_tags );
263
 
264
- $search = array();
265
- $replace = array();
266
  foreach ( $video_tags[0] as $video_tag ) {
267
  if ( ! $this->should_lazyload_iframe( $video_tag ) ) {
268
  continue;
@@ -279,7 +304,7 @@ final class Optml_Lazyload_Replacer extends Optml_App_Replacer {
279
  $video_tag .= '<noscript>' . $no_script . '</noscript>';
280
  }
281
  array_push( $replace, $video_tag );
282
-
283
  }
284
  $search = array_unique( $search );
285
  $replace = array_unique( $replace );
@@ -423,7 +448,7 @@ final class Optml_Lazyload_Replacer extends Optml_App_Replacer {
423
  */
424
  public static function get_ignore_noscript_flags() {
425
 
426
- if ( null != self::$ignore_no_script_flags && is_array( self::$ignore_no_script_flags ) ) {
427
  return self::$ignore_no_script_flags;
428
  }
429
 
@@ -438,11 +463,11 @@ final class Optml_Lazyload_Replacer extends Optml_App_Replacer {
438
  */
439
  public static function get_iframe_lazyload_flags() {
440
 
441
- if ( null != self::$iframe_lazyload_flags && is_array( self::$iframe_lazyload_flags ) ) {
442
  return self::$iframe_lazyload_flags;
443
  }
444
 
445
- self::$iframe_lazyload_flags = apply_filters( 'optml_iframe_lazyload_flags', [ 'gform_ajax_frame', '<noscript' ] );
446
 
447
  return self::$iframe_lazyload_flags;
448
  }
10
  use Optml_Normalizer;
11
  use Optml_Validator;
12
 
13
+ const IFRAME_PLACEHOLDER_CLASS = '
14
+ iframe[data-opt-src]:not([data-opt-lazy-loaded]) {
15
+ background-color: #ffffff;
16
+ background-image: url("data:image/svg+xml,%3Csvg%20width%3D%2240%22%20height%3D%2240%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20style%3D%22-webkit-transform-origin%3A50%25%2050%25%3B-webkit-animation%3Aspin%201.5s%20linear%20infinite%3B-webkit-backface-visibility%3Ahidden%3Banimation%3Aspin%201.5s%20linear%20infinite%22%20fill-rule%3D%22evenodd%22%20clip-rule%3D%22evenodd%22%20stroke-linejoin%3D%22round%22%20stroke-miterlimit%3D%221.414%22%3E%3Cdefs%3E%3Cstyle%3E%3C%21%5BCDATA%5B%40-webkit-keyframes%20spin%7Bfrom%7B-webkit-transform%3Arotate%280deg%29%7Dto%7B-webkit-transform%3Arotate%28-359deg%29%7D%7D%40keyframes%20spin%7Bfrom%7Btransform%3Arotate%280deg%29%7Dto%7Btransform%3Arotate%28-359deg%29%7D%7D%5D%5D%3E%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22outer%22%3E%3Cpath%20d%3D%22M20%200a3.994%203.994%200%20110%207.988A3.994%203.994%200%200120%200z%22%2F%3E%3Cpath%20d%3D%22M5.858%205.858a3.994%203.994%200%20115.648%205.648%203.994%203.994%200%2001-5.648-5.648z%22%20fill%3D%22%23d2d2d2%22%2F%3E%3Cpath%20d%3D%22M20%2032.012A3.994%203.994%200%201120%2040a3.994%203.994%200%20010-7.988z%22%20fill%3D%22%23828282%22%2F%3E%3Cpath%20d%3D%22M28.494%2028.494a3.994%203.994%200%20115.648%205.648%203.994%203.994%200%2001-5.648-5.648z%22%20fill%3D%22%23656565%22%2F%3E%3Cpath%20d%3D%22M3.994%2016.006a3.994%203.994%200%20110%207.988%203.994%203.994%200%20010-7.988z%22%20fill%3D%22%23bbb%22%2F%3E%3Cpath%20d%3D%22M5.858%2028.494a3.994%203.994%200%20115.648%205.648%203.994%203.994%200%2001-5.648-5.648z%22%20fill%3D%22%23a4a4a4%22%2F%3E%3Cpath%20d%3D%22M36.006%2016.006a3.994%203.994%200%20110%207.988%203.994%203.994%200%20010-7.988z%22%20fill%3D%22%234a4a4a%22%2F%3E%3Cpath%20d%3D%22M28.494%205.858a3.994%203.994%200%20115.648%205.648%203.994%203.994%200%2001-5.648-5.648z%22%20fill%3D%22%23323232%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E");
17
+ background-repeat: no-repeat;
18
+ background-position: 50% 50%;
19
+ }';
20
+ const IFRAME_PLACEHOLDER_STYLE = '<style type="text/css">' . self::IFRAME_PLACEHOLDER_CLASS . '</style>';
21
+
22
+ const IFRAME_TEMP_COMMENT = '/** optmliframelazyloadplaceholder */';
23
+
24
  const SVG_PLACEHOLDER = 'data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%20#width#%20#height#%22%20width%3D%22#width#%22%20height%3D%22#height#%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3C%2Fsvg%3E';
25
+ /**
26
+ * If frame lazyload is present on page.
27
+ *
28
+ * @var bool Whether or not at least one iframe has been lazyloaded.
29
+ */
30
+ private static $found_iframe = false;
31
  /**
32
  * Cached object instance.
33
  *
83
  public static function instance() {
84
  if ( null === self::$instance ) {
85
  self::$instance = new self();
86
+ add_action( 'optml_replacer_setup', [ self::$instance, 'init' ] );
87
  }
88
 
89
  return self::$instance;
96
  */
97
  public static function get_background_lazyload_selectors() {
98
 
99
+ if ( ! empty( self::$background_lazyload_selectors ) && is_array( self::$background_lazyload_selectors ) ) {
100
  return self::$background_lazyload_selectors;
101
  }
102
  if ( self::instance()->settings->get( 'bg_replacer' ) === 'disabled' ) {
135
  */
136
  public static function get_lazyload_bg_classes() {
137
 
138
+ if ( ! empty( self::$lazyload_background_classes ) && is_array( self::$lazyload_background_classes ) ) {
139
  return self::$lazyload_background_classes;
140
  }
141
 
151
  */
152
  public static function get_watcher_lz_classes() {
153
 
154
+ if ( ! empty( self::$lazyload_watcher_classes ) && is_array( self::$lazyload_watcher_classes ) ) {
155
  return self::$lazyload_watcher_classes;
156
  }
157
 
181
  );
182
  self::$is_lazyload_placeholder = self::$instance->settings->get( 'lazyload_placeholder' ) === 'enabled';
183
 
184
+ add_filter( 'optml_tag_replace', [ $this, 'lazyload_tag_replace' ], 2, 6 );
185
 
186
+ add_filter( 'optml_video_replace', [$this, 'lazyload_video_replace'], 2, 1 );
187
 
188
  }
189
+ /**
190
+ * Check if there are lazyloaded iframes.
191
+ *
192
+ * @return bool Whether an iframe was lazyloaded on the page or not.
193
+ */
194
+ public static function found_iframe() {
195
+ return self::$found_iframe;
196
+ }
197
 
198
  /**
199
  * Replaces the tags with lazyload tags.
283
  * @return string
284
  */
285
  public function lazyload_video_replace( $content ) {
286
+ $video_tags = [];
287
+ preg_match_all( '#(?:<noscript\s*>\s*)?<iframe(.*?)></iframe>(?:\s*</noscript\s*>)?#is', $content, $video_tags );
288
 
289
+ $search = [];
290
+ $replace = [];
291
  foreach ( $video_tags[0] as $video_tag ) {
292
  if ( ! $this->should_lazyload_iframe( $video_tag ) ) {
293
  continue;
304
  $video_tag .= '<noscript>' . $no_script . '</noscript>';
305
  }
306
  array_push( $replace, $video_tag );
307
+ self::$found_iframe = true;
308
  }
309
  $search = array_unique( $search );
310
  $replace = array_unique( $replace );
448
  */
449
  public static function get_ignore_noscript_flags() {
450
 
451
+ if ( ! empty( self::$ignore_no_script_flags ) && is_array( self::$ignore_no_script_flags ) ) {
452
  return self::$ignore_no_script_flags;
453
  }
454
 
463
  */
464
  public static function get_iframe_lazyload_flags() {
465
 
466
+ if ( ! empty( self::$iframe_lazyload_flags ) && is_array( self::$iframe_lazyload_flags ) ) {
467
  return self::$iframe_lazyload_flags;
468
  }
469
 
470
+ self::$iframe_lazyload_flags = apply_filters( 'optml_iframe_lazyload_flags', [ 'gform_ajax_frame', '<noscript', 'recaptcha' ] );
471
 
472
  return self::$iframe_lazyload_flags;
473
  }
inc/main.php CHANGED
@@ -55,7 +55,7 @@ final class Optml_Main {
55
  */
56
  public function __construct() {
57
 
58
- register_activation_hook( OPTML_BASEFILE, array( $this, 'activate' ) );
59
  }
60
 
61
  /**
@@ -68,13 +68,13 @@ final class Optml_Main {
68
  */
69
  public static function instance() {
70
  if ( null === self::$_instance ) {
71
- add_filter( 'themeisle_sdk_products', array( __CLASS__, 'register_sdk' ) );
72
- add_filter( 'optimole-wp_uninstall_feedback_icon', array( __CLASS__, 'change_icon' ) );
73
- add_filter( 'optimole_wp_uninstall_feedback_after_css', array( __CLASS__, 'adds_uf_css' ) );
74
- add_filter( 'optimole_wp_feedback_review_message', array( __CLASS__, 'change_review_message' ) );
75
- add_filter( 'optimole_wp_logger_heading', array( __CLASS__, 'change_review_message' ) );
76
- add_filter( 'optml_default_settings', array( __CLASS__, 'change_lazyload_default' ) );
77
- add_filter( 'optml_register_conflicts', array( __CLASS__, 'register_conflicts' ) );
78
  self::$_instance = new self();
79
  self::$_instance->manager = Optml_Manager::instance();
80
  self::$_instance->rest = new Optml_Rest();
@@ -100,10 +100,10 @@ final class Optml_Main {
100
  * @since 2.0.6
101
  * @access public
102
  */
103
- public static function register_conflicts( $conflicts_to_register = array() ) {
104
  $conflicts_to_register = array_merge(
105
  $conflicts_to_register,
106
- array(
107
  'Optml_Elementor',
108
  'Optml_Beaver',
109
  'Optml_Jetpack_Photon',
@@ -111,7 +111,7 @@ final class Optml_Main {
111
  'Optml_Wprocket',
112
  'Optml_Divi',
113
  'Optml_w3_total_cache_cdn',
114
- )
115
  );
116
 
117
  return $conflicts_to_register;
55
  */
56
  public function __construct() {
57
 
58
+ register_activation_hook( OPTML_BASEFILE, [ $this, 'activate' ] );
59
  }
60
 
61
  /**
68
  */
69
  public static function instance() {
70
  if ( null === self::$_instance ) {
71
+ add_filter( 'themeisle_sdk_products', [ __CLASS__, 'register_sdk' ] );
72
+ add_filter( 'optimole-wp_uninstall_feedback_icon', [ __CLASS__, 'change_icon' ] );
73
+ add_filter( 'optimole_wp_uninstall_feedback_after_css', [ __CLASS__, 'adds_uf_css' ] );
74
+ add_filter( 'optimole_wp_feedback_review_message', [ __CLASS__, 'change_review_message' ] );
75
+ add_filter( 'optimole_wp_logger_heading', [ __CLASS__, 'change_review_message' ] );
76
+ add_filter( 'optml_default_settings', [ __CLASS__, 'change_lazyload_default' ] );
77
+ add_filter( 'optml_register_conflicts', [ __CLASS__, 'register_conflicts' ] );
78
  self::$_instance = new self();
79
  self::$_instance->manager = Optml_Manager::instance();
80
  self::$_instance->rest = new Optml_Rest();
100
  * @since 2.0.6
101
  * @access public
102
  */
103
+ public static function register_conflicts( $conflicts_to_register = [] ) {
104
  $conflicts_to_register = array_merge(
105
  $conflicts_to_register,
106
+ [
107
  'Optml_Elementor',
108
  'Optml_Beaver',
109
  'Optml_Jetpack_Photon',
111
  'Optml_Wprocket',
112
  'Optml_Divi',
113
  'Optml_w3_total_cache_cdn',
114
+ ]
115
  );
116
 
117
  return $conflicts_to_register;
inc/manager.php CHANGED
@@ -54,7 +54,7 @@ final class Optml_Manager {
54
  *
55
  * @var array Integrations classes.
56
  */
57
- private $possible_compatibilities = array(
58
  'shortcode_ultimate',
59
  'foogallery',
60
  'envira',
@@ -76,7 +76,8 @@ final class Optml_Manager {
76
  'w3_total_cache',
77
  'translate_press',
78
  'give_wp',
79
- );
 
80
  /**
81
  * The current state of the buffer.
82
  *
@@ -99,7 +100,7 @@ final class Optml_Manager {
99
  self::$instance->url_replacer = Optml_Url_Replacer::instance();
100
  self::$instance->tag_replacer = Optml_Tag_Replacer::instance();
101
  self::$instance->lazyload_replacer = Optml_Lazyload_Replacer::instance();
102
- add_action( 'after_setup_theme', array( self::$instance, 'init' ) );
103
  }
104
 
105
  return self::$instance;
@@ -122,6 +123,10 @@ final class Optml_Manager {
122
  * @var Optml_compatibility $compatibility Class to register.
123
  */
124
  if ( $compatibility->should_load() ) {
 
 
 
 
125
  self::$loaded_compatibilities[ $compatibility_class ] = $compatibility;
126
  }
127
  }
@@ -150,7 +155,7 @@ final class Optml_Manager {
150
  return false; // @codeCoverageIgnore
151
  }
152
 
153
- if ( array_key_exists( 'optml_off', $_GET ) && 'true' == $_GET['optml_off'] ) {
154
  return false; // @codeCoverageIgnore
155
  }
156
  if ( array_key_exists( 'elementor-preview', $_GET ) && ! empty( $_GET['elementor-preview'] ) ) {
@@ -162,13 +167,13 @@ final class Optml_Manager {
162
  if ( array_key_exists( 'et_fb', $_GET ) && ! empty( $_GET['et_fb'] ) ) {
163
  return false; // @codeCoverageIgnore
164
  }
165
- if ( array_key_exists( 'tve', $_GET ) && $_GET['tve'] == 'true' ) {
166
  return false; // @codeCoverageIgnore
167
  }
168
- if ( array_key_exists( 'trp-edit-translation', $_GET ) && ( $_GET['trp-edit-translation'] == 'true' || $_GET['trp-edit-translation'] == 'preview' ) ) {
169
  return false; // @codeCoverageIgnore
170
  }
171
- if ( array_key_exists( 'context', $_GET ) && $_GET['context'] == 'edit' ) {
172
  return false; // @codeCoverageIgnore
173
  }
174
  if ( array_key_exists( 'fb-edit', $_GET ) && ! empty( $_GET['fb-edit'] ) ) {
@@ -179,7 +184,7 @@ final class Optml_Manager {
179
  */
180
  if (
181
  isset( $_SERVER['REQUEST_METHOD'] ) &&
182
- $_SERVER['REQUEST_METHOD'] === 'POST' &&
183
  is_user_logged_in()
184
  && ( ! isset( $_GET['quality'] ) || ! current_user_can( 'manage_options' ) )
185
  ) {
@@ -235,7 +240,7 @@ final class Optml_Manager {
235
  if ( $this->settings->get( 'native_lazyload' ) === 'disabled' ) {
236
  add_filter( 'wp_lazy_loading_enabled', '__return_false' );
237
  }
238
- add_filter( 'the_content', array( $this, 'process_images_from_content' ), PHP_INT_MAX );
239
  /**
240
  * When we have to process cdn images, i.e MIRROR is defined,
241
  * we need this as late as possible for other replacers to occur.
@@ -243,16 +248,16 @@ final class Optml_Manager {
243
  */
244
  add_action(
245
  self::is_ajax_request() ? 'init' : 'template_redirect',
246
- array(
247
  $this,
248
  'process_template_redirect_content',
249
- ),
250
  defined( 'OPTML_SITE_MIRROR' ) ? PHP_INT_MAX : PHP_INT_MIN
251
  );
252
- add_action( 'template_redirect', array( $this, 'register_after_setup' ) );
253
- add_action( 'rest_api_init', array( $this, 'process_template_redirect_content' ), PHP_INT_MIN );
254
 
255
- add_action( 'get_post_metadata', array( $this, 'replace_meta' ), PHP_INT_MAX, 4 );
256
 
257
  foreach ( self::$loaded_compatibilities as $registered_compatibility ) {
258
  $registered_compatibility->register();
@@ -280,11 +285,11 @@ final class Optml_Manager {
280
 
281
  $meta_needed = '_elementor_data';
282
 
283
- if ( isset( $meta_key ) && $meta_needed == $meta_key ) {
284
- remove_filter( 'get_post_metadata', array( $this, 'replace_meta' ), PHP_INT_MAX );
285
 
286
  $current_meta = get_post_meta( $object_id, $meta_needed, $single );
287
- add_filter( 'get_post_metadata', array( $this, 'replace_meta' ), PHP_INT_MAX, 4 );
288
 
289
  if ( ! is_string( $current_meta ) ) {
290
  return $metadata;
@@ -310,10 +315,19 @@ final class Optml_Manager {
310
  return $html;
311
  }
312
 
 
 
313
  $html = $this->process_images_from_content( $html );
314
 
315
  if ( $this->settings->get( 'video_lazyload' ) === 'enabled' ) {
316
  $html = apply_filters( 'optml_video_replace', $html );
 
 
 
 
 
 
 
317
  }
318
 
319
  $html = $this->process_urls_from_content( $html );
@@ -321,6 +335,41 @@ final class Optml_Manager {
321
  return $html;
322
  }
323
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
324
  /**
325
  * Adds a filter with detected images tags and the content.
326
  *
@@ -374,7 +423,7 @@ final class Optml_Manager {
374
  * and img_url keys are arrays of those matches.
375
  */
376
  public static function parse_images_from_html( $content ) {
377
- $images = array();
378
 
379
  $header_start = null;
380
  $header_end = null;
@@ -420,7 +469,7 @@ final class Optml_Manager {
420
  return $images;
421
  }
422
 
423
- return array();
424
  }
425
 
426
  /**
@@ -449,7 +498,7 @@ final class Optml_Manager {
449
  if ( $this->settings->use_cdn() && ! self::should_ignore_image_tags() ) {
450
  $extensions = array_merge( $extensions, array_keys( Optml_Config::$assets_extensions ) );
451
  }
452
- $regex = '/(?:[(|\s\';",=])((?:http|\/|\\\\){1}(?:[' . Optml_Config::$chars . ']{10,}\.(?:' . implode( '|', $extensions ) . ')))(?=(?:|\?|"|&|,|\s|\'|\)|\||\\\\|}))/Uu';
453
  preg_match_all(
454
  $regex,
455
  $content,
@@ -541,10 +590,10 @@ final class Optml_Manager {
541
  }
542
  self::$ob_started = true;
543
  // We no longer need this if the handler was started.
544
- remove_filter( 'the_content', array($this, 'process_images_from_content'), PHP_INT_MAX );
545
 
546
  ob_start(
547
- array(&$this, 'replace_content')
548
  );
549
  }
550
 
54
  *
55
  * @var array Integrations classes.
56
  */
57
+ private $possible_compatibilities = [
58
  'shortcode_ultimate',
59
  'foogallery',
60
  'envira',
76
  'w3_total_cache',
77
  'translate_press',
78
  'give_wp',
79
+ 'smart_search_woocommerce',
80
+ ];
81
  /**
82
  * The current state of the buffer.
83
  *
100
  self::$instance->url_replacer = Optml_Url_Replacer::instance();
101
  self::$instance->tag_replacer = Optml_Tag_Replacer::instance();
102
  self::$instance->lazyload_replacer = Optml_Lazyload_Replacer::instance();
103
+ add_action( 'after_setup_theme', [ self::$instance, 'init' ] );
104
  }
105
 
106
  return self::$instance;
123
  * @var Optml_compatibility $compatibility Class to register.
124
  */
125
  if ( $compatibility->should_load() ) {
126
+ if ( $compatibility->should_load_early() ) {
127
+ $compatibility->register();
128
+ continue;
129
+ }
130
  self::$loaded_compatibilities[ $compatibility_class ] = $compatibility;
131
  }
132
  }
155
  return false; // @codeCoverageIgnore
156
  }
157
 
158
+ if ( array_key_exists( 'optml_off', $_GET ) && 'true' == $_GET['optml_off'] ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
159
  return false; // @codeCoverageIgnore
160
  }
161
  if ( array_key_exists( 'elementor-preview', $_GET ) && ! empty( $_GET['elementor-preview'] ) ) {
167
  if ( array_key_exists( 'et_fb', $_GET ) && ! empty( $_GET['et_fb'] ) ) {
168
  return false; // @codeCoverageIgnore
169
  }
170
+ if ( array_key_exists( 'tve', $_GET ) && $_GET['tve'] == 'true' ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
171
  return false; // @codeCoverageIgnore
172
  }
173
+ if ( array_key_exists( 'trp-edit-translation', $_GET ) && ( $_GET['trp-edit-translation'] == 'true' || $_GET['trp-edit-translation'] == 'preview' ) ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
174
  return false; // @codeCoverageIgnore
175
  }
176
+ if ( array_key_exists( 'context', $_GET ) && $_GET['context'] == 'edit' ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
177
  return false; // @codeCoverageIgnore
178
  }
179
  if ( array_key_exists( 'fb-edit', $_GET ) && ! empty( $_GET['fb-edit'] ) ) {
184
  */
185
  if (
186
  isset( $_SERVER['REQUEST_METHOD'] ) &&
187
+ $_SERVER['REQUEST_METHOD'] == 'POST' && // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
188
  is_user_logged_in()
189
  && ( ! isset( $_GET['quality'] ) || ! current_user_can( 'manage_options' ) )
190
  ) {
240
  if ( $this->settings->get( 'native_lazyload' ) === 'disabled' ) {
241
  add_filter( 'wp_lazy_loading_enabled', '__return_false' );
242
  }
243
+ add_filter( 'the_content', [ $this, 'process_images_from_content' ], PHP_INT_MAX );
244
  /**
245
  * When we have to process cdn images, i.e MIRROR is defined,
246
  * we need this as late as possible for other replacers to occur.
248
  */
249
  add_action(
250
  self::is_ajax_request() ? 'init' : 'template_redirect',
251
+ [
252
  $this,
253
  'process_template_redirect_content',
254
+ ],
255
  defined( 'OPTML_SITE_MIRROR' ) ? PHP_INT_MAX : PHP_INT_MIN
256
  );
257
+ add_action( 'template_redirect', [ $this, 'register_after_setup' ] );
258
+ add_action( 'rest_api_init', [ $this, 'process_template_redirect_content' ], PHP_INT_MIN );
259
 
260
+ add_action( 'get_post_metadata', [ $this, 'replace_meta' ], PHP_INT_MAX, 4 );
261
 
262
  foreach ( self::$loaded_compatibilities as $registered_compatibility ) {
263
  $registered_compatibility->register();
285
 
286
  $meta_needed = '_elementor_data';
287
 
288
+ if ( isset( $meta_key ) && $meta_needed === $meta_key ) {
289
+ remove_filter( 'get_post_metadata', [ $this, 'replace_meta' ], PHP_INT_MAX );
290
 
291
  $current_meta = get_post_meta( $object_id, $meta_needed, $single );
292
+ add_filter( 'get_post_metadata', [ $this, 'replace_meta' ], PHP_INT_MAX, 4 );
293
 
294
  if ( ! is_string( $current_meta ) ) {
295
  return $metadata;
315
  return $html;
316
  }
317
 
318
+ $html = $this->add_html_class( $html );
319
+
320
  $html = $this->process_images_from_content( $html );
321
 
322
  if ( $this->settings->get( 'video_lazyload' ) === 'enabled' ) {
323
  $html = apply_filters( 'optml_video_replace', $html );
324
+ if ( Optml_Lazyload_Replacer::found_iframe() === true ) {
325
+ if ( strpos( $html, Optml_Lazyload_Replacer::IFRAME_TEMP_COMMENT ) !== false ) {
326
+ $html = str_replace( Optml_Lazyload_Replacer::IFRAME_TEMP_COMMENT, Optml_Lazyload_Replacer::IFRAME_PLACEHOLDER_CLASS, $html );
327
+ } else {
328
+ $html = preg_replace( '/<head>(.*)<\/head>/ism', '<head> $1' . Optml_Lazyload_Replacer::IFRAME_PLACEHOLDER_STYLE . '</head>', $html );
329
+ }
330
+ }
331
  }
332
 
333
  $html = $this->process_urls_from_content( $html );
335
  return $html;
336
  }
337
 
338
+ /**
339
+ * Adds a filter that allows adding classes to the HTML tag.
340
+ *
341
+ * @param string $content The HTML content.
342
+ *
343
+ * @return mixed
344
+ */
345
+ public function add_html_class( $content ) {
346
+ if ( empty( $content ) ) {
347
+ return $content;
348
+ }
349
+
350
+ $additional_html_classes = apply_filters( 'optml_additional_html_classes', [] );
351
+
352
+ if ( ! $additional_html_classes ) {
353
+ return $content;
354
+ }
355
+
356
+ if ( preg_match( '/<html.*>/ismU', $content, $matches, PREG_OFFSET_CAPTURE ) === 1 ) {
357
+
358
+ $add_classes = implode( ' ', $additional_html_classes );
359
+ foreach ( $matches as $match ) {
360
+ if ( strpos( $match[0], 'class' ) !== false ) {
361
+ $new_tag = str_replace( [ 'class="', "class='" ], [ 'class="' . $add_classes, "class='" . $add_classes ], $match[0] );
362
+ } else {
363
+ $new_tag = str_replace( 'html ', 'html class="' . $add_classes . '" ', $match[0] );
364
+ }
365
+
366
+ $content = str_replace( $match[0], $new_tag, $content );
367
+ }
368
+ }
369
+
370
+ return $content;
371
+ }
372
+
373
  /**
374
  * Adds a filter with detected images tags and the content.
375
  *
423
  * and img_url keys are arrays of those matches.
424
  */
425
  public static function parse_images_from_html( $content ) {
426
+ $images = [];
427
 
428
  $header_start = null;
429
  $header_end = null;
469
  return $images;
470
  }
471
 
472
+ return [];
473
  }
474
 
475
  /**
498
  if ( $this->settings->use_cdn() && ! self::should_ignore_image_tags() ) {
499
  $extensions = array_merge( $extensions, array_keys( Optml_Config::$assets_extensions ) );
500
  }
501
+ $regex = '/(?:[(|\s\';",=])((?:http|\/|\\\\){1}(?:[' . Optml_Config::$chars . ']{10,}\.(?:' . implode( '|', $extensions ) . ')))(?=(?:http|>|%3F|\?|"|&|,|\s|\'|\)|\||\\\\|}))/Uu';
502
  preg_match_all(
503
  $regex,
504
  $content,
590
  }
591
  self::$ob_started = true;
592
  // We no longer need this if the handler was started.
593
+ remove_filter( 'the_content', [$this, 'process_images_from_content'], PHP_INT_MAX );
594
 
595
  ob_start(
596
+ [&$this, 'replace_content']
597
  );
598
  }
599
 
inc/rest.php CHANGED
@@ -25,7 +25,7 @@ class Optml_Rest {
25
  */
26
  public function __construct() {
27
  $this->namespace = OPTML_NAMESPACE . '/v1';
28
- add_action( 'rest_api_init', array( $this, 'register' ) );
29
  }
30
 
31
  /**
@@ -38,48 +38,48 @@ class Optml_Rest {
38
  register_rest_route(
39
  $this->namespace,
40
  '/update_option',
41
- array(
42
- array(
43
  'methods' => \WP_REST_Server::CREATABLE,
44
  'permission_callback' => function () {
45
  return current_user_can( 'manage_options' );
46
  },
47
- 'callback' => array( $this, 'update_option' ),
48
- ),
49
- )
50
  );
51
 
52
  register_rest_route(
53
  $this->namespace,
54
  '/request_update',
55
- array(
56
- array(
57
  'methods' => \WP_REST_Server::READABLE,
58
  'permission_callback' => function () {
59
  return current_user_can( 'manage_options' );
60
  },
61
- 'callback' => array( $this, 'request_update' ),
62
- ),
63
- )
64
  );
65
  register_rest_route(
66
  $this->namespace,
67
  '/check_redirects',
68
- array(
69
- array(
70
  'methods' => \WP_REST_Server::EDITABLE,
71
  'permission_callback' => function () {
72
  return current_user_can( 'manage_options' );
73
  },
74
- 'callback' => array( $this, 'check_redirects' ),
75
- 'args' => array(
76
- 'images' => array(
77
  'type' => 'Array',
78
  'required' => true,
79
- ),
80
- ),
81
- ),
82
- )
83
  );
84
 
85
  $this->register_image_routes();
@@ -95,53 +95,53 @@ class Optml_Rest {
95
  register_rest_route(
96
  $this->namespace,
97
  '/connect',
98
- array(
99
- array(
100
  'methods' => \WP_REST_Server::CREATABLE,
101
  'permission_callback' => function () {
102
  return current_user_can( 'manage_options' );
103
  },
104
- 'callback' => array( $this, 'connect' ),
105
- 'args' => array(
106
- 'api_key' => array(
107
  'type' => 'string',
108
  'required' => true,
109
- ),
110
- ),
111
- ),
112
- )
113
  );
114
  register_rest_route(
115
  $this->namespace,
116
  '/register',
117
- array(
118
- array(
119
  'methods' => \WP_REST_Server::CREATABLE,
120
  'permission_callback' => function () {
121
  return current_user_can( 'manage_options' );
122
  },
123
- 'callback' => array( $this, 'register_service' ),
124
- 'args' => array(
125
- 'email' => array(
126
  'type' => 'string',
127
  'required' => true,
128
- ),
129
- ),
130
- ),
131
- )
132
  );
133
  register_rest_route(
134
  $this->namespace,
135
  '/disconnect',
136
- array(
137
- array(
138
  'methods' => \WP_REST_Server::READABLE,
139
  'permission_callback' => function () {
140
  return current_user_can( 'manage_options' );
141
  },
142
- 'callback' => array( $this, 'disconnect' ),
143
- ),
144
- )
145
  );
146
  }
147
 
@@ -152,28 +152,28 @@ class Optml_Rest {
152
  register_rest_route(
153
  $this->namespace,
154
  '/poll_optimized_images',
155
- array(
156
- array(
157
  'methods' => \WP_REST_Server::READABLE,
158
  'permission_callback' => function () {
159
  return current_user_can( 'manage_options' );
160
  },
161
- 'callback' => array( $this, 'poll_optimized_images' ),
162
- ),
163
- )
164
  );
165
  register_rest_route(
166
  $this->namespace,
167
  '/images-sample-rate',
168
- array(
169
- array(
170
  'methods' => \WP_REST_Server::CREATABLE,
171
  'permission_callback' => function () {
172
  return current_user_can( 'manage_options' );
173
  },
174
- 'callback' => array( $this, 'get_sample_rate' ),
175
- ),
176
- )
177
  );
178
  }
179
 
@@ -184,41 +184,41 @@ class Optml_Rest {
184
  register_rest_route(
185
  $this->namespace,
186
  '/poll_watermarks',
187
- array(
188
- array(
189
  'methods' => \WP_REST_Server::READABLE,
190
  'permission_callback' => function () {
191
  return current_user_can( 'manage_options' );
192
  },
193
- 'callback' => array( $this, 'poll_watermarks' ),
194
- ),
195
- )
196
  );
197
  register_rest_route(
198
  $this->namespace,
199
  '/add_watermark',
200
- array(
201
- array(
202
  'methods' => \WP_REST_Server::CREATABLE,
203
  'permission_callback' => function () {
204
  return current_user_can( 'manage_options' );
205
  },
206
- 'callback' => array( $this, 'add_watermark' ),
207
- ),
208
- )
209
  );
210
  register_rest_route(
211
  $this->namespace,
212
  '/remove_watermark',
213
- array(
214
- array(
215
  'methods' => \WP_REST_Server::CREATABLE,
216
  'permission_callback' => function () {
217
  return current_user_can( 'manage_options' );
218
  },
219
- 'callback' => array( $this, 'remove_watermark' ),
220
- ),
221
- )
222
  );
223
  }
224
 
@@ -229,28 +229,28 @@ class Optml_Rest {
229
  register_rest_route(
230
  $this->namespace,
231
  '/poll_conflicts',
232
- array(
233
- array(
234
  'methods' => \WP_REST_Server::READABLE,
235
  'permission_callback' => function () {
236
  return current_user_can( 'manage_options' );
237
  },
238
- 'callback' => array( $this, 'poll_conflicts' ),
239
- ),
240
- )
241
  );
242
  register_rest_route(
243
  $this->namespace,
244
  '/dismiss_conflict',
245
- array(
246
- array(
247
  'methods' => \WP_REST_Server::CREATABLE,
248
  'permission_callback' => function () {
249
  return current_user_can( 'manage_options' );
250
  },
251
- 'callback' => array( $this, 'dismiss_conflict' ),
252
- ),
253
- )
254
  );
255
  }
256
 
@@ -261,15 +261,15 @@ class Optml_Rest {
261
  register_rest_route(
262
  $this->namespace,
263
  '/clear_cache',
264
- array(
265
- array(
266
  'methods' => \WP_REST_Server::CREATABLE,
267
  'permission_callback' => function () {
268
  return current_user_can( 'manage_options' );
269
  },
270
- 'callback' => array( $this, 'clear_cache_request' ),
271
- ),
272
- )
273
  );
274
  }
275
 
@@ -342,7 +342,7 @@ class Optml_Rest {
342
  * @return WP_REST_Response
343
  */
344
  private function response( $data, $code = 'success' ) {
345
- return new WP_REST_Response( array( 'data' => $data, 'code' => $code ), 200 );
346
  }
347
 
348
  /**
@@ -358,11 +358,11 @@ class Optml_Rest {
358
  $user = $api->create_account( $email );
359
  if ( $user === false ) {
360
  return new WP_REST_Response(
361
- array(
362
  'data' => null,
363
  'message' => __( 'Error creating account.', 'optimole-wp' ),
364
  'code' => 'error',
365
- ),
366
  200
367
  );
368
 
@@ -386,7 +386,7 @@ class Optml_Rest {
386
  $image_sample = $this->fetch_sample_image();
387
  set_transient( 'optimole_sample_image', $image_sample );
388
  }
389
- $image = array( 'id' => $image_sample['id'] );
390
 
391
  $image['original'] = $image_sample['url'];
392
 
@@ -395,21 +395,21 @@ class Optml_Rest {
395
  $image['optimized'] = apply_filters(
396
  'optml_replace_image',
397
  $image['original'],
398
- array(
399
  'width' => $image_sample['width'],
400
  'height' => $image_sample['height'],
401
  'quality' => $request->get_param( 'quality' ),
402
- )
403
  );
404
 
405
  $optimized = wp_remote_get(
406
  $image['optimized'],
407
- array(
408
  'timeout' => 10,
409
- 'headers' => array(
410
  'Accept' => 'text/html,application/xhtml+xml,image/webp,image/apng ',
411
- ),
412
- )
413
  );
414
 
415
  $original = wp_remote_get( $image['original'] );
@@ -426,27 +426,27 @@ class Optml_Rest {
426
  * @return array Image data.
427
  */
428
  private function fetch_sample_image() {
429
- $accepted_mimes = array( 'image/jpeg' );
430
- $args = array(
431
  'post_type' => 'attachment',
432
  'post_status' => 'any',
433
  'number' => '5',
434
  'no_found_rows' => true,
435
  'fields' => 'ids',
436
  'post_mime_type' => $accepted_mimes,
437
- 'post_parent__not_in' => array( 0 ),
438
- );
439
  $image_result = new WP_Query( $args );
440
  if ( empty( $image_result->posts ) ) {
441
  $rand_id = rand( 1, 3 );
442
  $original_image_url = OPTML_URL . 'assets/img/' . $rand_id . '.jpg';
443
 
444
- return array(
445
  'url' => $original_image_url,
446
  'width' => '700',
447
  'height' => '465',
448
  'id' => - 1,
449
- );
450
  }
451
  $attachment_id = $image_result->posts[ array_rand( $image_result->posts, 1 ) ];
452
 
@@ -462,12 +462,12 @@ class Optml_Rest {
462
  $height = $metadata['sizes'][ $size ]['height'];
463
  }
464
 
465
- return array(
466
  'url' => $original_image_url,
467
  'id' => $attachment_id,
468
  'width' => $width,
469
  'height' => $height,
470
- );
471
  }
472
 
473
  /**
@@ -494,7 +494,7 @@ class Optml_Rest {
494
  $request = new Optml_Api();
495
  $images = $request->get_optimized_images( $api_key );
496
  if ( ! isset( $images['list'] ) || empty( $images['list'] ) ) {
497
- return $this->response( array() );
498
  }
499
 
500
  $final_images = array_splice( $images['list'], 0, 10 );
@@ -514,7 +514,7 @@ class Optml_Rest {
514
  $request = new Optml_Api();
515
  $watermarks = $request->get_watermarks( $api_key );
516
  if ( ! isset( $watermarks['watermarks'] ) || empty( $watermarks['watermarks'] ) ) {
517
- return $this->response( array() );
518
  }
519
  $final_images = array_splice( $watermarks['watermarks'], 0, 10 );
520
 
@@ -562,14 +562,14 @@ class Optml_Rest {
562
  * @return WP_REST_Response
563
  */
564
  public function poll_conflicts( WP_REST_Request $request ) {
565
- $conflicts_to_register = apply_filters( 'optml_register_conflicts', array() );
566
  $manager = new Optml_Conflict_Manager( $conflicts_to_register );
567
 
568
  return $this->response(
569
- array(
570
  'count' => $manager->get_conflict_count(),
571
  'conflicts' => $manager->get_conflict_list(),
572
- )
573
  );
574
  }
575
 
@@ -582,15 +582,15 @@ class Optml_Rest {
582
  */
583
  public function dismiss_conflict( WP_REST_Request $request ) {
584
  $conflict_id = $request->get_param( 'conflictID' );
585
- $conflicts_to_register = apply_filters( 'optml_register_conflicts', array() );
586
  $manager = new Optml_Conflict_Manager( $conflicts_to_register );
587
  $manager->dismiss_conflict( $conflict_id );
588
 
589
  return $this->response(
590
- array(
591
  'count' => $manager->get_conflict_count(),
592
  'conflicts' => $manager->get_conflict_list(),
593
- )
594
  );
595
  }
596
 
@@ -643,10 +643,10 @@ class Optml_Rest {
643
  $status = 'ok';
644
  $result = '';
645
  foreach ( $request->get_param( 'images' ) as $domain => $value ) {
646
- $args = array(
647
  'method' => 'GET',
648
  'redirection' => 0,
649
- );
650
  $processed_images = 0;
651
  if ( isset( $value['src'] ) ) {
652
  $processed_images = count( $value['src'] );
25
  */
26
  public function __construct() {
27
  $this->namespace = OPTML_NAMESPACE . '/v1';
28
+ add_action( 'rest_api_init', [ $this, 'register' ] );
29
  }
30
 
31
  /**
38
  register_rest_route(
39
  $this->namespace,
40
  '/update_option',
41
+ [
42
+ [
43
  'methods' => \WP_REST_Server::CREATABLE,
44
  'permission_callback' => function () {
45
  return current_user_can( 'manage_options' );
46
  },
47
+ 'callback' => [ $this, 'update_option' ],
48
+ ],
49
+ ]
50
  );
51
 
52
  register_rest_route(
53
  $this->namespace,
54
  '/request_update',
55
+ [
56
+ [
57
  'methods' => \WP_REST_Server::READABLE,
58
  'permission_callback' => function () {
59
  return current_user_can( 'manage_options' );
60
  },
61
+ 'callback' => [ $this, 'request_update' ],
62
+ ],
63
+ ]
64
  );
65
  register_rest_route(
66
  $this->namespace,
67
  '/check_redirects',
68
+ [
69
+ [
70
  'methods' => \WP_REST_Server::EDITABLE,
71
  'permission_callback' => function () {
72
  return current_user_can( 'manage_options' );
73
  },
74
+ 'callback' => [ $this, 'check_redirects' ],
75
+ 'args' => [
76
+ 'images' => [
77
  'type' => 'Array',
78
  'required' => true,
79
+ ],
80
+ ],
81
+ ],
82
+ ]
83
  );
84
 
85
  $this->register_image_routes();
95
  register_rest_route(
96
  $this->namespace,
97
  '/connect',
98
+ [
99
+ [
100
  'methods' => \WP_REST_Server::CREATABLE,
101
  'permission_callback' => function () {
102
  return current_user_can( 'manage_options' );
103
  },
104
+ 'callback' => [ $this, 'connect' ],
105
+ 'args' => [
106
+ 'api_key' => [
107
  'type' => 'string',
108
  'required' => true,
109
+ ],
110
+ ],
111
+ ],
112
+ ]
113
  );
114
  register_rest_route(
115
  $this->namespace,
116
  '/register',
117
+ [
118
+ [
119
  'methods' => \WP_REST_Server::CREATABLE,
120
  'permission_callback' => function () {
121
  return current_user_can( 'manage_options' );
122
  },
123
+ 'callback' => [ $this, 'register_service' ],
124
+ 'args' => [
125
+ 'email' => [
126
  'type' => 'string',
127
  'required' => true,
128
+ ],
129
+ ],
130
+ ],
131
+ ]
132
  );
133
  register_rest_route(
134
  $this->namespace,
135
  '/disconnect',
136
+ [
137
+ [
138
  'methods' => \WP_REST_Server::READABLE,
139
  'permission_callback' => function () {
140
  return current_user_can( 'manage_options' );
141
  },
142
+ 'callback' => [ $this, 'disconnect' ],
143
+ ],
144
+ ]
145
  );
146
  }
147
 
152
  register_rest_route(
153
  $this->namespace,
154
  '/poll_optimized_images',
155
+ [
156
+ [
157
  'methods' => \WP_REST_Server::READABLE,
158
  'permission_callback' => function () {
159
  return current_user_can( 'manage_options' );
160
  },
161
+ 'callback' => [ $this, 'poll_optimized_images' ],
162
+ ],
163
+ ]
164
  );
165
  register_rest_route(
166
  $this->namespace,
167
  '/images-sample-rate',
168
+ [
169
+ [
170
  'methods' => \WP_REST_Server::CREATABLE,
171
  'permission_callback' => function () {
172
  return current_user_can( 'manage_options' );
173
  },
174
+ 'callback' => [ $this, 'get_sample_rate' ],
175
+ ],
176
+ ]
177
  );
178
  }
179
 
184
  register_rest_route(
185
  $this->namespace,
186
  '/poll_watermarks',
187
+ [
188
+ [
189
  'methods' => \WP_REST_Server::READABLE,
190
  'permission_callback' => function () {
191
  return current_user_can( 'manage_options' );
192
  },
193
+ 'callback' => [ $this, 'poll_watermarks' ],
194
+ ],
195
+ ]
196
  );
197
  register_rest_route(
198
  $this->namespace,
199
  '/add_watermark',
200
+ [
201
+ [
202
  'methods' => \WP_REST_Server::CREATABLE,
203
  'permission_callback' => function () {
204
  return current_user_can( 'manage_options' );
205
  },
206
+ 'callback' => [ $this, 'add_watermark' ],
207
+ ],
208
+ ]
209
  );
210
  register_rest_route(
211
  $this->namespace,
212
  '/remove_watermark',
213
+ [
214
+ [
215
  'methods' => \WP_REST_Server::CREATABLE,
216
  'permission_callback' => function () {
217
  return current_user_can( 'manage_options' );
218
  },
219
+ 'callback' => [ $this, 'remove_watermark' ],
220
+ ],
221
+ ]
222
  );
223
  }
224
 
229
  register_rest_route(
230
  $this->namespace,
231
  '/poll_conflicts',
232
+ [
233
+ [
234
  'methods' => \WP_REST_Server::READABLE,
235
  'permission_callback' => function () {
236
  return current_user_can( 'manage_options' );
237
  },
238
+ 'callback' => [ $this, 'poll_conflicts' ],
239
+ ],
240
+ ]
241
  );
242
  register_rest_route(
243
  $this->namespace,
244
  '/dismiss_conflict',
245
+ [
246
+ [
247
  'methods' => \WP_REST_Server::CREATABLE,
248
  'permission_callback' => function () {
249
  return current_user_can( 'manage_options' );
250
  },
251
+ 'callback' => [ $this, 'dismiss_conflict' ],
252
+ ],
253
+ ]
254
  );
255
  }
256
 
261
  register_rest_route(
262
  $this->namespace,
263
  '/clear_cache',
264
+ [
265
+ [
266
  'methods' => \WP_REST_Server::CREATABLE,
267
  'permission_callback' => function () {
268
  return current_user_can( 'manage_options' );
269
  },
270
+ 'callback' => [ $this, 'clear_cache_request' ],
271
+ ],
272
+ ]
273
  );
274
  }
275
 
342
  * @return WP_REST_Response
343
  */
344
  private function response( $data, $code = 'success' ) {
345
+ return new WP_REST_Response( [ 'data' => $data, 'code' => $code ], 200 );
346
  }
347
 
348
  /**
358
  $user = $api->create_account( $email );
359
  if ( $user === false ) {
360
  return new WP_REST_Response(
361
+ [
362
  'data' => null,
363
  'message' => __( 'Error creating account.', 'optimole-wp' ),
364
  'code' => 'error',
365
+ ],
366
  200
367
  );
368
 
386
  $image_sample = $this->fetch_sample_image();
387
  set_transient( 'optimole_sample_image', $image_sample );
388
  }
389
+ $image = [ 'id' => $image_sample['id'] ];
390
 
391
  $image['original'] = $image_sample['url'];
392
 
395
  $image['optimized'] = apply_filters(
396
  'optml_replace_image',
397
  $image['original'],
398
+ [
399
  'width' => $image_sample['width'],
400
  'height' => $image_sample['height'],
401
  'quality' => $request->get_param( 'quality' ),
402
+ ]
403
  );
404
 
405
  $optimized = wp_remote_get(
406
  $image['optimized'],
407
+ [
408
  'timeout' => 10,
409
+ 'headers' => [
410
  'Accept' => 'text/html,application/xhtml+xml,image/webp,image/apng ',
411
+ ],
412
+ ]
413
  );
414
 
415
  $original = wp_remote_get( $image['original'] );
426
  * @return array Image data.
427
  */
428
  private function fetch_sample_image() {
429
+ $accepted_mimes = [ 'image/jpeg' ];
430
+ $args = [
431
  'post_type' => 'attachment',
432
  'post_status' => 'any',
433
  'number' => '5',
434
  'no_found_rows' => true,
435
  'fields' => 'ids',
436
  'post_mime_type' => $accepted_mimes,
437
+ 'post_parent__not_in' => [ 0 ],
438
+ ];
439
  $image_result = new WP_Query( $args );
440
  if ( empty( $image_result->posts ) ) {
441
  $rand_id = rand( 1, 3 );
442
  $original_image_url = OPTML_URL . 'assets/img/' . $rand_id . '.jpg';
443
 
444
+ return [
445
  'url' => $original_image_url,
446
  'width' => '700',
447
  'height' => '465',
448
  'id' => - 1,
449
+ ];
450
  }
451
  $attachment_id = $image_result->posts[ array_rand( $image_result->posts, 1 ) ];
452
 
462
  $height = $metadata['sizes'][ $size ]['height'];
463
  }
464
 
465
+ return [
466
  'url' => $original_image_url,
467
  'id' => $attachment_id,
468
  'width' => $width,
469
  'height' => $height,
470
+ ];
471
  }
472
 
473
  /**
494
  $request = new Optml_Api();
495
  $images = $request->get_optimized_images( $api_key );
496
  if ( ! isset( $images['list'] ) || empty( $images['list'] ) ) {
497
+ return $this->response( [] );
498
  }
499
 
500
  $final_images = array_splice( $images['list'], 0, 10 );
514
  $request = new Optml_Api();
515
  $watermarks = $request->get_watermarks( $api_key );
516
  if ( ! isset( $watermarks['watermarks'] ) || empty( $watermarks['watermarks'] ) ) {
517
+ return $this->response( [] );
518
  }
519
  $final_images = array_splice( $watermarks['watermarks'], 0, 10 );
520
 
562
  * @return WP_REST_Response
563
  */
564
  public function poll_conflicts( WP_REST_Request $request ) {
565
+ $conflicts_to_register = apply_filters( 'optml_register_conflicts', [] );
566
  $manager = new Optml_Conflict_Manager( $conflicts_to_register );
567
 
568
  return $this->response(
569
+ [
570
  'count' => $manager->get_conflict_count(),
571
  'conflicts' => $manager->get_conflict_list(),
572
+ ]
573
  );
574
  }
575
 
582
  */
583
  public function dismiss_conflict( WP_REST_Request $request ) {
584
  $conflict_id = $request->get_param( 'conflictID' );
585
+ $conflicts_to_register = apply_filters( 'optml_register_conflicts', [] );
586
  $manager = new Optml_Conflict_Manager( $conflicts_to_register );
587
  $manager->dismiss_conflict( $conflict_id );
588
 
589
  return $this->response(
590
+ [
591
  'count' => $manager->get_conflict_count(),
592
  'conflicts' => $manager->get_conflict_list(),
593
+ ]
594
  );
595
  }
596
 
643
  $status = 'ok';
644
  $result = '';
645
  foreach ( $request->get_param( 'images' ) as $domain => $value ) {
646
+ $args = [
647
  'method' => 'GET',
648
  'redirection' => 0,
649
+ ];
650
  $processed_images = 0;
651
  if ( isset( $value['src'] ) ) {
652
  $processed_images = count( $value['src'] );
inc/settings.php CHANGED
@@ -11,12 +11,32 @@ class Optml_Settings {
11
  const FILTER_CLASS = 'class';
12
  const FILTER_TYPE_LAZYLOAD = 'lazyload';
13
  const FILTER_TYPE_OPTIMIZE = 'optimize';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  /**
15
  * Default settings schema.
16
  *
17
  * @var array Settings schema.
18
  */
19
- private $default_schema = array(
20
  'api_key' => '',
21
  'service_data' => '',
22
  'cache_buster' => '',
@@ -48,7 +68,7 @@ class Optml_Settings {
48
  'report_script' => 'disabled',
49
  'native_lazyload' => 'disabled',
50
 
51
- );
52
  /**
53
  * Option key.
54
  *
@@ -75,6 +95,31 @@ class Optml_Settings {
75
  $this->options = wp_parse_args( get_option( $this->namespace, $this->default_schema ), $this->default_schema );
76
  restore_current_blog();
77
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  }
79
 
80
  /**
@@ -128,7 +173,7 @@ class Optml_Settings {
128
  * @return array
129
  */
130
  public function parse_settings( $new_settings ) {
131
- $sanitized = array();
132
  foreach ( $new_settings as $key => $value ) {
133
  switch ( $key ) {
134
  case 'admin_bar_item':
@@ -147,7 +192,7 @@ class Optml_Settings {
147
  case 'css_minify':
148
  case 'js_minify':
149
  case 'native_lazyload':
150
- $sanitized_value = $this->to_map_values( $value, array( 'enabled', 'disabled' ), 'enabled' );
151
  break;
152
  case 'max_width':
153
  case 'max_height':
@@ -189,7 +234,7 @@ class Optml_Settings {
189
  case 'wm_position':
190
  $sanitized_value = $this->to_map_values(
191
  $value,
192
- array(
193
  Optml_Resize::GRAVITY_NORTH,
194
  Optml_Resize::GRAVITY_NORTH_EAST,
195
  Optml_Resize::GRAVITY_NORTH_WEST,
@@ -199,7 +244,7 @@ class Optml_Settings {
199
  Optml_Resize::GRAVITY_SOUTH_EAST,
200
  Optml_Resize::GRAVITY_SOUTH,
201
  Optml_Resize::GRAVITY_SOUTH_WEST,
202
- ),
203
  Optml_Resize::GRAVITY_SOUTH_EAST
204
  );
205
  break;
@@ -294,7 +339,7 @@ class Optml_Settings {
294
  */
295
  public function get_site_settings() {
296
 
297
- return array(
298
  'quality' => $this->get_quality(),
299
  'admin_bar_item' => $this->get( 'admin_bar_item' ),
300
  'lazyload' => $this->get( 'lazyload' ),
@@ -317,7 +362,7 @@ class Optml_Settings {
317
  'js_minify' => $this->get( 'js_minify' ),
318
  'native_lazyload' => $this->get( 'native_lazyload' ),
319
  'report_script' => $this->get( 'report_script' ),
320
- );
321
  }
322
 
323
  /**
@@ -348,14 +393,14 @@ class Optml_Settings {
348
  * @return array
349
  */
350
  public function get_watermark() {
351
- return array(
352
  'id' => $this->get( 'wm_id' ),
353
  'opacity' => $this->get( 'wm_opacity' ),
354
  'position' => $this->get( 'wm_position' ),
355
  'x_offset' => $this->get( 'wm_x' ),
356
  'y_offset' => $this->get( 'wm_y' ),
357
  'scale' => $this->get( 'wm_scale' ),
358
- );
359
  }
360
 
361
  /**
11
  const FILTER_CLASS = 'class';
12
  const FILTER_TYPE_LAZYLOAD = 'lazyload';
13
  const FILTER_TYPE_OPTIMIZE = 'optimize';
14
+ /**
15
+ * Holds an array of possible settings to alter via wp cli or wp-config constants.
16
+ *
17
+ * @var array Whitelisted settings.
18
+ */
19
+ public static $whitelisted_settings = [
20
+ 'image_replacer' => 'bool',
21
+ 'quality' => 'int',
22
+ 'lazyload' => 'bool',
23
+ 'lazyload_placeholder' => 'bool',
24
+ 'network_optimization' => 'bool',
25
+ 'img_to_video' => 'bool',
26
+ 'resize_smart' => 'bool',
27
+ 'retina_images' => 'bool',
28
+ 'native_lazyload' => 'bool',
29
+ 'video_lazyload' => 'bool',
30
+ 'bg_replacer' => 'bool',
31
+ 'scale' => 'bool',
32
+ 'cdn' => 'bool',
33
+ ];
34
  /**
35
  * Default settings schema.
36
  *
37
  * @var array Settings schema.
38
  */
39
+ private $default_schema = [
40
  'api_key' => '',
41
  'service_data' => '',
42
  'cache_buster' => '',
68
  'report_script' => 'disabled',
69
  'native_lazyload' => 'disabled',
70
 
71
+ ];
72
  /**
73
  * Option key.
74
  *
95
  $this->options = wp_parse_args( get_option( $this->namespace, $this->default_schema ), $this->default_schema );
96
  restore_current_blog();
97
  }
98
+
99
+ if ( defined( 'OPTIML_USE_ENV' ) && constant( 'OPTIML_USE_ENV' ) && $this->to_boolean( constant( 'OPTIML_USE_ENV' ) ) ) {
100
+ foreach ( self::$whitelisted_settings as $key => $type ) {
101
+ $env_key = 'OPTIML_' . strtoupper( $key );
102
+ if ( defined( $env_key ) && constant( $env_key ) ) {
103
+ $value = constant( $env_key );
104
+ if ( $type === 'bool' && ( $value === '' || ! in_array(
105
+ $value,
106
+ [
107
+ 'on',
108
+ 'off',
109
+ ],
110
+ true
111
+ ) ) ) {
112
+ continue;
113
+ }
114
+
115
+ if ( $type === 'int' && ( $value === '' || (int) $value > 100 || (int) $value < 0 ) ) {
116
+ continue;
117
+ }
118
+ $sanitized_value = ( $type === 'bool' ) ? ( $value === 'on' ? 'enabled' : 'disabled' ) : (int) $value;
119
+ $this->options[ $key ] = $sanitized_value;
120
+ }
121
+ }
122
+ }
123
  }
124
 
125
  /**
173
  * @return array
174
  */
175
  public function parse_settings( $new_settings ) {
176
+ $sanitized = [];
177
  foreach ( $new_settings as $key => $value ) {
178
  switch ( $key ) {
179
  case 'admin_bar_item':
192
  case 'css_minify':
193
  case 'js_minify':
194
  case 'native_lazyload':
195
+ $sanitized_value = $this->to_map_values( $value, [ 'enabled', 'disabled' ], 'enabled' );
196
  break;
197
  case 'max_width':
198
  case 'max_height':
234
  case 'wm_position':
235
  $sanitized_value = $this->to_map_values(
236
  $value,
237
+ [
238
  Optml_Resize::GRAVITY_NORTH,
239
  Optml_Resize::GRAVITY_NORTH_EAST,
240
  Optml_Resize::GRAVITY_NORTH_WEST,
244
  Optml_Resize::GRAVITY_SOUTH_EAST,
245
  Optml_Resize::GRAVITY_SOUTH,
246
  Optml_Resize::GRAVITY_SOUTH_WEST,
247
+ ],
248
  Optml_Resize::GRAVITY_SOUTH_EAST
249
  );
250
  break;
339
  */
340
  public function get_site_settings() {
341
 
342
+ return [
343
  'quality' => $this->get_quality(),
344
  'admin_bar_item' => $this->get( 'admin_bar_item' ),
345
  'lazyload' => $this->get( 'lazyload' ),
362
  'js_minify' => $this->get( 'js_minify' ),
363
  'native_lazyload' => $this->get( 'native_lazyload' ),
364
  'report_script' => $this->get( 'report_script' ),
365
+ ];
366
  }
367
 
368
  /**
393
  * @return array
394
  */
395
  public function get_watermark() {
396
+ return [
397
  'id' => $this->get( 'wm_id' ),
398
  'opacity' => $this->get( 'wm_opacity' ),
399
  'position' => $this->get( 'wm_position' ),
400
  'x_offset' => $this->get( 'wm_x' ),
401
  'y_offset' => $this->get( 'wm_y' ),
402
  'scale' => $this->get( 'wm_scale' ),
403
+ ];
404
  }
405
 
406
  /**
inc/tag_replacer.php CHANGED
@@ -29,7 +29,7 @@ final class Optml_Tag_Replacer extends Optml_App_Replacer {
29
  public static function instance() {
30
  if ( null === self::$instance ) {
31
  self::$instance = new self();
32
- add_action( 'optml_replacer_setup', array( self::$instance, 'init' ) );
33
  }
34
 
35
  return self::$instance;
@@ -41,16 +41,16 @@ final class Optml_Tag_Replacer extends Optml_App_Replacer {
41
  public function init() {
42
 
43
  parent::init();
44
- add_filter( 'optml_content_images_tags', array( $this, 'process_image_tags' ), 1, 2 );
45
 
46
  if ( $this->settings->use_lazyload() ) {
47
  return;
48
  }
49
 
50
- add_filter( 'optml_tag_replace', array( $this, 'regular_tag_replace' ), 1, 6 );
51
- add_filter( 'image_downsize', array( $this, 'filter_image_downsize' ), PHP_INT_MAX, 3 );
52
- add_filter( 'wp_calculate_image_srcset', array( $this, 'filter_srcset_attr' ), PHP_INT_MAX, 5 );
53
- add_filter( 'wp_calculate_image_sizes', array( $this, 'filter_sizes_attr' ), 1, 2 );
54
 
55
  }
56
  /**
@@ -81,19 +81,19 @@ final class Optml_Tag_Replacer extends Optml_App_Replacer {
81
  $link_mp4 = apply_filters(
82
  'optml_content_url',
83
  $image_url,
84
- array('width' => 'auto',
85
  'height' => 'auto',
86
  'format' => 'mp4',
87
- )
88
  );
89
 
90
  $link_png = apply_filters(
91
  'optml_content_url',
92
  $image_url,
93
- array('width' => 'auto',
94
  'height' => 'auto',
95
  'quality' => 'eco',
96
- )
97
  );
98
 
99
  $video_tag = $image_tag;
@@ -123,7 +123,7 @@ final class Optml_Tag_Replacer extends Optml_App_Replacer {
123
  *
124
  * @return mixed
125
  */
126
- public function process_image_tags( $content, $images = array() ) {
127
 
128
  $image_sizes = self::image_sizes();
129
  $sizes2crop = self::size_to_crop();
@@ -141,14 +141,14 @@ final class Optml_Tag_Replacer extends Optml_App_Replacer {
141
 
142
  $new_src = $is_slashed ? addcslashes( $src, '/' ) : $src;
143
  $image_tag = str_replace(
144
- array(
145
  '"' . $images['img_url'][ $index ],
146
  "'" . $images['img_url'][ $index ],
147
- ),
148
- array(
149
  '"' . $new_src,
150
  "'" . $new_src,
151
- ),
152
  $image_tag
153
  );
154
  $images['img_url'][ $index ] = $new_src;
@@ -166,16 +166,16 @@ final class Optml_Tag_Replacer extends Optml_App_Replacer {
166
  continue;
167
  }
168
 
169
- $resize = apply_filters( 'optml_default_crop', array() );
170
 
171
  list( $width, $height, $resize ) = self::parse_dimensions_from_tag(
172
  $images['img_tag'][ $index ],
173
  $image_sizes,
174
- array(
175
  'width' => $width,
176
  'height' => $height,
177
  'resize' => $resize,
178
- )
179
  );
180
  if ( false === $width && false === $height ) {
181
  list( $width, $height, $crop ) = $this->parse_dimensions_from_filename( $tmp );
@@ -248,7 +248,7 @@ final class Optml_Tag_Replacer extends Optml_App_Replacer {
248
  *
249
  * @return array
250
  */
251
- private function parse_dimensions_from_tag( $tag, $image_sizes, $args = array() ) {
252
  if ( preg_match( '#width=["|\']?([\d%]+)["|\']?#i', $tag, $width_string ) ) {
253
  $args['width'] = $width_string[1];
254
  }
@@ -258,18 +258,18 @@ final class Optml_Tag_Replacer extends Optml_App_Replacer {
258
  if ( preg_match( '#class=["|\']?[^"\']*size-([^"\'\s]+)[^"\']*["|\']?#i', $tag, $size ) ) {
259
  $size = array_pop( $size );
260
 
261
- if ( false === $args['width'] && false === $args['height'] && 'full' != $size && array_key_exists( $size, $image_sizes ) ) {
262
  $args['width'] = (int) $image_sizes[ $size ]['width'];
263
  $args['height'] = (int) $image_sizes[ $size ]['height'];
264
  }
265
- if ( 'full' != $size && array_key_exists( $size, $image_sizes ) ) {
266
  $args['resize'] = $this->to_optml_crop( $image_sizes[ $size ]['crop'] );
267
  }
268
  } else {
269
  $args['resize'] = apply_filters( 'optml_parse_resize_from_tag', [], $tag );
270
  }
271
 
272
- return array( $args['width'], $args['height'], $args['resize'] );
273
  }
274
 
275
  /**
@@ -301,7 +301,7 @@ final class Optml_Tag_Replacer extends Optml_App_Replacer {
301
  *
302
  * @return array
303
  */
304
- public function filter_srcset_attr( $sources = array(), $size_array = array(), $image_src = '', $image_meta = array(), $attachment_id = 0 ) {
305
  if ( ! is_array( $sources ) ) {
306
  return $sources;
307
  }
@@ -332,9 +332,9 @@ final class Optml_Tag_Replacer extends Optml_App_Replacer {
332
  $original_url = $this->strip_image_size_from_url( $source['url'] );
333
  }
334
  }
335
- $args = array();
336
  if ( 'w' === $source['descriptor'] ) {
337
- if ( $height && ( $source['value'] == $width ) ) {
338
  $args['width'] = $width;
339
  $args['height'] = $height;
340
  } else {
@@ -401,10 +401,10 @@ final class Optml_Tag_Replacer extends Optml_App_Replacer {
401
  $image_meta = wp_get_attachment_metadata( $attachment_id );
402
  $image_args = self::image_sizes();
403
  // default size
404
- $sizes = array(
405
  'width' => isset( $image_meta['width'] ) ? intval( $image_meta['width'] ) : false,
406
  'height' => isset( $image_meta['height'] ) ? intval( $image_meta['height'] ) : false,
407
- );
408
 
409
  switch ( $size ) {
410
  case is_array( $size ):
@@ -446,12 +446,12 @@ final class Optml_Tag_Replacer extends Optml_App_Replacer {
446
  return $image;
447
  }
448
 
449
- return array(
450
  $new_url,
451
  $sizes['width'],
452
  $sizes['height'],
453
  $size === 'full',
454
- );
455
  }
456
 
457
  /**
29
  public static function instance() {
30
  if ( null === self::$instance ) {
31
  self::$instance = new self();
32
+ add_action( 'optml_replacer_setup', [ self::$instance, 'init' ] );
33
  }
34
 
35
  return self::$instance;
41
  public function init() {
42
 
43
  parent::init();
44
+ add_filter( 'optml_content_images_tags', [ $this, 'process_image_tags' ], 1, 2 );
45
 
46
  if ( $this->settings->use_lazyload() ) {
47
  return;
48
  }
49
 
50
+ add_filter( 'optml_tag_replace', [ $this, 'regular_tag_replace' ], 1, 6 );
51
+ add_filter( 'image_downsize', [ $this, 'filter_image_downsize' ], PHP_INT_MAX, 3 );
52
+ add_filter( 'wp_calculate_image_srcset', [ $this, 'filter_srcset_attr' ], PHP_INT_MAX, 5 );
53
+ add_filter( 'wp_calculate_image_sizes', [ $this, 'filter_sizes_attr' ], 1, 2 );
54
 
55
  }
56
  /**
81
  $link_mp4 = apply_filters(
82
  'optml_content_url',
83
  $image_url,
84
+ ['width' => 'auto',
85
  'height' => 'auto',
86
  'format' => 'mp4',
87
+ ]
88
  );
89
 
90
  $link_png = apply_filters(
91
  'optml_content_url',
92
  $image_url,
93
+ ['width' => 'auto',
94
  'height' => 'auto',
95
  'quality' => 'eco',
96
+ ]
97
  );
98
 
99
  $video_tag = $image_tag;
123
  *
124
  * @return mixed
125
  */
126
+ public function process_image_tags( $content, $images = [] ) {
127
 
128
  $image_sizes = self::image_sizes();
129
  $sizes2crop = self::size_to_crop();
141
 
142
  $new_src = $is_slashed ? addcslashes( $src, '/' ) : $src;
143
  $image_tag = str_replace(
144
+ [
145
  '"' . $images['img_url'][ $index ],
146
  "'" . $images['img_url'][ $index ],
147
+ ],
148
+ [
149
  '"' . $new_src,
150
  "'" . $new_src,
151
+ ],
152
  $image_tag
153
  );
154
  $images['img_url'][ $index ] = $new_src;
166
  continue;
167
  }
168
 
169
+ $resize = apply_filters( 'optml_default_crop', [] );
170
 
171
  list( $width, $height, $resize ) = self::parse_dimensions_from_tag(
172
  $images['img_tag'][ $index ],
173
  $image_sizes,
174
+ [
175
  'width' => $width,
176
  'height' => $height,
177
  'resize' => $resize,
178
+ ]
179
  );
180
  if ( false === $width && false === $height ) {
181
  list( $width, $height, $crop ) = $this->parse_dimensions_from_filename( $tmp );
248
  *
249
  * @return array
250
  */
251
+ private function parse_dimensions_from_tag( $tag, $image_sizes, $args = [] ) {
252
  if ( preg_match( '#width=["|\']?([\d%]+)["|\']?#i', $tag, $width_string ) ) {
253
  $args['width'] = $width_string[1];
254
  }
258
  if ( preg_match( '#class=["|\']?[^"\']*size-([^"\'\s]+)[^"\']*["|\']?#i', $tag, $size ) ) {
259
  $size = array_pop( $size );
260
 
261
+ if ( false === $args['width'] && false === $args['height'] && 'full' !== $size && array_key_exists( $size, $image_sizes ) ) {
262
  $args['width'] = (int) $image_sizes[ $size ]['width'];
263
  $args['height'] = (int) $image_sizes[ $size ]['height'];
264
  }
265
+ if ( 'full' !== $size && array_key_exists( $size, $image_sizes ) ) {
266
  $args['resize'] = $this->to_optml_crop( $image_sizes[ $size ]['crop'] );
267
  }
268
  } else {
269
  $args['resize'] = apply_filters( 'optml_parse_resize_from_tag', [], $tag );
270
  }
271
 
272
+ return [ $args['width'], $args['height'], $args['resize'] ];
273
  }
274
 
275
  /**
301
  *
302
  * @return array
303
  */
304
+ public function filter_srcset_attr( $sources = [], $size_array = [], $image_src = '', $image_meta = [], $attachment_id = 0 ) {
305
  if ( ! is_array( $sources ) ) {
306
  return $sources;
307
  }
332
  $original_url = $this->strip_image_size_from_url( $source['url'] );
333
  }
334
  }
335
+ $args = [];
336
  if ( 'w' === $source['descriptor'] ) {
337
+ if ( $height && ( $source['value'] === $width ) ) {
338
  $args['width'] = $width;
339
  $args['height'] = $height;
340
  } else {
401
  $image_meta = wp_get_attachment_metadata( $attachment_id );
402
  $image_args = self::image_sizes();
403
  // default size
404
+ $sizes = [
405
  'width' => isset( $image_meta['width'] ) ? intval( $image_meta['width'] ) : false,
406
  'height' => isset( $image_meta['height'] ) ? intval( $image_meta['height'] ) : false,
407
+ ];
408
 
409
  switch ( $size ) {
410
  case is_array( $size ):
446
  return $image;
447
  }
448
 
449
+ return [
450
  $new_url,
451
  $sizes['width'],
452
  $sizes['height'],
453
  $size === 'full',
454
+ ];
455
  }
456
 
457
  /**
inc/traits/normalizer.php CHANGED
@@ -16,11 +16,11 @@ trait Optml_Normalizer {
16
  * @return bool
17
  */
18
  public function to_boolean( $value ) {
19
- if ( in_array( $value, array( 'yes', 'enabled', 'true', '1' ) ) ) {
20
  return true;
21
  }
22
 
23
- if ( in_array( $value, array( 'no', 'disabled', 'false', '0' ) ) ) {
24
  return false;
25
  }
26
 
@@ -81,7 +81,7 @@ trait Optml_Normalizer {
81
  * @return mixed
82
  */
83
  public function to_map_values( $value, $map, $default ) {
84
- if ( in_array( $value, $map ) ) {
85
  return $value;
86
  }
87
 
@@ -101,13 +101,13 @@ trait Optml_Normalizer {
101
  }
102
  $value = trim( $value );
103
 
104
- $accepted_qualities = array(
105
  'eco' => 'eco',
106
  'auto' => 'auto',
107
  'high_c' => 55,
108
  'medium_c' => 75,
109
  'low_c' => 90,
110
- );
111
 
112
  if ( array_key_exists( $value, $accepted_qualities ) ) {
113
  return $accepted_qualities[ $value ];
@@ -139,7 +139,7 @@ trait Optml_Normalizer {
139
  *
140
  * @return array
141
  */
142
- public function to_optml_crop( $crop_args = array() ) {
143
 
144
  $enlarge = false;
145
  if ( isset( $crop_args['enlarge'] ) ) {
@@ -147,14 +147,14 @@ trait Optml_Normalizer {
147
  $enlarge = $crop_args['enlarge'];
148
  }
149
  if ( $crop_args === true ) {
150
- return array(
151
  'type' => Optml_Resize::RESIZE_FILL,
152
  'enlarge' => $enlarge,
153
  'gravity' => Optml_Resize::GRAVITY_CENTER,
154
- );
155
  }
156
- if ( $crop_args === false || ! is_array( $crop_args ) || count( $crop_args ) != 2 ) {
157
- return array();
158
  }
159
 
160
  $allowed_x = [
@@ -167,7 +167,7 @@ trait Optml_Normalizer {
167
  'center' => true,
168
  'bottom' => true,
169
  ];
170
- $allowed_gravities = array(
171
  'left' => Optml_Resize::GRAVITY_WEST,
172
  'right' => Optml_Resize::GRAVITY_EAST,
173
  'top' => Optml_Resize::GRAVITY_NORTH,
@@ -176,11 +176,11 @@ trait Optml_Normalizer {
176
  'leftbottom' => Optml_Resize::GRAVITY_SOUTH_WEST,
177
  'righttop' => Optml_Resize::GRAVITY_NORTH_EAST,
178
  'rightbottom' => Optml_Resize::GRAVITY_SOUTH_EAST,
179
- 'centertop' => array( 0.5, 0 ),
180
- 'centerbottom' => array( 0.5, 1 ),
181
- 'leftcenter' => array( 0, 0.5 ),
182
- 'rightcenter' => array( 1, 0.5 ),
183
- );
184
 
185
  $gravity = Optml_Resize::GRAVITY_CENTER;
186
  $key_search = ( $crop_args[0] === true ? '' :
@@ -192,11 +192,11 @@ trait Optml_Normalizer {
192
  $gravity = $allowed_gravities[ $key_search ];
193
  }
194
 
195
- return array(
196
  'type' => Optml_Resize::RESIZE_FILL,
197
  'enlarge' => $enlarge,
198
  'gravity' => $gravity,
199
- );
200
  }
201
 
202
  /**
@@ -206,8 +206,8 @@ trait Optml_Normalizer {
206
  *
207
  * @return array
208
  */
209
- public function to_optml_watermark( $watermark_args = array() ) {
210
- $allowed_gravities = array(
211
  'left' => Optml_Resize::GRAVITY_WEST,
212
  'right' => Optml_Resize::GRAVITY_EAST,
213
  'top' => Optml_Resize::GRAVITY_NORTH,
@@ -216,15 +216,15 @@ trait Optml_Normalizer {
216
  'left_bottom' => Optml_Resize::GRAVITY_SOUTH_WEST,
217
  'right_top' => Optml_Resize::GRAVITY_NORTH_EAST,
218
  'right_bottom' => Optml_Resize::GRAVITY_SOUTH_EAST,
219
- );
220
  $gravity = Optml_Resize::GRAVITY_CENTER;
221
  if ( isset( $watermark_args['position'] ) && array_key_exists( $watermark_args['position'], $allowed_gravities ) ) {
222
  $gravity = $allowed_gravities[ $watermark_args['position'] ];
223
  }
224
 
225
- return array(
226
  'opacity' => 1,
227
  'position' => $gravity,
228
- );
229
  }
230
  }
16
  * @return bool
17
  */
18
  public function to_boolean( $value ) {
19
+ if ( in_array( $value, [ 'yes', 'enabled', 'true', '1' ], true ) ) {
20
  return true;
21
  }
22
 
23
+ if ( in_array( $value, [ 'no', 'disabled', 'false', '0' ], true ) ) {
24
  return false;
25
  }
26
 
81
  * @return mixed
82
  */
83
  public function to_map_values( $value, $map, $default ) {
84
+ if ( in_array( $value, $map, true ) ) {
85
  return $value;
86
  }
87
 
101
  }
102
  $value = trim( $value );
103
 
104
+ $accepted_qualities = [
105
  'eco' => 'eco',
106
  'auto' => 'auto',
107
  'high_c' => 55,
108
  'medium_c' => 75,
109
  'low_c' => 90,
110
+ ];
111
 
112
  if ( array_key_exists( $value, $accepted_qualities ) ) {
113
  return $accepted_qualities[ $value ];
139
  *
140
  * @return array
141
  */
142
+ public function to_optml_crop( $crop_args = [] ) {
143
 
144
  $enlarge = false;
145
  if ( isset( $crop_args['enlarge'] ) ) {
147
  $enlarge = $crop_args['enlarge'];
148
  }
149
  if ( $crop_args === true ) {
150
+ return [
151
  'type' => Optml_Resize::RESIZE_FILL,
152
  'enlarge' => $enlarge,
153
  'gravity' => Optml_Resize::GRAVITY_CENTER,
154
+ ];
155
  }
156
+ if ( $crop_args === false || ! is_array( $crop_args ) || count( $crop_args ) !== 2 ) {
157
+ return [];
158
  }
159
 
160
  $allowed_x = [
167
  'center' => true,
168
  'bottom' => true,
169
  ];
170
+ $allowed_gravities = [
171
  'left' => Optml_Resize::GRAVITY_WEST,
172
  'right' => Optml_Resize::GRAVITY_EAST,
173
  'top' => Optml_Resize::GRAVITY_NORTH,
176
  'leftbottom' => Optml_Resize::GRAVITY_SOUTH_WEST,
177
  'righttop' => Optml_Resize::GRAVITY_NORTH_EAST,
178
  'rightbottom' => Optml_Resize::GRAVITY_SOUTH_EAST,
179
+ 'centertop' => [ 0.5, 0 ],
180
+ 'centerbottom' => [ 0.5, 1 ],
181
+ 'leftcenter' => [ 0, 0.5 ],
182
+ 'rightcenter' => [ 1, 0.5 ],
183
+ ];
184
 
185
  $gravity = Optml_Resize::GRAVITY_CENTER;
186
  $key_search = ( $crop_args[0] === true ? '' :
192
  $gravity = $allowed_gravities[ $key_search ];
193
  }
194
 
195
+ return [
196
  'type' => Optml_Resize::RESIZE_FILL,
197
  'enlarge' => $enlarge,
198
  'gravity' => $gravity,
199
+ ];
200
  }
201
 
202
  /**
206
  *
207
  * @return array
208
  */
209
+ public function to_optml_watermark( $watermark_args = [] ) {
210
+ $allowed_gravities = [
211
  'left' => Optml_Resize::GRAVITY_WEST,
212
  'right' => Optml_Resize::GRAVITY_EAST,
213
  'top' => Optml_Resize::GRAVITY_NORTH,
216
  'left_bottom' => Optml_Resize::GRAVITY_SOUTH_WEST,
217
  'right_top' => Optml_Resize::GRAVITY_NORTH_EAST,
218
  'right_bottom' => Optml_Resize::GRAVITY_SOUTH_EAST,
219
+ ];
220
  $gravity = Optml_Resize::GRAVITY_CENTER;
221
  if ( isset( $watermark_args['position'] ) && array_key_exists( $watermark_args['position'], $allowed_gravities ) ) {
222
  $gravity = $allowed_gravities[ $watermark_args['position'] ];
223
  }
224
 
225
+ return [
226
  'opacity' => 1,
227
  'position' => $gravity,
228
+ ];
229
  }
230
  }
inc/url_replacer.php CHANGED
@@ -30,7 +30,7 @@ final class Optml_Url_Replacer extends Optml_App_Replacer {
30
  public static function instance() {
31
  if ( null === self::$instance ) {
32
  self::$instance = new self();
33
- add_action( 'optml_replacer_setup', array( self::$instance, 'init' ) );
34
  }
35
 
36
  return self::$instance;
@@ -84,13 +84,13 @@ final class Optml_Url_Replacer extends Optml_App_Replacer {
84
  */
85
  public function init() {
86
 
87
- add_filter( 'optml_replace_image', array( $this, 'build_url' ), 10, 2 );
88
  parent::init();
89
 
90
  Optml_Quality::$default_quality = $this->to_accepted_quality( $this->settings->get_quality() );
91
  Optml_Image::$watermark = new Optml_Watermark( $this->settings->get_site_settings()['watermark'] );
92
  Optml_Resize::$default_enlarge = apply_filters( 'optml_always_enlarge', false );
93
- add_filter( 'optml_content_url', array( $this, 'build_url' ), 1, 2 );
94
 
95
  }
96
 
@@ -103,10 +103,10 @@ final class Optml_Url_Replacer extends Optml_App_Replacer {
103
  * @return string
104
  */
105
  public function build_url(
106
- $url, $args = array(
107
  'width' => 'auto',
108
  'height' => 'auto',
109
- )
110
  ) {
111
  if ( apply_filters( 'optml_dont_replace_url', false, $url ) ) {
112
  return $url;
30
  public static function instance() {
31
  if ( null === self::$instance ) {
32
  self::$instance = new self();
33
+ add_action( 'optml_replacer_setup', [ self::$instance, 'init' ] );
34
  }
35
 
36
  return self::$instance;
84
  */
85
  public function init() {
86
 
87
+ add_filter( 'optml_replace_image', [ $this, 'build_url' ], 10, 2 );
88
  parent::init();
89
 
90
  Optml_Quality::$default_quality = $this->to_accepted_quality( $this->settings->get_quality() );
91
  Optml_Image::$watermark = new Optml_Watermark( $this->settings->get_site_settings()['watermark'] );
92
  Optml_Resize::$default_enlarge = apply_filters( 'optml_always_enlarge', false );
93
+ add_filter( 'optml_content_url', [ $this, 'build_url' ], 1, 2 );
94
 
95
  }
96
 
103
  * @return string
104
  */
105
  public function build_url(
106
+ $url, $args = [
107
  'width' => 'auto',
108
  'height' => 'auto',
109
+ ]
110
  ) {
111
  if ( apply_filters( 'optml_dont_replace_url', false, $url ) ) {
112
  return $url;
optimole-wp.php CHANGED
@@ -2,7 +2,7 @@
2
  /**
3
  * Plugin Name: Image optimization service by Optimole
4
  * Description: Complete handling of your website images.
5
- * Version: 2.5.6
6
  * Author: Optimole
7
  * Author URI: https://optimole.com
8
  * License: GPL-2.0+
@@ -26,7 +26,7 @@ function optml_autoload( $class ) {
26
  if ( strpos( $class, $prefix ) !== 0 ) {
27
  return;
28
  }
29
- foreach ( array( '/inc/', '/inc/traits/', '/inc/image_properties/', '/inc/asset_properties/', '/inc/compatibilities/', '/inc/conflicts/', '/inc/cli/' ) as $folder ) {
30
  $file = str_replace( $prefix . '_', '', $class );
31
  $file = strtolower( $file );
32
  $file = dirname( __FILE__ ) . $folder . $file . '.php';
@@ -77,7 +77,7 @@ function optml() {
77
  define( 'OPTML_JS_CDN', 'd5jmkjjpb7yfg.cloudfront.net' );
78
  }
79
  define( 'OPTML_PATH', plugin_dir_path( __FILE__ ) );
80
- define( 'OPTML_VERSION', '2.5.6' );
81
  define( 'OPTML_NAMESPACE', 'optml' );
82
  define( 'OPTML_BASEFILE', __FILE__ );
83
  // Fallback for old PHP versions when this constant is not defined.
2
  /**
3
  * Plugin Name: Image optimization service by Optimole
4
  * Description: Complete handling of your website images.
5
+ * Version: 2.5.7
6
  * Author: Optimole
7
  * Author URI: https://optimole.com
8
  * License: GPL-2.0+
26
  if ( strpos( $class, $prefix ) !== 0 ) {
27
  return;
28
  }
29
+ foreach ( [ '/inc/', '/inc/traits/', '/inc/image_properties/', '/inc/asset_properties/', '/inc/compatibilities/', '/inc/conflicts/', '/inc/cli/' ] as $folder ) {
30
  $file = str_replace( $prefix . '_', '', $class );
31
  $file = strtolower( $file );
32
  $file = dirname( __FILE__ ) . $folder . $file . '.php';
77
  define( 'OPTML_JS_CDN', 'd5jmkjjpb7yfg.cloudfront.net' );
78
  }
79
  define( 'OPTML_PATH', plugin_dir_path( __FILE__ ) );
80
+ define( 'OPTML_VERSION', '2.5.7' );
81
  define( 'OPTML_NAMESPACE', 'optml' );
82
  define( 'OPTML_BASEFILE', __FILE__ );
83
  // Fallback for old PHP versions when this constant is not defined.
readme.txt CHANGED
@@ -89,6 +89,20 @@ Premium users will be able to optimize images for more than 25k monthly active u
89
 
90
  == Changelog ==
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  ##### [Version 2.5.6](https://github.com/Codeinwp/optimole-wp/compare/v2.5.5...v2.5.6) (2020-10-19)
93
 
94
  * Fixed regression on image lazyload after version v2.5.5
89
 
90
  == Changelog ==
91
 
92
+ ##### [Version 2.5.7](https://github.com/Codeinwp/optimole-wp/compare/v2.5.6...v2.5.7) (2020-12-17)
93
+
94
+ #### Fixes
95
+ * Adds iframe style for lazyloading only when the iframe is used on the current page
96
+ * Improve lazyload CLS web vital
97
+ * Adds compatibility with Smart Search for Woocommerce
98
+
99
+ #### Features
100
+ * Adds option to set the plugin settings via [wp-config](https://docs.optimole.com/article/1316-setting-plugin-options-via-wp-config)constants
101
+ * Adds more option to set plugin settings via [wp cli](https://docs.optimole.com/article/1202-plugin-cli-commands)
102
+
103
+
104
+
105
+
106
  ##### [Version 2.5.6](https://github.com/Codeinwp/optimole-wp/compare/v2.5.5...v2.5.6) (2020-10-19)
107
 
108
  * Fixed regression on image lazyload after version v2.5.5
vendor/autoload.php CHANGED
@@ -4,4 +4,4 @@
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
- return ComposerAutoloaderInit379ca36df2589cb97644f9a0a1e12009::getLoader();
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
+ return ComposerAutoloaderInitbc8b015f48b680dc9837def04d672ebf::getLoader();
vendor/composer/ClassLoader.php CHANGED
@@ -37,8 +37,8 @@ namespace Composer\Autoload;
37
  *
38
  * @author Fabien Potencier <fabien@symfony.com>
39
  * @author Jordi Boggiano <j.boggiano@seld.be>
40
- * @see http://www.php-fig.org/psr/psr-0/
41
- * @see http://www.php-fig.org/psr/psr-4/
42
  */
43
  class ClassLoader
44
  {
37
  *
38
  * @author Fabien Potencier <fabien@symfony.com>
39
  * @author Jordi Boggiano <j.boggiano@seld.be>
40
+ * @see https://www.php-fig.org/psr/psr-0/
41
+ * @see https://www.php-fig.org/psr/psr-4/
42
  */
43
  class ClassLoader
44
  {
vendor/composer/InstalledVersions.php ADDED
@@ -0,0 +1,228 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+ namespace Composer;
14
+
15
+ use Composer\Semver\VersionParser;
16
+
17
+
18
+
19
+
20
+
21
+
22
+ class InstalledVersions
23
+ {
24
+ private static $installed = array (
25
+ 'root' =>
26
+ array (
27
+ 'pretty_version' => '1.1.2',
28
+ 'version' => '1.1.2.0',
29
+ 'aliases' =>
30
+ array (
31
+ ),
32
+ 'reference' => NULL,
33
+ 'name' => 'codeinwp/optimole-wp',
34
+ ),
35
+ 'versions' =>
36
+ array (
37
+ 'codeinwp/optimole-wp' =>
38
+ array (
39
+ 'pretty_version' => '1.1.2',
40
+ 'version' => '1.1.2.0',
41
+ 'aliases' =>
42
+ array (
43
+ ),
44
+ 'reference' => NULL,
45
+ ),
46
+ 'codeinwp/themeisle-sdk' =>
47
+ array (
48
+ 'pretty_version' => '3.2.15',
49
+ 'version' => '3.2.15.0',
50
+ 'aliases' =>
51
+ array (
52
+ ),
53
+ 'reference' => '95b7447a5f4faba410c281c4bf278fbd740fed71',
54
+ ),
55
+ ),
56
+ );
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+ public static function getInstalledPackages()
65
+ {
66
+ return array_keys(self::$installed['versions']);
67
+ }
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+ public static function isInstalled($packageName)
78
+ {
79
+ return isset(self::$installed['versions'][$packageName]);
80
+ }
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+ public static function satisfies(VersionParser $parser, $packageName, $constraint)
96
+ {
97
+ $constraint = $parser->parseConstraints($constraint);
98
+ $provided = $parser->parseConstraints(self::getVersionRanges($packageName));
99
+
100
+ return $provided->matches($constraint);
101
+ }
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+ public static function getVersionRanges($packageName)
113
+ {
114
+ if (!isset(self::$installed['versions'][$packageName])) {
115
+ throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
116
+ }
117
+
118
+ $ranges = array();
119
+ if (isset(self::$installed['versions'][$packageName]['pretty_version'])) {
120
+ $ranges[] = self::$installed['versions'][$packageName]['pretty_version'];
121
+ }
122
+ if (array_key_exists('aliases', self::$installed['versions'][$packageName])) {
123
+ $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['aliases']);
124
+ }
125
+ if (array_key_exists('replaced', self::$installed['versions'][$packageName])) {
126
+ $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['replaced']);
127
+ }
128
+ if (array_key_exists('provided', self::$installed['versions'][$packageName])) {
129
+ $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['provided']);
130
+ }
131
+
132
+ return implode(' || ', $ranges);
133
+ }
134
+
135
+
136
+
137
+
138
+
139
+ public static function getVersion($packageName)
140
+ {
141
+ if (!isset(self::$installed['versions'][$packageName])) {
142
+ throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
143
+ }
144
+
145
+ if (!isset(self::$installed['versions'][$packageName]['version'])) {
146
+ return null;
147
+ }
148
+
149
+ return self::$installed['versions'][$packageName]['version'];
150
+ }
151
+
152
+
153
+
154
+
155
+
156
+ public static function getPrettyVersion($packageName)
157
+ {
158
+ if (!isset(self::$installed['versions'][$packageName])) {
159
+ throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
160
+ }
161
+
162
+ if (!isset(self::$installed['versions'][$packageName]['pretty_version'])) {
163
+ return null;
164
+ }
165
+
166
+ return self::$installed['versions'][$packageName]['pretty_version'];
167
+ }
168
+
169
+
170
+
171
+
172
+
173
+ public static function getReference($packageName)
174
+ {
175
+ if (!isset(self::$installed['versions'][$packageName])) {
176
+ throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
177
+ }
178
+
179
+ if (!isset(self::$installed['versions'][$packageName]['reference'])) {
180
+ return null;
181
+ }
182
+
183
+ return self::$installed['versions'][$packageName]['reference'];
184
+ }
185
+
186
+
187
+
188
+
189
+
190
+ public static function getRootPackage()
191
+ {
192
+ return self::$installed['root'];
193
+ }
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+ public static function getRawData()
202
+ {
203
+ return self::$installed;
204
+ }
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+
220
+
221
+
222
+
223
+
224
+ public static function reload($data)
225
+ {
226
+ self::$installed = $data;
227
+ }
228
+ }
vendor/composer/autoload_classmap.php CHANGED
@@ -6,4 +6,5 @@ $vendorDir = dirname(dirname(__FILE__));
6
  $baseDir = dirname($vendorDir);
7
 
8
  return array(
 
9
  );
6
  $baseDir = dirname($vendorDir);
7
 
8
  return array(
9
+ 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
10
  );
vendor/composer/autoload_real.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
- class ComposerAutoloaderInit379ca36df2589cb97644f9a0a1e12009
6
  {
7
  private static $loader;
8
 
@@ -22,15 +22,15 @@ class ComposerAutoloaderInit379ca36df2589cb97644f9a0a1e12009
22
  return self::$loader;
23
  }
24
 
25
- spl_autoload_register(array('ComposerAutoloaderInit379ca36df2589cb97644f9a0a1e12009', 'loadClassLoader'), true, true);
26
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
27
- spl_autoload_unregister(array('ComposerAutoloaderInit379ca36df2589cb97644f9a0a1e12009', 'loadClassLoader'));
28
 
29
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
30
  if ($useStaticLoader) {
31
- require_once __DIR__ . '/autoload_static.php';
32
 
33
- call_user_func(\Composer\Autoload\ComposerStaticInit379ca36df2589cb97644f9a0a1e12009::getInitializer($loader));
34
  } else {
35
  $map = require __DIR__ . '/autoload_namespaces.php';
36
  foreach ($map as $namespace => $path) {
@@ -51,19 +51,19 @@ class ComposerAutoloaderInit379ca36df2589cb97644f9a0a1e12009
51
  $loader->register(true);
52
 
53
  if ($useStaticLoader) {
54
- $includeFiles = Composer\Autoload\ComposerStaticInit379ca36df2589cb97644f9a0a1e12009::$files;
55
  } else {
56
  $includeFiles = require __DIR__ . '/autoload_files.php';
57
  }
58
  foreach ($includeFiles as $fileIdentifier => $file) {
59
- composerRequire379ca36df2589cb97644f9a0a1e12009($fileIdentifier, $file);
60
  }
61
 
62
  return $loader;
63
  }
64
  }
65
 
66
- function composerRequire379ca36df2589cb97644f9a0a1e12009($fileIdentifier, $file)
67
  {
68
  if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
69
  require $file;
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
+ class ComposerAutoloaderInitbc8b015f48b680dc9837def04d672ebf
6
  {
7
  private static $loader;
8
 
22
  return self::$loader;
23
  }
24
 
25
+ spl_autoload_register(array('ComposerAutoloaderInitbc8b015f48b680dc9837def04d672ebf', 'loadClassLoader'), true, true);
26
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
27
+ spl_autoload_unregister(array('ComposerAutoloaderInitbc8b015f48b680dc9837def04d672ebf', 'loadClassLoader'));
28
 
29
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
30
  if ($useStaticLoader) {
31
+ require __DIR__ . '/autoload_static.php';
32
 
33
+ call_user_func(\Composer\Autoload\ComposerStaticInitbc8b015f48b680dc9837def04d672ebf::getInitializer($loader));
34
  } else {
35
  $map = require __DIR__ . '/autoload_namespaces.php';
36
  foreach ($map as $namespace => $path) {
51
  $loader->register(true);
52
 
53
  if ($useStaticLoader) {
54
+ $includeFiles = Composer\Autoload\ComposerStaticInitbc8b015f48b680dc9837def04d672ebf::$files;
55
  } else {
56
  $includeFiles = require __DIR__ . '/autoload_files.php';
57
  }
58
  foreach ($includeFiles as $fileIdentifier => $file) {
59
+ composerRequirebc8b015f48b680dc9837def04d672ebf($fileIdentifier, $file);
60
  }
61
 
62
  return $loader;
63
  }
64
  }
65
 
66
+ function composerRequirebc8b015f48b680dc9837def04d672ebf($fileIdentifier, $file)
67
  {
68
  if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
69
  require $file;
vendor/composer/autoload_static.php CHANGED
@@ -4,15 +4,20 @@
4
 
5
  namespace Composer\Autoload;
6
 
7
- class ComposerStaticInit379ca36df2589cb97644f9a0a1e12009
8
  {
9
  public static $files = array (
10
  '9fef4034ed73e26a337d9856ea126f7f' => __DIR__ . '/..' . '/codeinwp/themeisle-sdk/load.php',
11
  );
12
 
 
 
 
 
13
  public static function getInitializer(ClassLoader $loader)
14
  {
15
  return \Closure::bind(function () use ($loader) {
 
16
 
17
  }, null, ClassLoader::class);
18
  }
4
 
5
  namespace Composer\Autoload;
6
 
7
+ class ComposerStaticInitbc8b015f48b680dc9837def04d672ebf
8
  {
9
  public static $files = array (
10
  '9fef4034ed73e26a337d9856ea126f7f' => __DIR__ . '/..' . '/codeinwp/themeisle-sdk/load.php',
11
  );
12
 
13
+ public static $classMap = array (
14
+ 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
15
+ );
16
+
17
  public static function getInitializer(ClassLoader $loader)
18
  {
19
  return \Closure::bind(function () use ($loader) {
20
+ $loader->classMap = ComposerStaticInitbc8b015f48b680dc9837def04d672ebf::$classMap;
21
 
22
  }, null, ClassLoader::class);
23
  }
vendor/composer/installed.json CHANGED
@@ -1,42 +1,51 @@
1
- [
2
- {
3
- "name": "codeinwp/themeisle-sdk",
4
- "version": "3.2.15",
5
- "version_normalized": "3.2.15.0",
6
- "source": {
7
- "type": "git",
8
- "url": "https://github.com/Codeinwp/themeisle-sdk.git",
9
- "reference": "95b7447a5f4faba410c281c4bf278fbd740fed71"
10
- },
11
- "dist": {
12
- "type": "zip",
13
- "url": "https://api.github.com/repos/Codeinwp/themeisle-sdk/zipball/95b7447a5f4faba410c281c4bf278fbd740fed71",
14
- "reference": "95b7447a5f4faba410c281c4bf278fbd740fed71",
15
- "shasum": ""
16
- },
17
- "require-dev": {
18
- "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
19
- "squizlabs/php_codesniffer": "^3.1",
20
- "wp-coding-standards/wpcs": "^1.0.0"
21
- },
22
- "time": "2020-07-23T15:02:10+00:00",
23
- "type": "library",
24
- "installation-source": "dist",
25
- "notification-url": "https://packagist.org/downloads/",
26
- "license": [
27
- "GPL-2.0+"
28
- ],
29
- "authors": [
30
- {
31
- "name": "ThemeIsle team",
32
- "email": "friends@themeisle.com",
33
- "homepage": "https://themeisle.com"
34
- }
35
- ],
36
- "description": "ThemeIsle SDK.",
37
- "homepage": "https://github.com/Codeinwp/themeisle-sdk",
38
- "keywords": [
39
- "wordpress"
40
- ]
41
- }
42
- ]
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "packages": [
3
+ {
4
+ "name": "codeinwp/themeisle-sdk",
5
+ "version": "3.2.15",
6
+ "version_normalized": "3.2.15.0",
7
+ "source": {
8
+ "type": "git",
9
+ "url": "https://github.com/Codeinwp/themeisle-sdk.git",
10
+ "reference": "95b7447a5f4faba410c281c4bf278fbd740fed71"
11
+ },
12
+ "dist": {
13
+ "type": "zip",
14
+ "url": "https://api.github.com/repos/Codeinwp/themeisle-sdk/zipball/95b7447a5f4faba410c281c4bf278fbd740fed71",
15
+ "reference": "95b7447a5f4faba410c281c4bf278fbd740fed71",
16
+ "shasum": ""
17
+ },
18
+ "require-dev": {
19
+ "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
20
+ "squizlabs/php_codesniffer": "^3.1",
21
+ "wp-coding-standards/wpcs": "^1.0.0"
22
+ },
23
+ "time": "2020-07-23T15:02:10+00:00",
24
+ "type": "library",
25
+ "installation-source": "dist",
26
+ "notification-url": "https://packagist.org/downloads/",
27
+ "license": [
28
+ "GPL-2.0+"
29
+ ],
30
+ "authors": [
31
+ {
32
+ "name": "ThemeIsle team",
33
+ "email": "friends@themeisle.com",
34
+ "homepage": "https://themeisle.com"
35
+ }
36
+ ],
37
+ "description": "ThemeIsle SDK.",
38
+ "homepage": "https://github.com/Codeinwp/themeisle-sdk",
39
+ "keywords": [
40
+ "wordpress"
41
+ ],
42
+ "support": {
43
+ "issues": "https://github.com/Codeinwp/themeisle-sdk/issues",
44
+ "source": "https://github.com/Codeinwp/themeisle-sdk/tree/master"
45
+ },
46
+ "install-path": "../codeinwp/themeisle-sdk"
47
+ }
48
+ ],
49
+ "dev": false,
50
+ "dev-package-names": []
51
+ }
vendor/composer/installed.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php return array (
2
+ 'root' =>
3
+ array (
4
+ 'pretty_version' => '1.1.2',
5
+ 'version' => '1.1.2.0',
6
+ 'aliases' =>
7
+ array (
8
+ ),
9
+ 'reference' => NULL,
10
+ 'name' => 'codeinwp/optimole-wp',
11
+ ),
12
+ 'versions' =>
13
+ array (
14
+ 'codeinwp/optimole-wp' =>
15
+ array (
16
+ 'pretty_version' => '1.1.2',
17
+ 'version' => '1.1.2.0',
18
+ 'aliases' =>
19
+ array (
20
+ ),
21
+ 'reference' => NULL,
22
+ ),
23
+ 'codeinwp/themeisle-sdk' =>
24
+ array (
25
+ 'pretty_version' => '3.2.15',
26
+ 'version' => '3.2.15.0',
27
+ 'aliases' =>
28
+ array (
29
+ ),
30
+ 'reference' => '95b7447a5f4faba410c281c4bf278fbd740fed71',
31
+ ),
32
+ ),
33
+ );