Skip to content

Commit

Permalink
Release version 3.5.0 (#68)
Browse files Browse the repository at this point in the history
Merge pull request #68 from short-pixel-optimizer/release-3.5.0
  • Loading branch information
pdobrescu authored Oct 29, 2020
2 parents 30ce74c + 52f5e51 commit 9b75054
Show file tree
Hide file tree
Showing 17 changed files with 661 additions and 121 deletions.
1 change: 1 addition & 0 deletions build/shortpixel/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
require_once (dirname(__FILE__) . "/PackageLoader.php");
$loader = new EnableMediaReplace\Build\PackageLoader();
$loader->load(__DIR__);

14 changes: 13 additions & 1 deletion build/shortpixel/log/src/ShortPixelLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ protected function addLog($message, $level, $data = array())
return;
}

// Force administrator on manuals.
if ( $this->is_manual_request )
{
if (! function_exists('wp_get_current_user')) // not loaded yet
return false;

$user_is_administrator = (current_user_can('manage_options')) ? true : false;
if (! $user_is_administrator)
return false;
}

// Check where to log to.
if ($this->logPath === false)
{
Expand Down Expand Up @@ -237,7 +248,7 @@ public static function addWarn($message, $args = array())
$log = self::getInstance();
$log->addLog($message, $level, $args);
}
// Alias, since it goes wrong so often.
// Alias, since it goes wrong so often.
public static function addWarning($message, $args = array())
{
self::addWarn($message, $args);
Expand Down Expand Up @@ -326,6 +337,7 @@ public function loadView()
$controller = $this;

$template_path = __DIR__ . '/' . $this->template . '.php';
// var_dump( $template_path);
if (file_exists($template_path))
{

Expand Down
17 changes: 17 additions & 0 deletions classes/cache.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<?php
namespace EnableMediaReplace;

use EnableMediaReplace\ShortPixelLogger\ShortPixelLogger as Log;

class emrCache
{
protected $has_supercache = false; // supercache seems to replace quite fine, without our help. @todo Test if this is needed
protected $has_w3tc = false;
protected $has_wpengine = false;
protected $has_fastestcache = false;
protected $has_siteground = false;
protected $has_litespeed = false;

public function __construct()
{
Expand Down Expand Up @@ -35,6 +38,11 @@ public function checkCaches()
$this->has_siteground = true;
}

if (defined( 'LSCWP_DIR' ))
{
$this->has_litespeed = true;
}

// @todo WpRocket?
// @todo BlueHost Caching?
}
Expand Down Expand Up @@ -78,6 +86,10 @@ public function flushCache($args)
if ($this->has_fastestcache)
$this->removeFastestCache();

if ($this->has_litespeed)
$this->litespeedReset($post_id);

do_action('emr/cache/flush', $post_id);
}

protected function removeSuperCache()
Expand Down Expand Up @@ -118,4 +130,9 @@ protected function removeSiteGround()
sg_cachepress_purge_cache();
}

protected function litespeedReset($post_id)
{
do_action('litespeed_media_reset', $post_id);
}

}
2 changes: 1 addition & 1 deletion classes/emr-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function init()
load_plugin_textdomain( 'enable-media-replace', false, basename(dirname(EMR_ROOT_FILE) ) . '/languages' );

// Load Submodules
Log::addDebug('Plugin Init');

$notices = Notices::getInstance();

// Enqueue notices
Expand Down
60 changes: 60 additions & 0 deletions classes/external/elementor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
namespace EnableMediaReplace\Externals;

