Enable Media Replace - Version 2.9.1

Version Description

  • Added Brazilian Portuguese translation, thanks Roger Nobrega!
  • Added filter hook for file name creation, thanks to Jonas Lundman for the code!
  • Added modification date to the edit attachment screen, thanks to Jonas Lundman for the code!
  • Enhanced the deletion method for old file/image thumbnails to never give unnecessary error messages and more accurately delete orphaned thumbs
Download this release

Release Info

Developer MungoBBQ
Plugin Icon 128x128 Enable Media Replace
Version 2.9.1
Comparing to
See all releases

Code changes from version 2.9 to 2.9.1

enable-media-replace-pt_BR.mo ADDED
Binary file
enable-media-replace-pt_BR.po ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: enable-media-replace\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2010-09-13 14:57+0100\n"
6
+ "PO-Revision-Date: \n"
7
+ "Last-Translator: Roger <rogerhnn@hotmail.com>\n"
8
+ "Language-Team: Roger Nobrega <rogerhnn@hotmail.com>\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Poedit-KeywordsList: __;_e\n"
13
+ "X-Poedit-Basepath: .\n"
14
+ "X-Generator: Poedit 1.5.4\n"
15
+ "Language: Português - Brasil\n"
16
+ "X-Poedit-SourceCharset: UTF-8\n"
17
+ "X-Poedit-SearchPath-0: .\n"
18
+
19
+ #: enable-media-replace.php:40 enable-media-replace.php:68
20
+ msgid "Replace media"
21
+ msgstr "Substituir mídia"
22
+
23
+ #: enable-media-replace.php:68
24
+ msgid "Upload a new file"
25
+ msgstr "Enviar novo arquivo"
26
+
27
+ #: enable-media-replace.php:68
28
+ msgid "To replace the current file, click the link and upload a replacement."
29
+ msgstr ""
30
+ "Para subtituir o arquivo atual, clique no link e carregue um substituto"
31
+
32
+ #: popup.php:14 upload.php:21
33
+ msgid "You do not have permission to upload files."
34
+ msgstr "Você não tem permissões para enviar arquivos."
35
+
36
+ #: popup.php:30
37
+ msgid "Replace Media Upload"
38
+ msgstr "Enviar Mídia Substituta"
39
+
40
+ #: popup.php:41
41
+ msgid "NOTE: You are about to replace the media file"
42
+ msgstr "NOTA: Você irá substituir o arquivo de mídia"
43
+
44
+ #: popup.php:41
45
+ msgid "There is no undo. Think about it!"
46
+ msgstr "Não é possível cancelar esta ação."
47
+
48
+ #: popup.php:43
49
+ msgid "Choose a file to upload from your computer"
50
+ msgstr "Escolha um arquivo para enviar do seu computador"
51
+
52
+ #: popup.php:47
53
+ msgid "Select media replacement type:"
54
+ msgstr "Selecione o tipo de substituição"
55
+
56
+ #: popup.php:49
57
+ msgid "Just replace the file"
58
+ msgstr "Apenas substituir arquivo"
59
+
60
+ #: popup.php:50
61
+ msgid "Note: This option requires you to upload a file of the same type ("
62
+ msgstr "Nota: Esta opção requer o carregamento de um arquivo do mesmo tipo ("
63
+
64
+ #: popup.php:50
65
+ msgid ""
66
+ ") as the one you are replacing. The name of the attachment will stay the "
67
+ "same ("
68
+ msgstr ""
69
+ ") do que está sendo substituído. O nome do arquivo permanecerá o mesmo("
70
+
71
+ #: popup.php:50
72
+ msgid ") no matter what the file you upload is called."
73
+ msgstr "), independente do nome do arquivo enviado."
74
+
75
+ #: popup.php:52
76
+ msgid "Replace the file, use new file name and update all links"
77
+ msgstr ""
78
+ "Substituir o arquivo, usar o novo nome de arquivo, e atualizar todos os links"
79
+
80
+ #: popup.php:53
81
+ msgid ""
82
+ "Note: If you check this option, the name and type of the file you are about "
83
+ "to upload will replace the old file. All links pointing to the current file ("
84
+ msgstr ""
85
+ "Nota: Se selecionar esta opção, o nome e tipo do arquivo que você enviar irá "
86
+ "substituir os do arquivo antigo. Todos os links do arquivo atual ("
87
+
88
+ #: popup.php:53
89
+ msgid ") will be updated to point to the new file name."
90
+ msgstr ") serão atualizados para o novo arquivo."
91
+
92
+ #: popup.php:55
93
+ msgid "Upload"
94
+ msgstr "Enviar"
95
+
96
+ #: popup.php:55
97
+ msgid "Cancel"
98
+ msgstr "Cancelar"
enable-media-replace-sv_SE.mo CHANGED
Binary file
enable-media-replace-sv_SE.po CHANGED
@@ -2,32 +2,38 @@ msgid ""
2
  msgstr ""
