Skip to content

Commit b290930

Browse files
authored
Release version 4.1.2 (#96)
Merge pull request #96 from short-pixel-optimizer/updates
2 parents 55cb752 + 9dcd355 commit b290930

File tree

10 files changed

+32
-187
lines changed

10 files changed

+32
-187
lines changed

classes/Controller/ReplaceController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class ReplaceController
3131
const ERROR_DIRECTORY_NOTEXIST = 25;
3232

3333
protected $replaceType;
34+
/** @var string */
3435
protected $new_location;
3536
protected $timeMode;
3637
protected $newDate;
@@ -352,6 +353,7 @@ protected function setupTarget()
352353
{
353354
$otherTarget = $this->fs()->getFile($targetLocation . $this->new_filename);
354355
// Halt if new target exists, but not if it's the same ( overwriting itself )
356+
355357
if ($otherTarget->exists() && $otherTarget->getFullPath() !== $this->getSourceFile()->getFullPath() )
356358
{
357359
$this->lastError = self::ERROR_TARGET_EXISTS;
@@ -372,6 +374,7 @@ protected function setupTarget()
372374
else
373375
{
374376
$unique = wp_unique_filename($path, $this->new_filename);
377+
Log::addTemp('Unique FIleName', $unique);
375378
}
376379
$new_filename = apply_filters( 'emr_unique_filename', $unique, $path, $this->post_id );
377380
$targetFile = trailingslashit($path) . $new_filename;

classes/ViewController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ protected function viewError($errorCode, $errorData = array())
102102
break;
103103
case self::ERROR_TARGET_EXISTS:
104104
$message = __('The target file already exists in this directory. Please try another name / directory', 'enable-media-replace');
105+
$description = __('This error is shown because you try to move the image to another folder, which already has this file', 'enable-media-replace');
105106
break;
106107
case self::ERROR_DESTINATION_FAIL:
107108
$message = __('Something went wrong while writing the file or directory', 'enable-media-replace');

classes/ViewController/ReplaceViewController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function load()
5252

5353
$defaults = array(
5454
'replace_type' => 'replace',
55-
'timestamp_replace' => \EnableMediaReplace\Replacer::TIME_UPDATEMODIFIED,
55+
'timestamp_replace' => ReplaceController::TIME_UPDATEMODIFIED,
5656
'custom_date' => date("Y-m-d H:i:s"),
5757
'new_location' => false,
5858
'new_location_dir' => false,

classes/ViewController/UploadViewController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,22 @@ protected function getPost()
9797
{
9898
$ID = intval($_POST["ID"]); // legacy
9999
$replace_type = isset($_POST["replace_type"]) ? sanitize_text_field($_POST["replace_type"]) : false;
100-
$timestamp_replace = isset($_POST['timestamp_replace']) ? intval($_POST['timestamp_replace']) : Replacer::TIME_UPDATEMODIFIED;
100+
$timestamp_replace = isset($_POST['timestamp_replace']) ? intval($_POST['timestamp_replace']) : ReplaceController::TIME_UPDATEMODIFIED;
101101

102102
$remove_background = ( isset( $_POST['remove_after_progress'] ) ) ? true : false;
103103

104104
$do_new_location = isset($_POST['new_location']) ? true : false;
105-
$do_new_location = apply_filters('emr/replace/file_is_movable', true, $ID);
105+
$do_new_location = apply_filters('emr/replace/file_is_movable', $do_new_location, $ID);
106106
$new_location_dir = isset($_POST['location_dir']) ? sanitize_text_field($_POST['location_dir']) : null;
107107

108108
$is_custom_date = false;
109109

110110
switch ($timestamp_replace) {
111-
case \EnableMediaReplace\Replacer::TIME_UPDATEALL:
112-
case \EnableMediaReplace\Replacer::TIME_UPDATEMODIFIED:
111+
case ReplaceController::TIME_UPDATEALL:
112+
case ReplaceController::TIME_UPDATEMODIFIED:
113113
$datetime = current_time('mysql');
114114
break;
115-
case \EnableMediaReplace\Replacer::TIME_CUSTOM:
115+
case ReplaceController::TIME_CUSTOM:
116116
$custom_date = $_POST['custom_date_formatted'];
117117
$custom_hour = str_pad($_POST['custom_hour'], 2, 0, STR_PAD_LEFT);
118118
$custom_minute = str_pad($_POST['custom_minute'], 2, 0, STR_PAD_LEFT);

classes/emr-plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ public function admin_scripts()
334334
wp_register_script('emr_success', plugins_url('js/emr_success.js', EMR_ROOT_FILE), array(), EMR_VERSION, true);
335335

336336
wp_localize_script('emr_success', 'emr_success_options', array(
337-
'timeout' => apply_filters('emr/success/timeout', 10),
337+
'timeout' => apply_filters('emr/success/timeout', 5),
338338
));
339339
}
340340

classes/external/wp-offload.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@ public function updateOriginalPath($source_url, $target_url, $post_id)
188188
{
189189
$item = $this->getItemById($post_id);
190190

191+
// If no item comes back, probably it's not offloaded
192+
if (false === $item)
193+
{
194+
return;
195+
}
196+
197+
191198
$original_path = $item->original_path(); // Original path (non-scaled-)
192199
$original_source_path = $item->original_source_path();
193200
$path = $item->path();

enable-media-replace.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Enable Media Replace
44
* Plugin URI: https://wordpress.org/plugins/enable-media-replace/
55
* Description: Enable replacing media files by uploading a new file in the "Edit Media" section of the WordPress Media Library.
6-
* Version: 4.1.1
6+
* Version: 4.1.2
77
* Author: ShortPixel
88
* Author URI: https://shortpixel.com
99
* GitHub Plugin URI: https://github.com/short-pixel-optimizer/enable-media-replace
@@ -25,7 +25,7 @@
2525
*
2626
*/
2727

28-
define( 'EMR_VERSION', '4.1.1' );
28+
define( 'EMR_VERSION', '4.1.2' );
2929

3030
if ( ! defined( 'ABSPATH' ) ) {
3131
exit; // Exit if accessed directly.

readme.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Tags: replace, attachment, media, files, replace image, remove background, repla
55
Requires at least: 4.9.7
66
Tested up to: 6.2
77
Requires PHP: 5.6
8-
Stable tag: 4.1.1
8+
Stable tag: 4.1.2
99

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

@@ -69,6 +69,13 @@ If you want more control over the format in which the time is shown, you can use
6969

7070
== Changelog ==
7171

72+
= 4.1.2 =
73+
74+
Release date: April 24, 2023
75+
* Tweak: Reduced the wait time before redirecting to the media edit page to half (5s);
76+
* Fix: If an item is not offloaded, no attempt is made to update its data;
77+
* Fix: Removed some double spaces from the plugin strings (thanks to @Presskopp).
78+
7279
= 4.1.1 =
7380

7481
Release date: April 13, 2023

views/screen.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
//use \EnableMediaReplace\UIHelper;
99
use EnableMediaReplace\ShortPixelLogger\ShortPixelLogger as Log;
1010
use EnableMediaReplace\Notices\NoticeController as Notices;
11+
use EnableMediaReplace\Controller\ReplaceController as ReplaceController;
12+
1113

1214
/**
1315
* Uploadscreen for selecting and uploading new media file
@@ -64,7 +66,7 @@
6466
<input type="hidden" name="ID" value="<?php echo $attachment_id ?>" />
6567

6668
<p class='explainer'>
67-
<?php printf(esc_html__(' You are about to replace %s in your media library. This will be %spermanent%s . %s You can click on the new image panel and select a file from your computer. You can also drag and drop a file into this window', 'enable-media-replace'), '<b class="underline" title="' . $sourceFile->getFullPath() . '">' . $sourceFile->getFileName() . '</b>', '<b>','</b>', '<br>' );
69+
<?php printf(esc_html__(' You are about to replace %s in your media library. This will be %spermanent%s. %s You can click on the new image panel and select a file from your computer. You can also drag and drop a file into this window', 'enable-media-replace'), '<b class="underline" title="' . $sourceFile->getFullPath() . '">' . $sourceFile->getFileName() . '</b>', '<b>','</b>', '<br>' );
6870
?>
6971
</p>
7072

@@ -179,7 +181,7 @@
179181
$attachmentDate = new \dateTime($view->attachment->post_date);
180182

181183

182-
if ($settings['timestamp_replace'] == \EnableMediaReplace\Replacer::TIME_CUSTOM)
184+
if ($settings['timestamp_replace'] == ReplaceController::TIME_CUSTOM)
183185
{
184186
$date = new \dateTime($settings['custom_date']);
185187
}

views/upload.php

Lines changed: 0 additions & 175 deletions
This file was deleted.

0 commit comments

Comments
 (0)