Version Description
- Bug fix for the short code displaying the modification date of a file
- Updated all database queries in preparation for WP 3.9
Download this release
Release Info
Developer | MungoBBQ |
Plugin | Enable Media Replace |
Version | 2.9.5 |
Comparing to | |
See all releases |
Code changes from version 2.9.4 to 2.9.5
- enable-media-replace.php +3 -3
- popup.php +1 -1
- readme.txt +4 -0
- upload.php +9 -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: 2.9.
|
7 |
Author: Måns Jonasson
|
8 |
Author URI: http://www.mansjonasson.se
|
9 |
|
@@ -144,8 +144,8 @@ function emr_get_modified_date($atts) {
|
|
144 |
$filetime = filemtime($current_file);
|
145 |
|
146 |
// do date conversion
|
147 |
-
$content = date($format,
|
148 |
-
|
149 |
return $content;
|
150 |
|
151 |
}
|
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: 2.9.5
|
7 |
Author: Måns Jonasson
|
8 |
Author URI: http://www.mansjonasson.se
|
9 |
|
144 |
$filetime = filemtime($current_file);
|
145 |
|
146 |
// do date conversion
|
147 |
+
$content = date($format, $filetime);
|
148 |
+
|
149 |
return $content;
|
150 |
|
151 |
}
|
popup.php
CHANGED
@@ -19,7 +19,7 @@ $table_name = $wpdb->prefix . "posts";
|
|
19 |
|
20 |
$sql = "SELECT guid, post_mime_type FROM $table_name WHERE ID = " . (int) $_GET["attachment_id"];
|
21 |
|
22 |
-
list($current_filename, $current_filetype) =
|
23 |
|
24 |
$current_filename = substr($current_filename, (strrpos($current_filename, "/") + 1));
|
25 |
|
19 |
|
20 |
$sql = "SELECT guid, post_mime_type FROM $table_name WHERE ID = " . (int) $_GET["attachment_id"];
|
21 |
|
22 |
+
list($current_filename, $current_filetype) = $wpdb->get_row($sql, ARRAY_N);
|
23 |
|
24 |
$current_filename = substr($current_filename, (strrpos($current_filename, "/") + 1));
|
25 |
|
readme.txt
CHANGED
@@ -37,6 +37,10 @@ If you want more control over the format used to display the time, you can use t
|
|
37 |
|
38 |
== Changelog ==
|
39 |
|
|
|
|
|
|
|
|
|
40 |
= 2.9.4 =
|
41 |
* Bug fix for timezone changes in WordPress
|
42 |
* Minor UI change to inform the user about what actually happens when replacing an image and using a new file name
|
37 |
|
38 |
== Changelog ==
|
39 |
|
40 |
+
= 2.9.5 =
|
41 |
+
* Bug fix for the short code displaying the modification date of a file
|
42 |
+
* Updated all database queries in preparation for WP 3.9
|
43 |
+
|
44 |
= 2.9.4 =
|
45 |
* Bug fix for timezone changes in WordPress
|
46 |
* Minor UI change to inform the user about what actually happens when replacing an image and using a new file name
|
upload.php
CHANGED
@@ -61,7 +61,7 @@ function emr_delete_current_files($current_file) {
|
|
61 |
|
62 |
// Get old guid and filetype from DB
|
63 |
$sql = "SELECT guid, post_mime_type FROM $table_name WHERE ID = '" . (int) $_POST["ID"] . "'";
|
64 |
-
list($current_filename, $current_filetype) =
|
65 |
|
66 |
// Massage a bunch of vars
|
67 |
$current_guid = $current_filename;
|
@@ -128,32 +128,34 @@ if (is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
|
|
128 |
$new_guid = str_replace($current_filename, $new_filename, $current_guid);
|
129 |
|
130 |
// Update database file name
|
131 |
-
|
132 |
|
133 |
// Update the postmeta file name
|
134 |
|
135 |
// Get old postmeta _wp_attached_file
|
136 |
$sql = "SELECT meta_value FROM $postmeta_table_name WHERE meta_key = '_wp_attached_file' AND post_id = '" . (int) $_POST["ID"] . "'";
|
137 |
-
$old_meta_name =
|
|
|
138 |
|
139 |
// Make new postmeta _wp_attached_file
|
140 |
$new_meta_name = str_replace($current_filename, $new_filename, $old_meta_name);
|
141 |
-
|
142 |
|
143 |
// Make thumb and/or update metadata
|
144 |
wp_update_attachment_metadata( (int) $_POST["ID"], wp_generate_attachment_metadata( (int) $_POST["ID"], $new_file) );
|
145 |
|
146 |
// Search-and-replace filename in post database
|
147 |
$sql = "SELECT ID, post_content FROM $table_name WHERE post_content LIKE '%$current_guid%'";
|
148 |
-
$rs = mysql_query($sql);
|
149 |
|
150 |
-
|
|
|
|
|
151 |
|
152 |
// replace old guid with new guid
|
153 |
$post_content = $rows["post_content"];
|
154 |
$post_content = addslashes(str_replace($current_guid, $new_guid, $post_content));
|
155 |
|
156 |
-
|
157 |
}
|
158 |
|
159 |
// Trigger possible updates on CDN and other plugins
|
61 |
|
62 |
// Get old guid and filetype from DB
|
63 |
$sql = "SELECT guid, post_mime_type FROM $table_name WHERE ID = '" . (int) $_POST["ID"] . "'";
|
64 |
+
list($current_filename, $current_filetype) = $wpdb->get_row($sql, ARRAY_N);
|
65 |
|
66 |
// Massage a bunch of vars
|
67 |
$current_guid = $current_filename;
|
128 |
$new_guid = str_replace($current_filename, $new_filename, $current_guid);
|
129 |
|
130 |
// Update database file name
|
131 |
+
$wpdb->query("UPDATE $table_name SET post_title = '$new_filetitle', post_name = '$new_filetitle', guid = '$new_guid', post_mime_type = '$new_filetype' WHERE ID = '" . (int) $_POST["ID"] . "'");
|
132 |
|
133 |
// Update the postmeta file name
|
134 |
|
135 |
// Get old postmeta _wp_attached_file
|
136 |
$sql = "SELECT meta_value FROM $postmeta_table_name WHERE meta_key = '_wp_attached_file' AND post_id = '" . (int) $_POST["ID"] . "'";
|
137 |
+
$old_meta_name = $wpdb->get_row($sql, ARRAY_A);
|
138 |
+
$old_meta_name = $old_meta_name["meta_value"];
|
139 |
|
140 |
// Make new postmeta _wp_attached_file
|
141 |
$new_meta_name = str_replace($current_filename, $new_filename, $old_meta_name);
|
142 |
+
$wpdb->query("UPDATE $postmeta_table_name SET meta_value = '$new_meta_name' WHERE meta_key = '_wp_attached_file' AND post_id = '" . (int) $_POST["ID"] . "'");
|
143 |
|
144 |
// Make thumb and/or update metadata
|
145 |
wp_update_attachment_metadata( (int) $_POST["ID"], wp_generate_attachment_metadata( (int) $_POST["ID"], $new_file) );
|
146 |
|
147 |
// Search-and-replace filename in post database
|
148 |
$sql = "SELECT ID, post_content FROM $table_name WHERE post_content LIKE '%$current_guid%'";
|
|
|
149 |
|
150 |
+
$rs = $wpdb->get_results($sql, ARRAY_A);
|
151 |
+
|
152 |
+
foreach($rs AS $rows) {
|
153 |
|
154 |
// replace old guid with new guid
|
155 |
$post_content = $rows["post_content"];
|
156 |
$post_content = addslashes(str_replace($current_guid, $new_guid, $post_content));
|
157 |
|
158 |
+
$wpdb->query("UPDATE $table_name SET post_content = '$post_content' WHERE ID = {$rows["ID"]}");
|
159 |
}
|
160 |
|
161 |
// Trigger possible updates on CDN and other plugins
|