3
  "Project-Id-Version: enable-media-replace\n"
4
  "Report-Msgid-Bugs-To: \n"
5
- "POT-Creation-Date: 2010-09-13 14:57+0100\n"
6
  "PO-Revision-Date: \n"
7
- "Last-Translator: Måns Jonasson <mans@mansjonasson.se>\n"
8
  "Language-Team: \n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=UTF-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
12
  "X-Poedit-KeywordsList: __;_e\n"
13
  "X-Poedit-Basepath: .\n"
 
14
  "X-Poedit-SearchPath-0: .\n"
15
 
16
- #: enable-media-replace.php:40
17
- #: enable-media-replace.php:68
18
  msgid "Replace media"
19
  msgstr "Ersätt media"
20
 
21
- #: enable-media-replace.php:68
22
  msgid "Upload a new file"
23
  msgstr "Ladda upp en ny fil"
24
 
25
- #: enable-media-replace.php:68
26
  msgid "To replace the current file, click the link and upload a replacement."
27
- msgstr "För att ersätta den nuvarande filen, klicka på länken och ladda upp en ny fil."
 
 
 
 
 
 
28
 
29
- #: popup.php:14
30
- #: upload.php:21
31
  msgid "You do not have permission to upload files."
32
  msgstr "Du har inte tillåtelse att ladda upp filer."
33
 
@@ -35,58 +41,70 @@ msgstr "Du har inte tillåtelse att ladda upp filer."
35
  msgid "Replace Media Upload"
36
  msgstr "Ladda upp ny fil"
37
 
38
- #: popup.php:41
39
  msgid "NOTE: You are about to replace the media file"
40
  msgstr "OBS: Du är på väg att ersätta filen"
41
 
42
- #: popup.php:41
43
  msgid "There is no undo. Think about it!"
44
  msgstr "Det finns inget sätt att ångra. Tänk efter först!"
45
 
46
- #: popup.php:43
47
  msgid "Choose a file to upload from your computer"
48
  msgstr "Välj en fil att ladda upp från din dator"
49
 
50
- #: popup.php:47
51
  msgid "Select media replacement type:"
52
  msgstr "Välj ersättningsform:"
53
 
54
- #: popup.php:49
55
  msgid "Just replace the file"
56
  msgstr "Ersätt bara filen"
57
 
58
- #: popup.php:50
59
  msgid "Note: This option requires you to upload a file of the same type ("
60
  msgstr "Detta val kräver att du laddar upp en fil av exakt samma typ ("
61
 
62
- #: popup.php:50
63
- msgid ") as the one you are replacing. The name of the attachment will stay the same ("
 
 
64
  msgstr ") som den du ersätter. Namnet på filen kommer att behållas ("
65
 
66
- #: popup.php:50
67
  msgid ") no matter what the file you upload is called."
68
  msgstr ") oavsett vad filen du laddar upp heter på din dator."
69
 
70
- #: popup.php:52
71
  msgid "Replace the file, use new file name and update all links"
72
  msgstr "Ersätt filen, använd det nya filnamnet och uppdatera alla länkar"
73
 
74
- #: popup.php:53
75
- msgid "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 ("
76
- msgstr "Om du klickar i den här rutan kommer den även namnet och typen den nya filen du laddar upp helt att ersätta den gamla. Alla länkar som pekar på den gamla filen ("
 
 
 
 
 
