|
| 1 | +<?php |
| 2 | +namespace EnableMediaReplace\Replacer\Modules; |
| 3 | + |
| 4 | +class Elementor |
| 5 | +{ |
| 6 | + private static $instance; |
| 7 | + |
| 8 | + protected $queryKey = 'elementor'; |
| 9 | + |
| 10 | + public static function getInstance() |
| 11 | + { |
| 12 | + if (is_null(self::$instance)) |
| 13 | + self::$instance = new Elementor(); |
| 14 | + |
| 15 | + return self::$instance; |
| 16 | + } |
| 17 | + |
| 18 | + public function __construct() |
| 19 | + { |
| 20 | + if ($this->elementor_is_active()) // elementor is active |
| 21 | + { |
| 22 | + add_filter('shortpixel/replacer/custom_replace_query', array($this, 'addElementor'), 10, 4); // custom query for elementor \ // problem |
| 23 | + // @todo Fix this for SPIO |
| 24 | + //add_action('enable-media-replace-upload-done', array($this, 'removeCache') ); |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + public function addElementor($items, $base_url, $search_urls, $replace_urls) |
| 29 | + { |
| 30 | + $base_url = $this->addSlash($base_url); |
| 31 | + $el_search_urls = $search_urls; //array_map(array($this, 'addslash'), $search_urls); |
| 32 | + $el_replace_urls = $replace_urls; //array_map(array($this, 'addslash'), $replace_urls); |
| 33 | + $items[$this->queryKey] = array('base_url' => $base_url, 'search_urls' => $el_search_urls, 'replace_urls' => $el_replace_urls); |
| 34 | + return $items; |
| 35 | + } |
| 36 | + |
| 37 | + public function addSlash($value) |
| 38 | + { |
| 39 | + global $wpdb; |
| 40 | + $value= ltrim($value, '/'); // for some reason the left / isn't picked up by Mysql. |
| 41 | + $value= str_replace('/', '\/', $value); |
| 42 | + $value = $wpdb->esc_like(($value)); //(wp_slash) / str_replace('/', '\/', $value); |
| 43 | + |
| 44 | + return $value; |
| 45 | + } |
| 46 | + |
| 47 | + protected function elementor_is_active() |
| 48 | + { |
| 49 | + $bool = false; |
| 50 | + |
| 51 | + if (defined('ELEMENTOR_VERSION')) |
| 52 | + $bool = true; |
| 53 | + |
| 54 | + return apply_filters('emr/externals/elementor_is_active', $bool); // manual override |
| 55 | + } |
| 56 | + |
| 57 | + public function removeCache() |
| 58 | + { |
| 59 | + \Elementor\Plugin::$instance->files_manager->clear_cache(); |
| 60 | + } |
| 61 | +} |
0 commit comments