|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Class Optml_sassy_social_share. |
| 5 | + * |
| 6 | + * @reason Sassy social share picks eco images to share |
| 7 | + */ |
| 8 | +class Optml_sassy_social_share extends Optml_compatibility { |
| 9 | + /** |
| 10 | + * Should we load the integration logic. |
| 11 | + * |
| 12 | + * @return bool Should we load. |
| 13 | + */ |
| 14 | + function should_load() { |
| 15 | + include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 16 | + |
| 17 | + if ( ! is_plugin_active( 'sassy-social-share/sassy-social-share.php' ) ) { |
| 18 | + return false; |
| 19 | + } |
| 20 | + $ss_options = get_option( 'heateor_sss' ); |
| 21 | + $ss_bars = ['vertical_re_providers', 'horizontal_re_providers']; |
| 22 | + if ( ! is_array( $ss_options ) ) { |
| 23 | + return false; |
| 24 | + } |
| 25 | + foreach ( $ss_bars as $key => $bar ) { |
| 26 | + if ( ! isset( $ss_options[ $bar ] ) ) { |
| 27 | + continue; |
| 28 | + } |
| 29 | + foreach ( $ss_options[ $bar ] as $index => $value ) { |
| 30 | + if ( isset( $value ) && is_string( $value ) ) { |
| 31 | + if ( strpos( $value, 'pinterest' ) !== false ) { |
| 32 | + return true; |
| 33 | + } |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + return false; |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Register integration details. |
| 43 | + */ |
| 44 | + public function register() { |
| 45 | + add_action( |
| 46 | + 'wp_enqueue_scripts', |
| 47 | + function () { |
| 48 | + wp_register_script( 'optml-typekit', false ); |
| 49 | + wp_enqueue_script( 'optml-typekit' ); |
| 50 | + $script = ' |
| 51 | + (function(w, d){ |
| 52 | + w.addEventListener("load", function(){ |
| 53 | + let p=d.querySelectorAll( ".heateorSssSharing.heateorSssPinterestBackground" ); |
| 54 | + p.forEach ( function (button,index) { |
| 55 | + button.addEventListener( "mouseover", () => { |
| 56 | + let images = d.getElementsByTagName( "img" ); |
| 57 | + for ( let i = 0; i < images.length; i++ ) { |
| 58 | + if ( "optSrc" in images[i].dataset ) { |
| 59 | + images[i].src = images[i].dataset.optSrc ; |
| 60 | + } |
| 61 | + } |
| 62 | + },{once:true} ); |
| 63 | + }); |
| 64 | + |
| 65 | + }); |
| 66 | + }(window, document)); |
| 67 | + '; |
| 68 | + wp_add_inline_script( 'optml-typekit', $script ); |
| 69 | + } |
| 70 | + ); |
| 71 | + } |
| 72 | +} |
0 commit comments