77
 
78
- #: popup.php:53
79
  msgid ") will be updated to point to the new file name."
80
  msgstr ") kommer att uppdateras så att de pekar på det nya filnamnet."
81
 
82
- #: popup.php:55
83
  msgid "Upload"
84
  msgstr "Ladda upp"
85
 
86
- #: popup.php:55
87
  msgid "Cancel"
88
  msgstr "Avbryt"
89
 
 
 
 
 
 
90
  #~ msgid "Enable Media Replace"
91
  #~ msgstr "Ladda upp ny fil"
92
 
2
  msgstr ""
3
  "Project-Id-Version: enable-media-replace\n"
4
  "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2013-06-03 14:32+0100\n"
6
  "PO-Revision-Date: \n"
7
+ "Last-Translator: Måns Jonasson <mans@thejonassons.com>\n"
8
  "Language-Team: \n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=UTF-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
12
  "X-Poedit-KeywordsList: __;_e\n"
13
  "X-Poedit-Basepath: .\n"
14
+ "X-Generator: Poedit 1.5.5\n"
15
  "X-Poedit-SearchPath-0: .\n"
16
 
17
+ #: enable-media-replace.php:40 enable-media-replace.php:79
18
+ #: enable-media-replace.php:120
19
  msgid "Replace media"
20
  msgstr "Ersätt media"
21
 
22
+ #: enable-media-replace.php:79
23
  msgid "Upload a new file"
24
  msgstr "Ladda upp en ny fil"
25
 
26
+ #: enable-media-replace.php:79
27
  msgid "To replace the current file, click the link and upload a replacement."
28
+ msgstr ""
29
+ "För att ersätta den nuvarande filen, klicka på länken och ladda upp en ny "
30
+ "fil."
31
+
32
+ #: enable-media-replace.php:168
33
+ msgid "Revised"
34
+ msgstr "Uppdaterad"
35
 
36
+ #: popup.php:14 upload.php:3
 
37
  msgid "You do not have permission to upload files."
38
  msgstr "Du har inte tillåtelse att ladda upp filer."
39
 
41
  msgid "Replace Media Upload"
42
  msgstr "Ladda upp ny fil"
43
 
44
+ #: popup.php:46
45
  msgid "NOTE: You are about to replace the media file"
46
  msgstr "OBS: Du är på väg att ersätta filen"
47
 
48
+ #: popup.php:46
49
  msgid "There is no undo. Think about it!"
50
  msgstr "Det finns inget sätt att ångra. Tänk efter först!"
51
 
52
+ #: popup.php:48
53
  msgid "Choose a file to upload from your computer"
54
  msgstr "Välj en fil att ladda upp från din dator"
55
 
56
+ #: popup.php:52
57
  msgid "Select media replacement type:"
58
  msgstr "Välj ersättningsform:"
59
 
60
+ #: popup.php:54
61
  msgid "Just replace the file"
62
  msgstr "Ersätt bara filen"
63
 
64
+ #: popup.php:55
65
  msgid "Note: This option requires you to upload a file of the same type ("
66
  msgstr "Detta val kräver att du laddar upp en fil av exakt samma typ ("
67
 
68
+ #: popup.php:55
69
+ msgid ""
70
+ ") as the one you are replacing. The name of the attachment will stay the "
71
+ "same ("
72
  msgstr ") som den du ersätter. Namnet på filen kommer att behållas ("
73
 
74
+ #: popup.php:55
75
  msgid ") no matter what the file you upload is called."
76
  msgstr ") oavsett vad filen du laddar upp heter på din dator."
77
 
78
+ #: popup.php:57
79
  msgid "Replace the file, use new file name and update all links"
80
  msgstr "Ersätt filen, använd det nya filnamnet och uppdatera alla länkar"
81
 
82
+ #: popup.php:58
83
+ msgid ""
84
+ "Note: If you check this option, the name and type of the file you are about "
85
+ "to upload will replace the old file. All links pointing to the current file ("
86
+ msgstr ""
87
+ "Om du klickar i den här rutan kommer den även namnet och typen på den nya "
88
+ "filen du laddar upp helt att ersätta den gamla. Alla länkar som pekar på den "
89
+ "gamla filen ("
90
 
