Skip to content

Commit

Permalink
Release version 4.0.3 (#89)
Browse files Browse the repository at this point in the history
Merge pull request #89 from short-pixel-optimizer/hotfix-4.0.3
  • Loading branch information
pdobrescu authored Feb 21, 2023
2 parents 57ed323 + 5407252 commit 88d6347
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 81 deletions.
1 change: 0 additions & 1 deletion build/shortpixel/log/src/ShortPixelLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ public function loadView()
$controller = $this;

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

Expand Down
60 changes: 57 additions & 3 deletions build/shortpixel/notices/src/NoticeModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class NoticeModel //extends ShortPixelModel
protected $is_dismissed = false; // for persistent notices,
protected $suppress_until = null;
protected $suppress_period = -1;
protected $include_screens = array();
protected $exclude_screens = array();
public $is_removable = true; // if removable, display a notice dialog with red X or so.
public $messageType = self::NOTICE_NORMAL;

Expand All @@ -33,7 +35,6 @@ public function __construct($message, $messageType = self::NOTICE_NORMAL)
{
$this->message = $message;
$this->messageType = $messageType;

}

public function isDone()
Expand All @@ -43,9 +44,7 @@ public function isDone()
{
if (time() >= $this->suppress_until)
{
//Log::addDebug('')
$this->is_persistent = false; // unpersist, so it will be cleaned and dropped.

}
}

Expand Down Expand Up @@ -98,6 +97,53 @@ public function addDetail($detail, $clean = false)
$this->details[] = $detail;
}

/**
* @param $method String Include or Exclude
* @param $includes String|Array Screen Names to Include / Exclude either string, or array
*/
public function limitScreens($method, $screens)
{
if ($method == 'exclude')
{
$var = 'exclude_screens';
}
else {
$var = 'include_screens';
}

if (is_array($screens))
{
$this->$var = array_merge($this->$var, $screens);
}
else {
$this->{$var}[] = $screens; // strange syntax is PHP 5.6 compat.
}
}

/* Checks if Notice is allowed on this screen
* @param @screen_id String The screen Id to check ( most likely current one, via EnvironmentModel)
*/
public function checkScreen($screen_id)
{
if (in_array($screen_id, $this->exclude_screens))
{
return false;
}
if (in_array($screen_id, $this->include_screens))
{
return true;
}

// if include is set, don't show if not screen included.
if (count($this->include_screens) == 0)
{
return true;
}
else {
return false;
}
}



/** Set a notice persistent. Meaning it shows every page load until dismissed.
Expand Down Expand Up @@ -136,6 +182,14 @@ public static function setIcon($notice_type, $icon)
self::$icons[$type] = $icon;
}

public function _debug_getvar($var)
{
if (property_exists($this, $var))
{
return $this->$var;
}
}

private function checkIncomplete($var)
{
return ($var instanceof \__PHP_Incomplete_Class);
Expand Down
6 changes: 3 additions & 3 deletions classes/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public function flushCache($args)
$this->checkCaches();

// general WP
//if ($post_id > 0)
// clean_post_cache($post_id);
//else
if ($args['flush_mode'] === 'post' && $post_id > 0)
clean_post_cache($post_id);
else
wp_cache_flush();

/* Verified working without.
Expand Down
36 changes: 2 additions & 34 deletions classes/emr-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected function nopriv_plugin_actions()
public function plugin_actions()
{
$this->plugin_path = plugin_dir_path(EMR_ROOT_FILE);
$this->plugin_url = plugin_dir_url(EMR_ROOT_FILE);
//$this->plugin_url = plugin_dir_url(EMR_ROOT_FILE);

// loads the dismiss hook.
$notices = Notices::getInstance();
Expand All @@ -132,9 +132,6 @@ public function plugin_actions()
//add_filter('upload_mimes', array($this,'add_mime_types'), 1, 1);

// notices
add_action('admin_notices', array($this,'display_notices'));
add_action('network_admin_notices', array($this,'display_network_notices'));
add_action('wp_ajax_emr_dismiss_notices', array($this,'dismiss_notices'));

// editors
add_action('add_meta_boxes_attachment', array($this, 'add_meta_boxes'), 10, 2);
Expand Down Expand Up @@ -163,7 +160,6 @@ public function menu()
$title = (isset($_REQUEST['action']) && ($_REQUEST['action'] === 'emr_prepare_remove')) ? esc_html__("Remove background", "enable-media-replace") : $title;
add_submenu_page('upload.php',$title, $title, 'upload_files', 'enable-media-replace/enable-media-replace.php', array($this, 'route'));


}

public function hide_sub_menu($submenu_file)
Expand Down Expand Up @@ -201,7 +197,7 @@ public function setScreen()
$screen = get_current_screen();

$notice_pages = array('attachment', 'media_page_enable-media-replace/enable-media-replace', 'upload' );
if ( in_array($screen->id, $notice_pages) )
if ( in_array($screen->id, $notice_pages) && true === emr()->useFeature('background'))
{

$notices = Notices::getInstance();
Expand Down Expand Up @@ -564,34 +560,6 @@ public function add_media_action($actions, $post)
}


public function display_notices()
{
$current_screen = get_current_screen();

$crtScreen = function_exists("get_current_screen") ? get_current_screen() : (object)array("base" => false);
/*
if(current_user_can( 'activate_plugins' ) && !get_option( 'emr_news') && !is_plugin_active('shortpixel-image-optimiser/wp-shortpixel.php')
&& ($crtScreen->base == "upload" || $crtScreen->base == "plugins")
//for network installed plugins, don't display the message on subsites.
&& !(function_exists('is_multisite') && is_multisite() && is_plugin_active_for_network('enable-media-replace/enable-media-replace.php') && !is_main_site()))
{
require_once($this->plugin_path . '/views/notice.php');
} */
}

