Skip to content

Commit

Permalink
Release version 4.1.2 (#96)
Browse files Browse the repository at this point in the history
Merge pull request #96 from short-pixel-optimizer/updates
  • Loading branch information
pdobrescu authored Apr 24, 2023
2 parents 55cb752 + 9dcd355 commit b290930
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 187 deletions.
3 changes: 3 additions & 0 deletions classes/Controller/ReplaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ReplaceController
const ERROR_DIRECTORY_NOTEXIST = 25;

protected $replaceType;
/** @var string */
protected $new_location;
protected $timeMode;
protected $newDate;
Expand Down Expand Up @@ -352,6 +353,7 @@ protected function setupTarget()
{
$otherTarget = $this->fs()->getFile($targetLocation . $this->new_filename);
// Halt if new target exists, but not if it's the same ( overwriting itself )

if ($otherTarget->exists() && $otherTarget->getFullPath() !== $this->getSourceFile()->getFullPath() )
{
$this->lastError = self::ERROR_TARGET_EXISTS;
Expand All @@ -372,6 +374,7 @@ protected function setupTarget()
else
{
$unique = wp_unique_filename($path, $this->new_filename);
Log::addTemp('Unique FIleName', $unique);
}
$new_filename = apply_filters( 'emr_unique_filename', $unique, $path, $this->post_id );
$targetFile = trailingslashit($path) . $new_filename;
Expand Down
1 change: 1 addition & 0 deletions classes/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ protected function viewError($errorCode, $errorData = array())
break;
case self::ERROR_TARGET_EXISTS:
$message = __('The target file already exists in this directory. Please try another name / directory', 'enable-media-replace');
$description = __('This error is shown because you try to move the image to another folder, which already has this file', 'enable-media-replace');
break;
case self::ERROR_DESTINATION_FAIL:
$message = __('Something went wrong while writing the file or directory', 'enable-media-replace');
Expand Down
2 changes: 1 addition & 1 deletion classes/ViewController/ReplaceViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function load()

$defaults = array(
'replace_type' => 'replace',
'timestamp_replace' => \EnableMediaReplace\Replacer::TIME_UPDATEMODIFIED,
'timestamp_replace' => ReplaceController::TIME_UPDATEMODIFIED,
'custom_date' => date("Y-m-d H:i:s"),
'new_location' => false,
'new_location_dir' => false,
Expand Down
10 changes: 5 additions & 5 deletions classes/ViewController/UploadViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,22 @@ protected function getPost()
{
$ID = intval($_POST["ID"]); // legacy
$replace_type = isset($_POST["replace_type"]) ? sanitize_text_field($_POST["replace_type"]) : false;
$timestamp_replace = isset($_POST['timestamp_replace']) ? intval($_POST['timestamp_replace']) : Replacer::TIME_UPDATEMODIFIED;
$timestamp_replace = isset($_POST['timestamp_replace']) ? intval($_POST['timestamp_replace']) : ReplaceController::TIME_UPDATEMODIFIED;

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

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

$is_custom_date = false;

switch ($timestamp_replace) {
case \EnableMediaReplace\Replacer::TIME_UPDATEALL:
case \EnableMediaReplace\Replacer::TIME_UPDATEMODIFIED:
case ReplaceController::TIME_UPDATEALL:
case ReplaceController::TIME_UPDATEMODIFIED:
$datetime = current_time('mysql');
break;
case \EnableMediaReplace\Replacer::TIME_CUSTOM:
case ReplaceController::TIME_CUSTOM:
$custom_date = $_POST['custom_date_formatted'];
$custom_hour = str_pad($_POST['custom_hour'], 2, 0, STR_PAD_LEFT);
$custom_minute = str_pad($_POST['custom_minute'], 2, 0, STR_PAD_LEFT);
Expand Down
2 changes: 1 addition & 1 deletion classes/emr-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public function admin_scripts()
wp_register_script('emr_success', plugins_url('js/emr_success.js', EMR_ROOT_FILE), array(), EMR_VERSION, true);

wp_localize_script('emr_success', 'emr_success_options', array(
'timeout' => apply_filters('emr/success/timeout', 10),
'timeout' => apply_filters('emr/success/timeout', 5),
));
}

Expand Down
7 changes: 7 additions & 0 deletions classes/external/wp-offload.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ public function updateOriginalPath($source_url, $target_url, $post_id)
{
$item = $this->getItemById($post_id);

// If no item comes back, probably it's not offloaded
if (false === $item)
{
return;
}


$original_path = $item->original_path(); // Original path (non-scaled-)
$original_source_path = $item->original_source_path();
$path = $item->path();
Expand Down
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.1.1
* Version: 4.1.2
* Author: ShortPixel
* Author URI: https://shortpixel.com
* GitHub Plugin URI: https://github.com/short-pixel-optimizer/enable-media-replace
Expand All @@ -25,7 +25,7 @@
*
*/

define( 'EMR_VERSION', '4.1.1' );
define( 'EMR_VERSION', '4.1.2' );

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
Expand Down
9 changes: 8 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: replace, attachment, media, files, replace image, remove background, repla
Requires at least: 4.9.7
Tested up to: 6.2
Requires PHP: 5.6
Stable tag: 4.1.1
Stable tag: 4.1.2

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 @@ -69,6 +69,13 @@ If you want more control over the format in which the time is shown, you can use

== Changelog ==

= 4.1.2 =

Release date: April 24, 2023
* Tweak: Reduced the wait time before redirecting to the media edit page to half (5s);
* Fix: If an item is not offloaded, no attempt is made to update its data;
* Fix: Removed some double spaces from the plugin strings (thanks to @Presskopp).

= 4.1.1 =

Release date: April 13, 2023
Expand Down
6 changes: 4 additions & 2 deletions views/screen.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
//use \EnableMediaReplace\UIHelper;
use EnableMediaReplace\ShortPixelLogger\ShortPixelLogger as Log;
use EnableMediaReplace\Notices\NoticeController as Notices;
use EnableMediaReplace\Controller\ReplaceController as ReplaceController;


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

<p class='explainer'>
<?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>' );
<?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>' );
?>
</p>

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


if ($settings['timestamp_replace'] == \EnableMediaReplace\Replacer::TIME_CUSTOM)
if ($settings['timestamp_replace'] == ReplaceController::TIME_CUSTOM)
{
$date = new \dateTime($settings['custom_date']);
}
Expand Down
175 changes: 0 additions & 175 deletions views/upload.php

This file was deleted.

0 comments on commit b290930

Please sign in to comment.