91
+ #: popup.php:58
92
  msgid ") will be updated to point to the new file name."
93
  msgstr ") kommer att uppdateras så att de pekar på det nya filnamnet."
94
 
95
+ #: popup.php:60
96
  msgid "Upload"
97
  msgstr "Ladda upp"
98
 
99
+ #: popup.php:60
100
  msgid "Cancel"
101
  msgstr "Avbryt"
102
 
103
+ #: upload.php:33
104
+ msgid "File type does not meet security guidelines. Try another."
105
+ msgstr ""
106
+ "Den här filen är inte tillåten enligt WordPress säkerhetsinställningar. "
107
+
108
  #~ msgid "Enable Media Replace"
109
  #~ msgstr "Ladda upp ny fil"
110
 
enable-media-replace.mo CHANGED
Binary file
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
 
@@ -157,5 +157,19 @@ function emr_get_modified_date($atts) {
157
 
158
  }
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
 
161
  ?>
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.1
7
  Author: Måns Jonasson
8
  Author URI: http://www.mansjonasson.se
9
 
157
 
158
  }
159
 
160
+ // Add Last replaced by EMR plugin in the media edit screen metabox - Thanks Jonas Lundman (http://wordpress.org/support/topic/add-filter-hook-suggestion-to)
161
+ function ua_admin_date_replaced_media_on_edit_media_screen() {
162
+ if( !function_exists( 'enable_media_replace' ) ) return;
163
+ global $post;
164
+ $id = $post->ID;
165
+ $shortcode = "[file_modified id=$id]";
166
+ ?>
167
+ <div class="misc-pub-section curtime">
168
+ <span id="timestamp"><?php _e( 'Revised', 'enable-media-replace' ); ?>: <b><?php echo do_shortcode($shortcode); ?></b></span>
169
+ </div>
170
+ <?php
171
+ }
172
+ add_action( 'attachment_submitbox_misc_actions', 'ua_admin_date_replaced_media_on_edit_media_screen', 91 );
173
+
174
 
175
  ?>
enable-media-replace.po CHANGED
@@ -2,32 +2,36 @@ msgid ""
2
  msgstr ""
3
  "Project-Id-Version: enable-media-replace\n"
4
  "Report-Msgid-Bugs-To: \n"
5
- "POT-Creation-Date: 2010-09-13 14:57+0100\n"
6
  "PO-Revision-Date: \n"
7
- "Last-Translator: Måns Jonasson <mans@mansjonasson.se>\n"
8
  "Language-Team: \n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=UTF-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
12
  "X-Poedit-KeywordsList: __;_e\n"
13
  "X-Poedit-Basepath: .\n"
 
14
  "X-Poedit-SearchPath-0: .\n"
15
 
16
- #: enable-media-replace.php:40
17
- #: enable-media-replace.php:68
18
  msgid "Replace media"
19
  msgstr ""
20
 
21
- #: enable-media-replace.php:68
22
  msgid "Upload a new file"
23
  msgstr ""
24
 
25
- #: enable-media-replace.php:68
26
  msgid "To replace the current file, click the link and upload a replacement."
27
  msgstr ""
28
 
29
- #: popup.php:14
30
- #: upload.php:21
 
 
 
31
  msgid "You do not have permission to upload files."
32
  msgstr ""
33
 
@@ -35,55 +39,62 @@ msgstr ""
35
  msgid "Replace Media Upload"
36
  msgstr ""
37
 
38
- #: popup.php:41
39
  msgid "NOTE: You are about to replace the media file"
40
  msgstr ""
41
 
42
- #: popup.php:41
43
  msgid "There is no undo. Think about it!"
44
  msgstr ""
45
 
46
- #: popup.php:43
47
  msgid "Choose a file to upload from your computer"
48
  msgstr ""
49
 
50
- #: popup.php:47
51
  msgid "Select media replacement type:"
52
  msgstr ""
53
 
54
- #: popup.php:49
55
  msgid "Just replace the file"
56
  msgstr ""
57
 
58
- #: popup.php:50
59
  msgid "Note: This option requires you to upload a file of the same type ("
