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

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

82 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class Optml_woocommerce
5 *
6 * @reason Adding flags for ignoring the lazyloaded tags.
7 */
8 class Optml_woocommerce extends Optml_compatibility {
9
10
11 /**
12 * Should we load the integration logic.
13 *
14 * @return bool Should we load.
15 */
16 function should_load() {
17 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
18 return is_plugin_active( 'woocommerce/woocommerce.php' );
19 }
20
21 /**
22 * Register integration details.
23 */
24 public function register() {
25 if ( Optml_Main::instance()->admin->settings->use_lazyload() ) {
26 add_filter( 'optml_lazyload_early_flags', [ $this, 'add_lazyload_early_flag' ], PHP_INT_MAX, 1 );
27 }
28
29 }
30 /**
31 * Add ignore lazyload flag.
32 *
33 * @param array $flags Old flags.
34 *
35 * @return array New flags.
36 */
37 public function add_lazyload_early_flag( $flags = [] ) {
38 $flags[] = 'data-large_image';
39
40 return $flags;
41 }
42 /**
43 * Ads the product pages to the list of posts parents when querying images for offload.
44 *
45 * @param array $parents Default post parents.
46 *
47 * @return array New post parents that include product pages.
48 */
49 public function add_product_pages_to_image_query( $parents = [ 0 ] ) {
50 $paged = 1;
51 $query_args = [
52 'post_type' => 'product',
53 'fields' => 'ids',
54 'posts_per_page' => 150,
55 'post_status' => 'publish',
56 'paged' => $paged,
57 ];
58 $products = new \WP_Query( $query_args );
59 $ids = $products->get_posts();
60 while ( ! empty( $ids ) ) {
61 $paged++;
62 $parents = array_merge( $parents, $ids );
63 $query_args['paged'] = $paged;
64 $products = new \WP_Query( $query_args );
65 $ids = $products->get_posts();
66 }
67
68 return $parents;
69 }
70 /**
71 * Should we early load the compatibility?
72 *
73 * @return bool Whether to load the compatibility or not.
74 */
75 public function should_load_early() {
76 if ( Optml_Main::instance()->admin->settings->get( 'offload_media' ) === 'enabled' ) {
77 return true;
78 }
79 return false;
80 }
81 }
82