public function display_network_notices()
{
if (current_user_can('activate_plugins') && !get_option('emr_news') && !is_plugin_active_for_network('shortpixel-image-optimiser/wp-shortpixel.php')) {
require_once(str_replace("enable-media-replace.php", "notice.php", __FILE__));
}
}

/* Ajax function to dismiss notice */
public function dismiss_notices()
{
update_option('emr_news', true);
exit(json_encode(array("Status" => 0)));
}

/** Outputs the replaced date of the media on the edit_attachment screen
*
Expand Down
16 changes: 6 additions & 10 deletions classes/replacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,16 @@ public function __construct($post_id)
{
$this->post_id = $post_id;

$source_file = false;
if (function_exists('wp_get_original_image_path')) // WP 5.3+
{
$source_file = wp_get_original_image_path($post_id);
}

if ($source_file === false) // if it's not an image, returns false, use the old way.
{
$source_file = trim(get_attached_file($post_id, apply_filters( 'emr_unfiltered_get_attached_file', true )));
}
else {
$this->source_is_scaled = true;
}
}
else
$source_file = trim(get_attached_file($post_id, apply_filters( 'emr_unfiltered_get_attached_file', true )));
if (false === $source_file)
{
$source_file = trim(get_attached_file($post_id, apply_filters( 'emr_unfiltered_get_attached_file', true )));
}

/* It happens that the SourceFile returns relative / incomplete when something messes up get_upload_dir with an error something.
This case shoudl be detected here and create a non-relative path anyhow..
Expand Down
6 changes: 6 additions & 0 deletions css/admin.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion css/admin.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions enable-media-replace.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Enable Media Replace
* Plugin URI: https://wordpress.org/plugins/enable-media-replace/
* Description: Enable replacing media files by uploading a new file in the "Edit Media" section of the WordPress Media Library.
* Version: 4.0.2
* Version: 4.0.3
* Author: ShortPixel
* Author URI: https://shortpixel.com
* GitHub Plugin URI: https://github.com/short-pixel-optimizer/enable-media-replace
Expand All @@ -27,7 +27,7 @@

namespace EnableMediaReplace;

define( 'EMR_VERSION', '4.0.2' );
define( 'EMR_VERSION', '4.0.3' );

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
Expand Down
Binary file added img/sp-banner-theme.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Contributors: ShortPixel
Donate link: https://www.paypal.me/resizeImage
Tags: replace, attachment, media, files, replace image, remove background, replace jpg, change media, replace media, image, file
Requires at least: 4.9.7
Tested up to: 6.1
Tested up to: 6.2
Requires PHP: 5.6
Stable tag: 4.0.2
Stable tag: 4.0.3

Easily replace any attached image/file by simply uploading a new file in the Media Library edit view - a real time saver!

Expand Down Expand Up @@ -61,6 +61,13 @@ If you want more control over the format in which the time is shown, you can use

== Changelog ==

= 4.0.3 =

Release date: February 21, 2023
* Fix: background removal notification is no longer displayed when this feature is disabled with the filter;
* Compat: improved compatibility with PHP 8.1 and 8.2
* Tweak: updated the banners on the replace page.

= 4.0.2 =

Release date: January 13, 2023
Expand Down
10 changes: 10 additions & 0 deletions scss/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@
{
padding: 12px;
}

// *** UPSELL SNIPPET
.shortpixel-offer
{
background: #fff;
Expand Down Expand Up @@ -359,6 +361,7 @@
img { max-width: 140px; max-height: 140px; margin: 0; }
}


&.spio // shortpixel
{
}
Expand All @@ -369,6 +372,13 @@
{
background: #fff;
}
&.theme-offer
{
background: #fff;
img {
max-width: 100%;
}
}
}

@media( max-width: 1200px)
Expand Down
Loading

0 comments on commit 88d6347

Please sign in to comment.