60
  msgstr ""
61
 
62
- #: popup.php:50
63
- msgid ") as the one you are replacing. The name of the attachment will stay the same ("
 
 
64
  msgstr ""
65
 
66
- #: popup.php:50
67
  msgid ") no matter what the file you upload is called."
68
  msgstr ""
69
 
70
- #: popup.php:52
71
  msgid "Replace the file, use new file name and update all links"
72
  msgstr ""
73
 
74
- #: popup.php:53
75
- msgid "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 ("
 
 
76
  msgstr ""
77
 
78
- #: popup.php:53
79
  msgid ") will be updated to point to the new file name."
80
  msgstr ""
81
 
82
- #: popup.php:55
83
  msgid "Upload"
84
  msgstr ""
85
 
86
- #: popup.php:55
87
  msgid "Cancel"
88
  msgstr ""
89
 
 
 
 
2
  msgstr ""
3
  "Project-Id-Version: enable-media-replace\n"
4
  "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2013-06-03 14:32+0100\n"
6
  "PO-Revision-Date: \n"
7
+ "Last-Translator: Måns Jonasson <mans@thejonassons.com>\n"
8
  "Language-Team: \n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=UTF-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
12
  "X-Poedit-KeywordsList: __;_e\n"
13
  "X-Poedit-Basepath: .\n"
14
+ "X-Generator: Poedit 1.5.5\n"
15
  "X-Poedit-SearchPath-0: .\n"
16
 
17
+ #: enable-media-replace.php:40 enable-media-replace.php:79
18
+ #: enable-media-replace.php:120
19
  msgid "Replace media"
20
  msgstr ""
21
 
22
+ #: enable-media-replace.php:79
23
  msgid "Upload a new file"
24
  msgstr ""
25
 
26
+ #: enable-media-replace.php:79
27
  msgid "To replace the current file, click the link and upload a replacement."
28
  msgstr ""
29
 
30
+ #: enable-media-replace.php:168
31
+ msgid "Revised"
32
+ msgstr ""
33
+
34
+ #: popup.php:14 upload.php:3
35
  msgid "You do not have permission to upload files."
36
  msgstr ""
37
 
39
  msgid "Replace Media Upload"
40
  msgstr ""
41
 
42
+ #: popup.php:46
43
  msgid "NOTE: You are about to replace the media file"
44
  msgstr ""
45
 
46
+ #: popup.php:46
47
  msgid "There is no undo. Think about it!"
48
  msgstr ""
49
 
50
+ #: popup.php:48
51
  msgid "Choose a file to upload from your computer"
52
  msgstr ""
53
 
54
+ #: popup.php:52
55
  msgid "Select media replacement type:"
56
  msgstr ""
57
 
58
+ #: popup.php:54
59
  msgid "Just replace the file"
60
  msgstr ""
61
 
62
+ #: popup.php:55
63
  msgid "Note: This option requires you to upload a file of the same type ("
64
  msgstr ""
65
 
66
+ #: popup.php:55
67
+ msgid ""
68
+ ") as the one you are replacing. The name of the attachment will stay the "
69
+ "same ("
70
  msgstr ""
71
 
72
+ #: popup.php:55
73
  msgid ") no matter what the file you upload is called."
74
  msgstr ""
75
 
76
+ #: popup.php:57
77
  msgid "Replace the file, use new file name and update all links"
78
  msgstr ""
79
 
80
+ #: popup.php:58
81
+ msgid ""
82
+ "Note: If you check this option, the name and type of the file you are about "
83
+ "to upload will replace the old file. All links pointing to the current file ("
84
  msgstr ""
85
 
86
+ #: popup.php:58
87
  msgid ") will be updated to point to the new file name."
88
  msgstr ""
89
 
90
+ #: popup.php:60
91
  msgid "Upload"
92
  msgstr ""
93
 
94
+ #: popup.php:60
95
  msgid "Cancel"
96
  msgstr ""
97
 
98
+ #: upload.php:33
99
+ msgid "File type does not meet security guidelines. Try another."
100
+ msgstr ""
readme.txt CHANGED
@@ -31,12 +31,18 @@ This plugin is very powerful and a must-have for any larger sites built with Wor
31
  There is a shortcode available which picks up the file modification date and displays it in a post or a page. The code is:
