Enable Media Replace - Version 2.1

Version Description

  • New shortcode - display file modification date on your site (see description for more info)
  • A couple of bug fixes for final release of 3.0 - Thanks to Jim Isaacs for pointing them out!
Download this release

Release Info

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

Code changes from version 2.0.1 to 2.1

Files changed (3) hide show
  1. enable-media-replace.php +35 -4
  2. readme.txt +21 -1
  3. screenshot-3.png +0 -0
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.0.1
7
  Author: Måns Jonasson
8
  Author URI: http://www.mansjonasson.se
9
 
@@ -21,15 +21,17 @@ add_action( 'init', 'enable_media_replace_init' );
21
  add_action('admin_menu', 'emr_menu');
22
  add_filter('attachment_fields_to_edit', 'enable_media_replace', 10, 2);
23
 
 
 
24
 
25
  function emr_menu() {
26
- add_submenu_page('upload.php', __("Enable Media Replace", "enable-media-replace"), __("Replace media", "enable-media-replace"), 4, __FILE__, 'emr_options');
27
  }
28
 
29
 
30
  // Initialize this plugin. Called by 'init' hook.
31
  function enable_media_replace_init() {
32
- load_plugin_textdomain( 'enable-media-replace', '/wp-content/plugins/enable-media-replace' );
33
  }
34
 
35
  function enable_media_replace( $form_fields, $post ) {
@@ -45,7 +47,7 @@ function enable_media_replace( $form_fields, $post ) {
45
  }
46
 
47
  function emr_options() {
48
- if ($_GET["attachment_id"] > 0) {
49
  include("popup.php");
50
  }
51
 
@@ -64,4 +66,33 @@ function emr_options() {
64
  }
65
  }
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  ?>
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.1
7
  Author: Måns Jonasson
8
  Author URI: http://www.mansjonasson.se
9
 
21
  add_action('admin_menu', 'emr_menu');
22
  add_filter('attachment_fields_to_edit', 'enable_media_replace', 10, 2);
23
 
24
+ add_shortcode('file_modified', 'emr_get_modified_date');
25
+
26
 
27
  function emr_menu() {
28
+ add_submenu_page('upload.php', __("Enable Media Replace", "enable-media-replace"), __("Replace media", "enable-media-replace"), 'upload_files', __FILE__, 'emr_options');
29
  }
30
 
31
 
32
  // Initialize this plugin. Called by 'init' hook.
33
  function enable_media_replace_init() {
34
+ load_plugin_textdomain( 'enable-media-replace', false, dirname( plugin_basename( __FILE__ ) ) );
35
  }
36
 
37
  function enable_media_replace( $form_fields, $post ) {
47
  }
48
 
49
  function emr_options() {
50
+ if ( array_key_exists("attachment_id", $_GET) && $_GET["attachment_id"] > 0) {
51
  include("popup.php");
52
  }
53
 
66
  }
67
  }
68
 
69
+ function emr_get_modified_date($atts) {
70
+ extract(shortcode_atts(array(
71
+ 'id' => '',
72
+ 'format' => get_option('date_format') . " " . get_option('time_format'),
73
+ ), $atts));
74
+
75
+ if ($id == '') return false;
76
+
77
+ // Get path to file
78
+ $current_file = get_attached_file($id, true);
79
+
80
+ // Get file modification time
81
+ $filetime = filemtime($current_file);
82
+
83
+ // Do timezone magic to get around UTC
84
+ $timezone = date_default_timezone_get();
85
+ date_default_timezone_set(get_option('timezone_string'));
86
+
87
+ // do date conversion
88
+ $content = date($format, $filetime);
89
+
90
+ // Set timezone back to default
91
+ date_default_timezone_set($timezone);
92
+
93
+ return $content;
94
+
95
+ }
96
+
97
+
98
  ?>
readme.txt CHANGED
@@ -9,19 +9,38 @@ Enables replacing attachment files by simply uploading a new file in the media l
9
 
10
  == Description ==
11
 
 
 
 
 
12
  Don't you find it tedious and complicated to have to first delete a file and then upload one with the exact same name every time you want to update an image or any uploaded file inside the WordPress media library?
13
 
14
  Well, no longer!
15
 
16
  Now you'll be able to replace any uploaded file from the media "edit" view, where it should be. Media replacement can be done in one of two ways:
17
 
 
 
18
  1. Just replace the file. This option requires you to upload a file of the same type as the one you are replacing. The name of the attachment will stay the same no matter what the file you upload is called.
19
  1. Replace the file, use new file name and update all links. 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 will be updated to point to the new file name.
20
 
21
  This plugin is very powerful and a must-have for any larger sites built with WordPress.
22
 
 
 
 
 
 
 
 
 
 
23
  == Changelog ==
24
 
 
 
 
 
25
  = 2.0.1 =
26
  * Added support for SSL admin
27
 
@@ -63,12 +82,13 @@ This plugin makes it easy to update/replace files that have been uploaded to the
63
 
64
  = How does it work? =
65
 
66
- A new option will be available in the Edit Media view, called "Replace Media". Clicking it opens up a window where you can upload a new file to replace the old one.
67
 
68
  == Screenshots ==
69
 
70
  1. The new link in the WordPress Edit Media view.
71
  2. The upload window.
 
72
 
73
  == Wishlist / Coming attractons ==
74
 
9
 
10
  == Description ==
11
 
12
+ This plugin allows you to replace a file in your media library by uploading a new file in its place. No more deleting, renaming and re-uploading files!
13
+
14
+ #### A real timesaver
15
+
16
  Don't you find it tedious and complicated to have to first delete a file and then upload one with the exact same name every time you want to update an image or any uploaded file inside the WordPress media library?
17
 
18
  Well, no longer!
19
 
20
  Now you'll be able to replace any uploaded file from the media "edit" view, where it should be. Media replacement can be done in one of two ways:
21
 
22
+ #### It's simple to replace a file
23
+
24
  1. Just replace the file. This option requires you to upload a file of the same type as the one you are replacing. The name of the attachment will stay the same no matter what the file you upload is called.
25
  1. Replace the file, use new file name and update all links. 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 will be updated to point to the new file name.
26
 
27
  This plugin is very powerful and a must-have for any larger sites built with WordPress.
28
 
29
+ #### Display file modification time
30
+
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.1 =
41
+ * New shortcode - display file modification date on your site (see description for more info)
42
+ * A couple of bug fixes for final release of 3.0 - Thanks to Jim Isaacs for pointing them out!
43
+
44
  = 2.0.1 =
45
  * Added support for SSL admin
46
 
82
 
83
  = How does it work? =
84
 
85
+ 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.
86
 
87
  == Screenshots ==
88
 
89
  1. The new link in the WordPress Edit Media view.
90
  2. The upload window.
91
+ 3. Get the file ID in the edit file URL
92
 
93
  == Wishlist / Coming attractons ==
94
 
screenshot-3.png ADDED
Binary file