class Elementor
{
private static $instance;

protected $queryKey = 'elementor';

public static function getInstance()
{
if (is_null(self::$instance))
self::$instance = new Elementor();

return self::$instance;
}

public function __construct()
{
if ($this->elementor_is_active()) // elementor is active
{
add_filter('emr/replacer/custom_replace_query', array($this, 'addElementor'), 10, 4); // custom query for elementor \ // problem
add_action('enable-media-replace-upload-done', array($this, 'removeCache') );
}
}

public function addElementor($items, $base_url, $search_urls, $replace_urls)
{
$base_url = $this->addSlash($base_url);
$el_search_urls = $search_urls; //array_map(array($this, 'addslash'), $search_urls);
$el_replace_urls = $replace_urls; //array_map(array($this, 'addslash'), $replace_urls);
$items[$this->queryKey] = array('base_url' => $base_url, 'search_urls' => $el_search_urls, 'replace_urls' => $el_replace_urls);
return $items;
}

public function addSlash($value)
{
global $wpdb;
$value= ltrim($value, '/'); // for some reason the left / isn't picked up by Mysql.
$value= str_replace('/', '\/', $value);
$value = $wpdb->esc_like(($value)); //(wp_slash) / str_replace('/', '\/', $value);

return $value;
}

protected function elementor_is_active()
{
$bool = false;

if (defined('ELEMENTOR_VERSION'))
$bool = true;

return apply_filters('emr/externals/elementor_is_active', $bool); // manual override
}

public function removeCache()
{
\Elementor\Plugin::$instance->files_manager->clear_cache();
}
}
52 changes: 52 additions & 0 deletions classes/external/wpbakery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
namespace EnableMediaReplace\Externals;


// Note! This class doubles as integration for both Visual Composer *and* WP Bakery. They both need URLENCODE.
class WpBakery
{
private static $instance;

protected $queryKey = 'wpbakery';

public static function getInstance()
{
if (is_null(self::$instance))
self::$instance = new WpBakery();

return self::$instance;
}

public function __construct()
{
if ($this->bakery_is_active()) // elementor is active
{
add_filter('emr/replacer/custom_replace_query', array($this, 'addURLEncoded'), 10, 4); // custom query for elementor \ // problem
}
}

public function addUrlEncoded($items, $base_url, $search_urls, $replace_urls)
{
$base_url = $this->addEncode($base_url);
$el_search_urls = array_map(array($this, 'addEncode'), $search_urls);
$el_replace_urls = array_map(array($this, 'addEncode'), $replace_urls);
$items[$this->queryKey] = array('base_url' => $base_url, 'search_urls' => $el_search_urls, 'replace_urls' => $el_replace_urls);
return $items;
}

public function addEncode($value)
{
return urlencode($value);
}

protected function bakery_is_active()
{
$bool = false;

// did_action -> wpbakery , VCV_version -> detect Visual Composer
if (did_action('vc_plugins_loaded') || defined('VCV_VERSION'))
$bool = true;

return apply_filters('emr/externals/urlencode_is_active', $bool); // manual override
}
}
37 changes: 25 additions & 12 deletions classes/externals.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
use EnableMediaReplace\ShortPixelLogger\ShortPixelLogger as Log;
use EnableMediaReplace\Notices\NoticeController as Notices;

use EnableMediaReplace\Externals\Elementor as Elementor;
use EnableMediaReplace\Externals\WpBakery as WpBakery;

class Externals
{
Expand All @@ -11,27 +13,29 @@ class Externals

protected $messages = array();


public function __construct()
{
// These hooks prevent loading of options when plugin conflicts arise.
add_filter('emr_display_replace_type_options', array($this, 'get_replace_type'));
add_filter('emr_enable_replace_and_search', array($this, 'get_replacesearch_type'));

add_action('emr_after_replace_type_options', array($this, 'get_messages'));


$this->check();
}

protected function check()
{
/*if (class_exists('FLBuilder'))
{
$this->replaceSearchType = false;
$this->messages[] = __('Replace and Search feature is not compatible with Beaver Builder.', 'enable-media-replace');
} */
// integrations
$this->loadElementor();
$this->loadBakery(); // in case of urlencoded issues, this class should be used probably.
}

protected function check() // check if any of the options should be disabled due to conflicts
{
/*if (class_exists('FLBuilder'))
{
$this->replaceSearchType = false;
$this->messages[] = __('Replace and Search feature is not compatible with Beaver Builder.', 'enable-media-replace');
} */
}

public function get_replace_type($bool)
{
if ($this->replaceType === null)
Expand All @@ -54,7 +58,16 @@ public function get_messages()
{
echo '<span class="nofeature-notice"><p>'. $message . '</p></span>';
}
}

public function loadElementor()
{
Elementor::getInstance();
}

}
public function loadBakery()
{
WpBakery::getInstance();
}

} // class
Loading

0 comments on commit 9b75054

Please sign in to comment.