Enable Media Replace - Version 3.0.3

Version Description

  • Scrapped old method of detecting media screen, button to replace media will now show up in more places, yay!
  • Made sure the call to get_attached_file() no longer skips filters, in response to several users wishes.
  • Suppressed error messages on chmod()
  • Added Japanese translation (Thank you, chacomv!)
Download this release

Release Info

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

Code changes from version 3.0.2 to 3.0.3

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.0.2
7
  Author: Måns Jonasson
8
  Author URI: http://www.mansjonasson.se
9
 
@@ -55,29 +55,16 @@ function enable_media_replace_init() {
55
  */
56
  function enable_media_replace( $form_fields, $post ) {
57
 
58
- // Check if we are on media upload screen for insertion of replace link
59
- $on_media_edit_screen = false;
60
- $current_wp_version = get_bloginfo('version');
61
- if ($current_wp_version < 3.5) {
62
- if (isset($_GET["attachment_id"]) && $_GET["attachment_id"]) { $on_media_edit_screen = true; }
63
- }
64
- else {
65
- $current_screen = get_current_screen();
66
- if ( !is_null($current_screen) && $current_screen->base == 'post' && $current_screen->post_type == 'attachment' ) { $on_media_edit_screen = true; }
67
- }
68
-
69
- if ($on_media_edit_screen == true) {
70
-
71
- $url = admin_url( "upload.php?page=enable-media-replace/enable-media-replace.php&action=media_replace&attachment_id=" . $post->ID);
72
- $action = "media_replace";
73
- $editurl = wp_nonce_url( $url, $action );
74
 
75
- if (FORCE_SSL_ADMIN) {
76
- $editurl = str_replace("http:", "https:", $editurl);
77
- }
78
- $link = "href=\"$editurl\"";
79
- $form_fields["enable-media-replace"] = array("label" => __("Replace media", "enable-media-replace"), "input" => "html", "html" => "<p><a class='button-secondary'$link>" . __("Upload a new file", "enable-media-replace") . "</a></p>", "helps" => __("To replace the current file, click the link and upload a replacement.", "enable-media-replace"));
80
  }
 
 
 
81
  return $form_fields;
82
  }
83
 
@@ -138,7 +125,7 @@ function emr_get_modified_date($atts) {
138
  if ($id == '') return false;
139
 
140
  // Get path to file
141
- $current_file = get_attached_file($id, true);
142
 
143
  // Get file modification time
144
  $filetime = filemtime($current_file);
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.0.3
7
  Author: Måns Jonasson
8
  Author URI: http://www.mansjonasson.se
9
 
55
  */
56
  function enable_media_replace( $form_fields, $post ) {
57
 
58
+ $url = admin_url( "upload.php?page=enable-media-replace/enable-media-replace.php&action=media_replace&attachment_id=" . $post->ID);
59
+ $action = "media_replace";
60
+ $editurl = wp_nonce_url( $url, $action );
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
+ if (FORCE_SSL_ADMIN) {
63
+ $editurl = str_replace("http:", "https:", $editurl);
 
 
 
64
  }
65
+ $link = "href=\"$editurl\"";
66
+ $form_fields["enable-media-replace"] = array("label" => __("Replace media", "enable-media-replace"), "input" => "html", "html" => "<p><a class='button-secondary'$link>" . __("Upload a new file", "enable-media-replace") . "</a></p>", "helps" => __("To replace the current file, click the link and upload a replacement.", "enable-media-replace"));
67
+
68
  return $form_fields;
69
  }
70
 
125
  if ($id == '') return false;
126
 
127
  // Get path to file
128
+ $current_file = get_attached_file($id);
129
 
130
  // Get file modification time
131
  $filetime = filemtime($current_file);
languages/enable-media-replace-ja.mo ADDED
Binary file
languages/enable-media-replace-ja.po ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: enable-media-replace\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2015-01-19 09:00+0900\n"
6
+ "PO-Revision-Date: \n"
7
+ "Last-Translator: chacomv\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.7\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
+
31
+ #: enable-media-replace.php:168
32
+ msgid "Revised"
33
+ msgstr "変更されました"
34
+
35
+ #: popup.php:14 upload.php:3
36
+ msgid "You do not have permission to upload files."
37
+ msgstr "ファイルをアップロードする権限がありません。"
38
+
39
+ #: popup.php:30
40
+ msgid "Replace Media Upload"
41
+ msgstr "新しいメディアファイルをアップロード"
42
+
43
+ #: popup.php:46
44
+ msgid "NOTE: You are about to replace the media file"
45
+ msgstr "※ このメディアを置き換えようとしています。"
46
+
47
+ #: popup.php:46
48
+ msgid "There is no undo. Think about it!"
49
+ msgstr "元に戻せませんのでご注意ください。"
50
+
51
+ #: popup.php:48
52
+ msgid "Choose a file to upload from your computer"
53
+ msgstr "コンピューターからアップロードするファイルを選択"
54
+
55
+ #: popup.php:52
56
+ msgid "Select media replacement type:"
57
+ msgstr "メディアを置換する方式を選択:"
58
+
59
+ #: popup.php:54
60
+ msgid "Just replace the file"
61
+ msgstr "ファイルの置換のみ"
62
+
63
+ #: popup.php:55
64
+ msgid "Note: This option requires you to upload a file of the same type ("
65
+ msgstr ""
66
+ "※ このオプションは、元のファイルと同じファイル形式でアップロードする必要があ"
67
+ "ります。("
68
+
69
+ #: popup.php:55
70
+ msgid ""
71
+ ") as the one you are replacing. The name of the attachment will stay the "
72
+ "same ("
73
+ msgstr ") ファイル名は同じになります。("
74
+
75
+ #: popup.php:55
76
+ msgid ") no matter what the file you upload is called."
77
+ msgstr ")"
78
+
79
+ #: popup.php:57
80
+ msgid "Replace the file, use new file name and update all links"
81
+ msgstr "ファイルを置換して新しいファイル名で全てのリンクを更新する"
82
+
83
+ #: popup.php:58
84
+ msgid ""
85
+ "Note: If you check this option, the name and type of the file you are about "
86
+ "to upload will replace the old file. All links pointing to the current file ("
87
+ msgstr ""
88
+ "※ このオプションをチェックすると、アップロードしたファイルの名称と形式に置換"
89
+ "されます。現在のファイル名("
90
+
91
+ #: popup.php:58
92
+ msgid ") will be updated to point to the new file name."
93
+ msgstr ")へのリンクが全て新しいファイル名に更新されます。"
94
+
95
+ #: popup.php:60
96
+ msgid "Upload"
97
+ msgstr "アップロード"
98
+
99
+ #: popup.php:60
100
+ msgid "Cancel"
101
+ msgstr "キャンセル"
102
+
103
+ #: upload.php:33
104
+ msgid "File type does not meet security guidelines. Try another."
105
+ msgstr ""
106
+ "ファイル形式がセキュリティ的に許可されません。他の形式をお試しください。"
107
+
108
+ #: popup.php:63
109
+ msgid ""
110
+ "Please note that if you upload a new image, only embeds/links of the "
111
+ "original size image will be replaced in your posts."
112
+ msgstr ""
113
+ "新しいファイルをアップロードすると、元のサイズの画像へのリンクや埋め込みのみ"
114
+ "が置換されますのでご注意ください。"
languages/enable-media-replace-pt_PT.mo ADDED
Binary file
readme.txt CHANGED
@@ -1,7 +1,7 @@
1
  === Enable Media Replace ===
2
  Contributors: mungobbq
3
  Tags: admin, attachment, media, files
4
- Requires at least: 3.0
5
  Tested up to: 4.1
6
  Stable tag: trunk
7
 
@@ -37,6 +37,12 @@ If you want more control over the format used to display the time, you can use t
37
 
38
  == Changelog ==
39
 
 
 
 
 
 
 
40
  = 3.0.2 =
41
  * Cleaned up language files
42
  * Added Portuguese translation (Thanks pedro-mendonca!)
1
  === Enable Media Replace ===
2
  Contributors: mungobbq
3
  Tags: admin, attachment, media, files
4
+ Requires at least: 3.5
5
  Tested up to: 4.1
6
  Stable tag: trunk
7
 
37
 
38
  == Changelog ==
39
 
40
+ = 3.0.3 =
41
+ * Scrapped old method of detecting media screen, button to replace media will now show up in more places, yay!
42
+ * Made sure the call to get_attached_file() no longer skips filters, in response to several users wishes.
43
+ * Suppressed error messages on chmod()
44
+ * Added Japanese translation (Thank you, chacomv!)
45
+
46
  = 3.0.2 =
47
  * Cleaned up language files
48
  * Added Portuguese translation (Thanks pedro-mendonca!)
upload.php CHANGED
@@ -102,7 +102,7 @@ if (is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
102
  move_uploaded_file($_FILES["userfile"]["tmp_name"], $current_file);
103
 
104
  // Chmod new file to original file permissions
105
- chmod($current_file, $original_file_perms);
106
 
107
  // Make thumb and/or update metadata
108
  wp_update_attachment_metadata( (int) $_POST["ID"], wp_generate_attachment_metadata( (int) $_POST["ID"], $current_file ) );
@@ -122,7 +122,7 @@ if (is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
122
  move_uploaded_file($_FILES["userfile"]["tmp_name"], $new_file);
123
 
124
  // Chmod new file to original file permissions
125
- chmod($current_file, $original_file_perms);
126
 
127
  $new_filetitle = preg_replace('/\.[^.]+$/', '', basename($new_file));
128
  $new_filetitle = apply_filters( 'enable_media_replace_title', $new_filetitle ); // Thanks Jonas Lundman (http://wordpress.org/support/topic/add-filter-hook-suggestion-to)
102
  move_uploaded_file($_FILES["userfile"]["tmp_name"], $current_file);
103
 
104
  // Chmod new file to original file permissions
105
+ @chmod($current_file, $original_file_perms);
106
 
107
  // Make thumb and/or update metadata
108
  wp_update_attachment_metadata( (int) $_POST["ID"], wp_generate_attachment_metadata( (int) $_POST["ID"], $current_file ) );
122
  move_uploaded_file($_FILES["userfile"]["tmp_name"], $new_file);
123
 
124
  // Chmod new file to original file permissions
125
+ @chmod($current_file, $original_file_perms);
126
 
127
  $new_filetitle = preg_replace('/\.[^.]+$/', '', basename($new_file));
128
  $new_filetitle = apply_filters( 'enable_media_replace_title', $new_filetitle ); // Thanks Jonas Lundman (http://wordpress.org/support/topic/add-filter-hook-suggestion-to)