WordPress.org

Ready to get started?Download WordPress

Forums

Enable Media Replace
[resolved] Not compatible with WordPress 3.5's new media manager (28 posts)

  1. Matt van Andel
    Member
    Posted 1 year ago #

    This plugin has been in my default toolkit for a while... the ability to simply replace a file in the media manager with a new one was incredibly useful for quickly and easily updating documents or promo images.

    Unfortunately, WordPress 3.5's amazing new media manager is simply not compatible with this plugin. The real bummer is that the new media manager STILL doesn't have the ability to simply replace a file, meaning that a serious update to Enable Media Replace is now badly needed to restore this "basic" functionality.

    http://wordpress.org/extend/plugins/enable-media-replace/

  2. duncmorley
    Member
    Posted 1 year ago #

    Agreed. Hopefully an update will be pushed soon enough as I use this loads.

  3. Elizabeth Powell
    Member
    Posted 1 year ago #

    In case it's useful for others (or the original developer!) I've managed to fix this on mine with a couple of code changes. (This is my first time posting code here so I hope it works...)

    In enable-media-replace.php, make the following replacements:

    Line 55:
    function enable_media_replace( $form_fields, $post ) {
    The attachment_fields_to_edit hook also passes through a $post variable containing the current post.

    Line 57:

    $current_screen = get_current_screen();
    if ( $current_screen->base == 'post' && $current_screen->post_type == 'attachment' ) {

    This checks that we're on the attachment edit screen.

    Line 59:
    $url = admin_url( "upload.php?page=enable-media-replace/enable-media-replace.php&action=media_replace&attachment_id=" . $post->ID);
    Changes the way the method fetches the current attachment id.

    I made a pastebin of the entire method here: http://pastebin.com/HJVXz0qa

    It's not pretty but it'll do until there's an official update!

  4. gabeshaughnessy
    Member
    Posted 1 year ago #

    Thanks for the fix Elizabeth!
    I can verify that your solution worked for us as well.
    Hopefully Mans will see this and update the plugin. Personally I include this plugin in all my WordPress sites, and I would love to see this feature in core.

  5. Gillian
    Member
    Posted 1 year ago #

    Thanks, Elizabeth :-)

  6. Matt van Andel
    Member
    Posted 1 year ago #

    Thanks, Elizabeth! Your patch works flawlessly.

  7. webaware
    Member
    Posted 1 year ago #

    @Elizabeth Powell: many thanks!

  8. kjparish
    Member
    Posted 1 year ago #

    @Elizabeth Powell, worked for me too. Thanks!

  9. rikau
    Member
    Posted 1 year ago #

    Mahalo Elizabeth.
    Works like a charm!

  10. lucasgaudette
    Member
    Posted 1 year ago #

    Code works! Amazing, thanks!
    And thanks to the developer for making this plug-in in the first place, I've found nothing else like it and have used religiously for quite some time... cheers!

    Lucas

  11. thatwastaxing
    Member
    Posted 1 year ago #

    Thanks!

  12. nebulatechnologies
    Member
    Posted 1 year ago #

    Elizabeth,

    Thank you kindly for sharing your work. Hacking someone else's code is never easy. You've saved a lot of us a lot of work (Including maybe the developer - HINT HINT)

    I noticed two things I would like to mention:

    When I was replacing the code for line 57 in Dreamweaver, the new code took two lines, which made line 59 become line 60. Just FYI for anyone who doesn't figure that out.

    2nd: When I tested the fix (and this was my first use of the plug-in) the gallery view did not change the "thumbnail" or "preview" from the old image to the new image, but the changes were live on the site. When I left the media tab (I went to posts, but it doesn't matter) and returned to the media tab, the "preview" had refreshed.

    I can see that being a little confusing for my clients. I wonder if this plug-in always functioned that way.....

    Thank you again!

    Jason

  13. gabeshaughnessy
    Member
    Posted 1 year ago #

    Jason, your browser cached the image and because the uploaded file had the same file name, you did not see the new file right away. Don't forget to empty your browser cache to see the changes.

  14. nebulatechnologies
    Member
    Posted 1 year ago #

    Gabe,

    Thank you. That makes sense. However, I don't think the average user wants to empty their cache every time they change out a picture, especially when changing 10 or so. The process is a hassle even for professionals.

    I am personally opposed to clearing my cache regularly, because I typically have over 30 tabs open in two to three browsers, and I often use my page history to go back to some tabs when I have closed them.

    I noticed a page refresh did not update the picture, but leaving the page and returning did change the picture. I assume this is because the page dynamically pulled new content from the DB.

    I'm sure there is a way to automate having WP re-"get" the image thumbnails when the page transitions from the "edit image" page to the media main page, but it probably would involve editing the WP core files.

    Again, to me this is a minor issue. This is a really great plug-in now that it is working with WP 3.5.

  15. Matt van Andel
    Member
    Posted 1 year ago #

    Jason,

    You don't seem to understand how caching works.

    Here's the gist version:
    When you visit a webpage, your browser caches everything locally. As you browse around the site, it uses it's locally cached copies to speed up web page load times. There's no need to re-download everything constantly, which not only hurts the visitor, but places extra load on the server.

    Now if you have an image with filename myimage.jpg and then you replace that with something else, chances are your web browser will keep serving up the one it's cached until you FORCE it to reload it... either by clearing the cache, or doing a force-refresh if your browser supports it.

    Developers have some small control over caching by telling the browser how long it should hold on to downloaded files (via headers, etags, etc)... but at the end of the day, a website can't FORCE a browser to do anything. You can only make recommendations... and some browsers are much more militant about holding onto their cache for the sake of speed (even ignoring "distant past" expires headers).

    This has nothing to do with the media manager, this plugin, or anything concerning WordPress... it's a browser issue. If you replace a file that is already cached, you will need to force refresh the page you're working on. Eventually it would simply happen on it's own as the cached file "ages".

    As far as Enable Media Replace is concerned, there's only one way I know of that you might be able to force a file to update on revision with any amount of consistency... you must change the LINK to the affected media to include a randomized querystring parameter.

    For instance: myimage.jpg?1355666742

    And then, every time you update that file, you need to update that querystring value (the above example uses a unix timestamp which would theoretically change on each file replace).

    While it is technically possible to do something like this automatically with a plugin, it's a sloppy solution to something that isn't really a problem.

  16. bunster101
    Member
    Posted 1 year ago #

    Thank you, Elizabeth! Works like a charm! I love this plugin and grateful for your posting a fix.

  17. Måns Jonasson
    Member
    Plugin Author

    Posted 1 year ago #

    Thank you, Elisabeth!

    I got a couple of emails that EMR was no longer working with 3.5 and I just implemented your changes to the plugin and it works great. I'll submit a new version to WordPress.org momentarily.

  18. Joolee
    Member
    Posted 1 year ago #

    I had to change line 57 (65 now actually) to:
    ` if ( !is_null($current_screen) && $current_screen->base == 'post' && $current_screen->post_type == 'attachment' ) { $on_media_edit_screen = true; }

    I got errors on response to the "query-attachments" ajax call when editing a gallery.

  19. ironprogrammer
    Member
    Posted 1 year ago #

    I've also added a ! is_null( $current_screen ) condition on line 65, since get_current_screen() returns null in the Add Media and Set Featured Image dialogs.

    One thing I'm not clear on is whether you should be able to replace media from within a post or page, or if the functionality should be restricted to the Edit Media page. Either way, this workaround does the trick for my purposes.

    Thanks to Måns and everyone else for your help in improving this plugin!

  20. Jason Lemahieu (MadtownLems)
    Member
    Posted 1 year ago #

    The issue that persists in version 2.8.1:

    With EMR active, if I try to add Media to a post, the Media Library tab (that's supposed to show existing images in my media library to use) always comes up blank.

    Disabling EMR lets me see my entire Media Library there, as expected.

    The fix that Joolee suggests 2 posts above seems to correct my issue.

  21. Måns Jonasson
    Member
    Plugin Author

    Posted 1 year ago #

    This is very strange, I am not seeing this at all. I went ahead and implemented Joolee's change anyway and submitted 2.8.2 so please update and try it out and let me know!

  22. consultor
    Member
    Posted 1 year ago #

    Hi
    great plugin
    2.8.2 just installed with WP 3.5.1, and the problem persist.
    Any fix?

    getting this error message:

    Invalid argument supplied for foreach() in /home/myuser/public_html/myfolder/wp-content/plugins/enable-media-replace/upload.php on line 55
    
    Cannot modify header information - headers already sent by (output started at /home/myuser/public_html/myfolder/wp-content/plugins/enable-media-replace/upload.php:55) in /home/frente/public_html/semanario/wp-includes/pluggable.php on line 876
    
    Versión 3.5.1
  23. Måns Jonasson
    Member
    Plugin Author

    Posted 1 year ago #

    Arnold, the only way I can see that you would get that error message is when WP fails to get metadata for the requested file. This would mean that there is no metadata stored in the database for that file.

    I could make it fail more gracefully (and I might) but that wouldn't really help you since my plugin needs the thumbnail sizes stored in that metadata to replace the resized images.

    Question 1: When you receive that error, is the original file still replaced?

    Question 2: Is it an image you are trying to replace?

  24. bikeamtn
    Member
    Posted 1 year ago #

    Installed the Plugin
    Requires: 2.8 or higher
    Compatible up to: 3.5.1
    Last Updated: 2013-1-18

    IN: WP 3.5.1
    Using WOO-Theme Bueno 1.7.4 / Framework 5.4.1

    Replaced one pic as a test (jpg for jpg of simul. size).
    Went ok but all I got now is a place-holder with no image...

    WordPress Programmers; "We Real Need This Option"

  25. Måns Jonasson
    Member
    Plugin Author

    Posted 1 year ago #

    bikeamtn: What happened in your file system - was the file replaced? Is it completely missing?

  26. bikeamtn
    Member
    Posted 1 year ago #

    Hi Måns; The details are: looking at the page as a public view, if I do a right-click 'Show Image' it will then load. Refreash the page and again just place-holder is shown. From the admin side of things, the image replace looks like it worked although in the library the thumbnail is the old image but if I select 'Edit' will show the new one in the edit screen. I tried flipping the image just so I could SAVE it hoping it would then show correctly but nope and still just shows place-holder.
    I've now deactivated plugin and replaced the manual way (delete image in library, upload new with same name and assigned to the page or post and used the original URL-Link for the new image). That worked. That way it goes right in the same place without a page layout change. Its the long way around but thats what it is. Don't know about others but my issue may be with using WooTheme.

  27. Måns Jonasson
    Member
    Plugin Author

    Posted 1 year ago #

    That sounds more like there is a problem with the local cache in your browser preventing you from seeing the new thumbnail after replacing the image.

  28. bikeamtn
    Member
    Posted 1 year ago #

    No; kept clearing cache, refreashing and checked using IE and Chrome. Also doesn't explain why WP-admin Library was having a problem.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic