Enable Media Replace - Version 3.2.8

Version Description

  • fix for failures in link updating when replacing file because of addslashes - use prepared query instead
  • replace basename with wp_basename because basename doesn't work well with UTF8
Download this release

Release Info

Developer ShortPixel
Plugin Icon 128x128 Enable Media Replace
Version 3.2.8
Comparing to
See all releases

Code changes from version 3.2.7 to 3.2.8

Files changed (4) hide show
  1. enable-media-replace.php +1 -1
  2. popup.php +2 -2
  3. readme.txt +5 -1
  4. upload.php +5 -7
enable-media-replace.php CHANGED
@@ -3,7 +3,7 @@
3
Plugin Name: Enable Media Replace
4
Plugin URI: http://www.mansjonasson.se/enable-media-replace
5
Description: Enable replacing media files by uploading a new file in the "Edit Media" section of the WordPress Media Library.
6
- Version: 3.2.7
7
Author: ShortPixel
8
Author URI: https://shortpixel.com
9
3
Plugin Name: Enable Media Replace
4
Plugin URI: http://www.mansjonasson.se/enable-media-replace
5
Description: Enable replacing media files by uploading a new file in the "Edit Media" section of the WordPress Media Library.
6
+ Version: 3.2.8
7
Author: ShortPixel
8
Author URI: https://shortpixel.com
9
popup.php CHANGED
@@ -107,8 +107,8 @@ $current_filename = substr($current_filename, (strrpos($current_filename, "/") +
107
<?php endif; ?>
108
<?php if ( apply_filters( 'emr_enable_replace_and_search', true ) ) : ?>
109
<label for="replace_type_2"><input <?php echo $s3pluginExist ? 'CHECKED' : '' ?> id="replace_type_2" type="radio" name="replace_type" value="replace_and_search"> <?php echo __("Replace the file, use new file name and update all links", "enable-media-replace"); ?></label>
110
- <p class="howto"><?php printf( __("Note: If you check this option, the name and type of the file you are about to upload will replace the old file. All links pointing to the current file (%s) will be updated to point to the new file name.", "enable-media-replace"), $current_filename ); ?></p>
111
- <p class="howto"><?php echo __("Please note that if you upload a new image, only embeds/links of the original size image will be replaced in your posts.", "enable-media-replace"); ?></p>
112
<?php endif; ?>
113
<?php else : ?>
114
<?php if ( ! $s3pluginExist) : ?>
107
<?php endif; ?>
108
<?php if ( apply_filters( 'emr_enable_replace_and_search', true ) ) : ?>
109
<label for="replace_type_2"><input <?php echo $s3pluginExist ? 'CHECKED' : '' ?> id="replace_type_2" type="radio" name="replace_type" value="replace_and_search"> <?php echo __("Replace the file, use new file name and update all links", "enable-media-replace"); ?></label>
110
+ <p class="howto"><?php printf( esc_html__("Note: If you check this option, the name and type of the file you are about to upload will replace the old file. All links pointing to the current file (%s) will be updated to point to the new file name.", "enable-media-replace"), $current_filename ); ?></p>
111
+ <p class="howto"><?php echo esc_html__("Please note that if you upload a new image, only embeds/links of the original size image will be replaced in your posts.", "enable-media-replace"); ?></p>
112
<?php endif; ?>
113
<?php else : ?>
114
<?php if ( ! $s3pluginExist) : ?>
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: ShortPixel
3
Donate link: https://www.paypal.me/resizeImage
4
Tags: replace, attachment, media, files, replace image, replace jpg, change media, replace media, image, file
5
Requires at least: 4.0
6
- Tested up to: 4.9
7
Requires PHP: 5.4
8
Stable tag: trunk
9
@@ -47,6 +47,10 @@ If you want more control over the format used to display the time, you can use t
47
48
== Changelog ==
49
50
= 3.2.7 =
51
* Add minimum required php version to run the plugin.
52
* Security: Prevent direct access to php files.
3
Donate link: https://www.paypal.me/resizeImage
4
Tags: replace, attachment, media, files, replace image, replace jpg, change media, replace media, image, file
5
Requires at least: 4.0
6
+ Tested up to: 5.0
7
Requires PHP: 5.4
8
Stable tag: trunk
9
47
48
== Changelog ==
49
50
+ = 3.2.8 =
51
+ * fix for failures in link updating when replacing file because of addslashes - use prepared query instead
52
+ * replace basename with wp_basename because basename doesn't work well with UTF8
53
+
54
= 3.2.7 =
55
* Add minimum required php version to run the plugin.
56
* Security: Prevent direct access to php files.
upload.php CHANGED
@@ -205,18 +205,16 @@ function emr_normalize_file_urls( $old, $new ) {
205
// Get old guid and filetype from DB
206
$sql = "SELECT post_mime_type FROM $table_name WHERE ID = '" . (int) $_POST["ID"] . "'";
207
list($current_filetype) = $wpdb->get_row($sql, ARRAY_N);
208
- $current_filename = wp_get_attachment_url($_POST['ID']);
209
210
// Massage a bunch of vars
211
- $current_guid = $current_filename;
212
- $current_filename = substr($current_filename, (strrpos($current_filename, "/") + 1));
213
214
$ID = (int) $_POST["ID"];
215
216
$current_file = get_attached_file($ID, apply_filters( 'emr_unfiltered_get_attached_file', true ));
217
$current_path = substr($current_file, 0, (strrpos($current_file, "/")));
218
$current_file = preg_replace("|(?<!:)/{2,}|", "/", $current_file);
219
- $current_filename = basename($current_file);
220
$current_metadata = wp_get_attachment_metadata( $_POST["ID"] );
221
222
$replace_type = $_POST["replace_type"];
@@ -360,11 +358,11 @@ if (is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
360
361
// replace old URLs with new URLs.
362
$post_content = $rows["post_content"];
363
- $post_content = addslashes( str_replace( $search_urls, $replace_urls, $post_content ) );
364
365
$sql = $wpdb->prepare(
366
- "UPDATE $table_name SET post_content = '$post_content' WHERE ID = %d;",
367
- $rows["ID"]
368
);
369
370
$wpdb->query( $sql );
205
// Get old guid and filetype from DB
206
$sql = "SELECT post_mime_type FROM $table_name WHERE ID = '" . (int) $_POST["ID"] . "'";
207
list($current_filetype) = $wpdb->get_row($sql, ARRAY_N);
208
209
// Massage a bunch of vars
210
+ $current_guid =wp_get_attachment_url($_POST['ID']);
211
212
$ID = (int) $_POST["ID"];
213
214
$current_file = get_attached_file($ID, apply_filters( 'emr_unfiltered_get_attached_file', true ));
215
$current_path = substr($current_file, 0, (strrpos($current_file, "/")));
216
$current_file = preg_replace("|(?<!:)/{2,}|", "/", $current_file);
217
+ $current_filename = wp_basename($current_file);
218
$current_metadata = wp_get_attachment_metadata( $_POST["ID"] );
219
220
$replace_type = $_POST["replace_type"];
358
359
// replace old URLs with new URLs.
360
$post_content = $rows["post_content"];
361
+ $post_content = str_replace( $search_urls, $replace_urls, $post_content );
362
363
$sql = $wpdb->prepare(
364
+ "UPDATE $table_name SET post_content = %s WHERE ID = %d;",
365
+ array($post_content, $rows["ID"])
366
);
367
368
$wpdb->query( $sql );