PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / 4.2.8
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization v4.2.8
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 / pinterest.php

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

126 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class Pinterest.
5 *
6 * @reason Pinterest plugins picks eco images to share
7 */
8 class Optml_pinterest extends Optml_compatibility {
9 /**
10 * String with all css selectors to target
11 *
12 * @var string
13 */
14 private $selectors;
15 /**
16 * Should we load the integration logic.
17 *
18 * @return bool Should we load.
19 */
20 public function should_load() {
21
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( ', ', $selectors_array );
35 return $load;
36 }
37
38 /**
39 * Register integration details.
40 */
41 public function register() {
42 add_action(
43 'wp_enqueue_scripts',
44 function () {
45 wp_register_script( 'optml-pinterest', false );
46 wp_enqueue_script( 'optml-pinterest' );
47 $script = sprintf(
48 '
49 (function(w, d){
50 w.addEventListener("load", function() {
51 const addCustomEventListener = function (selector, event, handler) {
52 let rootElement = document.querySelector(\'body\');
53 rootElement.addEventListener(event, function (evt) {
54 var targetElement = evt.target;
55 while (targetElement != null) {
56 if (targetElement.matches(selector)) {
57 handler(evt);
58 return;
59 }
60 targetElement = targetElement.parentElement;
61 }
62 },
63 true
64 );
65 };
66 addCustomEventListener(\'%s\',\'mouseover\',function(){
67 let images = d.getElementsByTagName( "img" );
68 for ( let i = 0; i < images.length; i++ ) {
69 if ( "optSrc" in images[i].dataset ) {
70 images[i].src = images[i].dataset.optSrc ;
71 }
72 }
73 });
74 });
75 }(window, document));
76 ',
77 $this->selectors
78 );
79 wp_add_inline_script( 'optml-pinterest', $script );
80 }
81 );
82 }
83 /**
84 Check if plugin is active.
85
86 @return bool
87 */
88 private function isShareaholic() {
89
90 if ( ! is_plugin_active( 'shareaholic/shareaholic.php' ) ) {
91 return false;
92 }
93 return true;
94 }
95 /**
96 * Check if plugin is active.
97 *
98 * @return bool
99 */
100 private function isSassySocialShare() {
101
102 if ( ! is_plugin_active( 'sassy-social-share/sassy-social-share.php' ) ) {
103 return false;
104 }
105 $ss_options = get_option( 'heateor_sss' );
106 $ss_bars = [ 'vertical_re_providers', 'horizontal_re_providers' ];
107 if ( ! is_array( $ss_options ) ) {
108 return false;
109 }
110 foreach ( $ss_bars as $key => $bar ) {
111 if ( ! isset( $ss_options[ $bar ] ) ) {
112 continue;
113 }
114 foreach ( $ss_options[ $bar ] as $index => $value ) {
115 if ( isset( $value ) && is_string( $value ) ) {
116 if ( strpos( $value, 'pinterest' ) !== false ) {
117 return true;
118 }
119 }
120 }
121 }
122
123 return false;
124 }
125 }
126