elementor
7 months ago
class-autoptimize-compatibility.php
7 months ago
class-elasticpress-compatibility.php
7 months ago
class-elementor-compatibility.php
7 months ago
class-foobox-compatibility.php
7 months ago
class-foogallery-compatibility.php
7 months ago
class-foovideo-compatibility.php
7 months ago
class-jetpack-compatibility.php
7 months ago
class-polylang-compatibility.php
7 months ago
class-responsive-lightbox-dfactory-compatibility.php
7 months ago
class-wpoptimize-compatibility.php
7 months ago
class-wprocket-compatibility.php
7 months ago
view-foovideo-offer.php
7 months ago
class-wprocket-compatibility.php
65 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Adds support for WPRocket in FooGallery |
| 4 | * Created by brad. |
| 5 | * Date: 11/06/2017 |
| 6 | * |
| 7 | * @since 1.3.3 |
| 8 | */ |
| 9 | if ( ! class_exists( 'FooGallery_WPRocket_Compatibility' ) ) { |
| 10 | |
| 11 | class FooGallery_WPRocket_Compatibility { |
| 12 | |
| 13 | function __construct() { |
| 14 | add_action( 'plugins_loaded', array( $this, 'init_wprocket' ) ); |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Init hooks for WPRocket |
| 19 | */ |
| 20 | function init_wprocket() { |
| 21 | //check that WPRocket is activated |
| 22 | if ( defined( 'WP_ROCKET_VERSION' ) ) { |
| 23 | //add_filter( 'foogallery_process_image_url', array( $this, 'force_images_to_use_rocket_cdn' ), 999 ); |
| 24 | add_filter( 'foogallery_attachment_html_image_attributes', array( $this, 'alter_image_attributes' ), 10, 3 ); |
| 25 | add_filter( 'rocket_excluded_inline_js_content', array( $this, 'ensure_foogallery_items_excluded' ) ); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | function ensure_foogallery_items_excluded( $excluded_inline ) { |
| 30 | $excluded_inline[] = 'window["foogallery-gallery-'; |
| 31 | return $excluded_inline; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * |
| 36 | * @param $url |
| 37 | * |
| 38 | * @return mixed |
| 39 | */ |
| 40 | function force_images_to_use_rocket_cdn( $url ) { |
| 41 | if ( function_exists( 'get_rocket_cdn_url' ) ) { |
| 42 | return get_rocket_cdn_url( $url ); |
| 43 | } |
| 44 | |
| 45 | return $url; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Ensure that WPRocket lazyloading does not interfere with FooGallery's lazy loading |
| 50 | * |
| 51 | * @uses "foogallery_attachment_html_image_attributes" filter |
| 52 | * |
| 53 | * @param $attr |
| 54 | * @param $args |
| 55 | * @param object|FooGalleryAttachment $object |
| 56 | * |
| 57 | * @return array |
| 58 | */ |
| 59 | function alter_image_attributes( $attr, $args, $object ) { |
| 60 | $attr['data-no-lazy'] = '1'; |
| 61 | return $attr; |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 |