32
  `[file_modified id=XX format=XXXX]` where the "id" is required and the "format" is optional and defaults to your current WordPress settings for date and time format.
33
 
34
- So `[file_modified id=870]` would display the last time the file with ID 870 was updated on your site. To get the ID for a file, check the URL when editing a file in the media library (see screenshot #3)
35
 
36
  If you want more control over the format used to display the time, you can use the format option, so `[file_modified id=870 format=Y-m-d]` would display the file modification date but not the time. The format string uses [standard PHP date() formatting tags](http://php.net/manual/en/function.date.php).
37
 
38
  == Changelog ==
39
 
 
 
 
 
 
 
40
  = 2.9 =
41
  * Added Portuguese translation, thanks Bruno Miguel Bras Silva!
42
  * New edit link from media library
@@ -119,7 +125,7 @@ If you want more control over the format used to display the time, you can use t
119
 
120
  Quick and easy installation:
121
 
122
- 1. Upload the folder `enable-media-replace` to the `/wp-content/plugins/` directory
123
  1. Activate the plugin through the 'Plugins' menu in WordPress
124
  1. Done!
125
 
@@ -133,11 +139,20 @@ This plugin makes it easy to update/replace files that have been uploaded to the
133
 
134
  A new option will be available in the Edit Media view, called "Replace Media". This is where you can upload a new file to replace the old one.
135
 
 
 
 
 
 
 
 
 
136
  == Screenshots ==
137
 
138
- 1. The new link in the WordPress Edit Media view.
139
- 2. The upload window.
140
- 3. Get the file ID in the edit file URL
 
141
 
142
  == Wishlist / Coming attractons ==
143
 
31
  There is a shortcode available which picks up the file modification date and displays it in a post or a page. The code is:
32
  `[file_modified id=XX format=XXXX]` where the "id" is required and the "format" is optional and defaults to your current WordPress settings for date and time format.
33
 
34
+ So `[file_modified id=870]` would display the last time the file with ID 870 was updated on your site. To get the ID for a file, check the URL when editing a file in the media library (see screenshot #4)
35
 
36
  If you want more control over the format used to display the time, you can use the format option, so `[file_modified id=870 format=Y-m-d]` would display the file modification date but not the time. The format string uses [standard PHP date() formatting tags](http://php.net/manual/en/function.date.php).
37
 
38
  == Changelog ==
39
 
40
+ = 2.9.1 =
41
+ * Added Brazilian Portuguese translation, thanks Roger Nobrega!
42
+ * Added filter hook for file name creation, thanks to Jonas Lundman for the code!
43
+ * Added modification date to the edit attachment screen, thanks to Jonas Lundman for the code!
44
+ * Enhanced the deletion method for old file/image thumbnails to never give unnecessary error messages and more accurately delete orphaned thumbs
45
+
46
  = 2.9 =
47
  * Added Portuguese translation, thanks Bruno Miguel Bras Silva!
48
  * New edit link from media library
125
 
126
  Quick and easy installation:
127
 
128
+ 1. Upload the folder `enable-media-replace` to your plugin directory
129
  1. Activate the plugin through the 'Plugins' menu in WordPress
130
  1. Done!
131
 
139
 
140
  A new option will be available in the Edit Media view, called "Replace Media". This is where you can upload a new file to replace the old one.
141
 
142
+ = I replaced a file, but it didn't change! =
143
+
144
+ There are two main reasons this would happen.
145
+
146
+ First, make sure you are not viewing a cached version of the file, especially if you replaced an image. Press "Refresh" in your browser to make sure.
147
+
148
+ Second, if the file really looks unchanged, make sure WordPress has write permissions to the files in your uploads folder. If you have ever moved your WP installation (maybe when you moved it to a new server), the permissions on your uploaded files are commonly reset so that WordPress no longer has permissions to change the files. If you don't know how to do this, contact your web server operator.
149
+
150
  == Screenshots ==
151
 
152
+ 1. The new link in the media library.
153
+ 2. The replace media-button as seen in the "Edit media" view.
154
+ 3. The upload options.
155
+ 4. Get the file ID in the edit file URL
156
 
157
  == Wishlist / Coming attractons ==
158
 
screenshot-1.png CHANGED
Binary file
screenshot-2.png CHANGED
Binary file
screenshot-3.png CHANGED
Binary file
screenshot-4.png ADDED
Binary file
upload.php CHANGED
@@ -7,6 +7,55 @@ global $wpdb;
7
  $table_name = $wpdb->prefix . "posts";
8
  $postmeta_table_name = $wpdb->prefix . "postmeta";
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  // Get old guid and filetype from DB
11
  $sql = "SELECT guid, post_mime_type FROM $table_name WHERE ID = '" . (int) $_POST["ID"] . "'";
12
  list($current_filename, $current_filetype) = mysql_fetch_array(mysql_query($sql));
@@ -20,7 +69,6 @@ $current_path = substr($current_file, 0, (strrpos($current_file, "/")));
20
  $current_file = str_replace("//", "/", $current_file);
21
  $current_filename = basename($current_file);
22
 
23
-
24
  $replace_type = $_POST["replace_type"];
25
  // We have two types: replace / replace_and_search
26
 
@@ -42,33 +90,7 @@ if (is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
42
  // Drop-in replace and we don't even care if you uploaded something that is the wrong file-type.
43
  // That's your own fault, because we warned you!
44
 
45
- // Delete old file
46
- unlink($current_file);
47
-
48
- // Delete old resized versions if this was an image
49
- $suffix = substr($current_file, (strlen($current_file)-4));
50
- $prefix = substr($current_file, 0, (strlen($current_file)-4));
51
- $imgAr = array(".png", ".gif", ".jpg");
52
- if (in_array($suffix, $imgAr)) {
53
- // It's a png/gif/jpg based on file name
54
- // Get thumbnail filenames from metadata
55
- $metadata = wp_get_attachment_metadata($_POST["ID"]);
56
- if (is_array($metadata)) { // Added fix for error messages when there is no metadata (but WHY would there not be? I don't know…)
57
- foreach($metadata["sizes"] AS $thissize) {
58
- // Get all filenames and do an unlink() on each one;
59
- $thisfile = $thissize["file"];
60
- if (strlen($thisfile)) {
61
- $thisfile = $current_path . "/" . $thissize["file"];
62
- if (file_exists($thisfile)) {
63
- unlink($thisfile);
64
- }
65
- }
66
- }
67
- }
68
- // Old (brutal) method, left here for now
69
- //$mask = $prefix . "-*x*" . $suffix;
70
- //array_map( "unlink", glob( $mask ) );
71
- }
72
 
73
  // Move new file to old location/name
74
  move_uploaded_file($_FILES["userfile"]["tmp_name"], $current_file);
@@ -84,30 +106,7 @@ if (is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
84
  else {
85
  // Replace file, replace file name, update meta data, replace links pointing to old file name
86
 
87
- // Delete old file
88
- unlink($current_file);
89
-
90
- // Delete old resized versions if this was an image
91
- $suffix = substr($current_file, (strlen($current_file)-4));
92
- $prefix = substr($current_file, 0, (strlen($current_file)-4));
93
- $imgAr = array(".png", ".gif", ".jpg");
94
- if (in_array($suffix, $imgAr)) {
95
- // Get thumbnail filenames from metadata
96
- $metadata = wp_get_attachment_metadata($_POST["ID"]);
97
- foreach($metadata["sizes"] AS $thissize) {
98
- // Get all filenames and do an unlink() on each one;
99
- $thisfile = $thissize["file"];
100
- if (strlen($thisfile)) {
101
- $thisfile = $current_path . "/" . $thissize["file"];
102
- if (file_exists($thisfile)) {
103
- unlink($thisfile);
104
- }
105
- }
106
- }
107
- // Old (brutal) method, left here for now
108
- //$mask = $prefix . "-*x*" . $suffix;
109
- //array_map( "unlink", glob( $mask ) );
110
- }
111
 
112
  // Massage new filename to adhere to WordPress standards
113
  $new_filename= wp_unique_filename( $current_path, $new_filename );
@@ -120,6 +119,7 @@ if (is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
120
  chmod($new_file, 0644);
121
 
122
  $new_filetitle = preg_replace('/\.[^.]+$/', '', basename($new_file));
 
123
  $new_guid = str_replace($current_filename, $new_filename, $current_guid);
124
 
125
  // Update database file name
7
  $table_name = $wpdb->prefix . "posts";
8
  $postmeta_table_name = $wpdb->prefix . "postmeta";
9
 
10
+ function emr_delete_current_files($current_file) {
11
+ // Delete old file
12
+
13
+ // Find path of current file
14
+ $current_path = substr($current_file, 0, (strrpos($current_file, "/")));
15
+
16
+ // Check if old file exists first
17
+ if (file_exists($current_file)) {
18
+ // Now check for correct file permissions for old file
19
+ clearstatcache();
20
+ if (is_writable($current_file)) {
21
+ // Everything OK; delete the file
22
+ unlink($current_file);
23
+ }
24
+ else {
25
+ // File exists, but has wrong permissions. Let the user know.
26
+ printf(__('The file %1$s can not be deleted by the web server, most likely because the permissions on the file are wrong.', "enable-media-replace"), $current_file);
27
+ exit;
28
+ }
29
+ }
30
+
31
+ // Delete old resized versions if this was an image
32
+ $suffix = substr($current_file, (strlen($current_file)-4));
33
+ $prefix = substr($current_file, 0, (strlen($current_file)-4));
34
+ $imgAr = array(".png", ".gif", ".jpg");
35
+ if (in_array($suffix, $imgAr)) {
36
+ // It's a png/gif/jpg based on file name
37
+ // Get thumbnail filenames from metadata
38
+ $metadata = wp_get_attachment_metadata($_POST["ID"]);
39
+ if (is_array($metadata)) { // Added fix for error messages when there is no metadata (but WHY would there not be? I don't know…)
40
+ foreach($metadata["sizes"] AS $thissize) {
41
+ // Get all filenames and do an unlink() on each one;
42
+ $thisfile = $thissize["file"];
43
+ if (strlen($thisfile)) {
44
+ $thisfile = $current_path . "/" . $thissize["file"];
45
+ if (file_exists($thisfile)) {
46
+ unlink($thisfile);
47
+ }
48
+ }
49
+ }
50
+ }
51
+ // Old (brutal) method, left here for now
52
+ //$mask = $prefix . "-*x*" . $suffix;
53
+ //array_map( "unlink", glob( $mask ) );
54
+ }
55
+
56
+ }
57
+
58
+
59
  // Get old guid and filetype from DB
60
  $sql = "SELECT guid, post_mime_type FROM $table_name WHERE ID = '" . (int) $_POST["ID"] . "'";
61
  list($current_filename, $current_filetype) = mysql_fetch_array(mysql_query($sql));
69
  $current_file = str_replace("//", "/", $current_file);
70
  $current_filename = basename($current_file);
71
 
 
72
  $replace_type = $_POST["replace_type"];
73
  // We have two types: replace / replace_and_search
74
 
90
  // Drop-in replace and we don't even care if you uploaded something that is the wrong file-type.
91
  // That's your own fault, because we warned you!
92
 
93
+ emr_delete_current_files($current_file);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
95
  // Move new file to old location/name
96
  move_uploaded_file($_FILES["userfile"]["tmp_name"], $current_file);
106
  else {
107
  // Replace file, replace file name, update meta data, replace links pointing to old file name
108
 
109
+ emr_delete_current_files($current_file);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
 
111
  // Massage new filename to adhere to WordPress standards
112
  $new_filename= wp_unique_filename( $current_path, $new_filename );
119
  chmod($new_file, 0644);
120
 
121
  $new_filetitle = preg_replace('/\.[^.]+$/', '', basename($new_file));
122
+ $new_filetitle = apply_filters( 'enable_media_replace_title', $new_filetitle ); // Thanks Jonas Lundman (http://wordpress.org/support/topic/add-filter-hook-suggestion-to)
123
  $new_guid = str_replace($current_filename, $new_filename, $current_guid);
124
 
125
  // Update database file name