GithubHelp home page GithubHelp logo

mansj / enable-media-replace Goto Github PK

View Code? Open in Web Editor NEW
28.0 7.0 27.0 528 KB

***DEVELOPMENT DISCONTINUED*** Enable Media Replace, a WordPress plugin to make it possible to replace uploaded media files in a simple way.

License: GNU General Public License v2.0

PHP 100.00%

enable-media-replace's Introduction

Enable Media Replace

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!

A real timesaver

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?

Well, no longer!

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:

It's simple to replace a file

  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.
  2. 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.

This plugin is very powerful and a must-have for any larger sites built with WordPress.

Display file modification time

There is a shortcode available which picks up the file modification date and displays it in a post or a page. The code is: [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.

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)

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.


See Enable Media Replace at WordPress.org for more information.

enable-media-replace's People

Contributors

aaemnnosttv avatar fiwad avatar grantnorwood avatar ianmjones avatar jeremyfelt avatar mansj avatar pacotole avatar pedro-mendonca avatar polevaultweb avatar ramiy avatar speerface avatar twoelevenjay avatar ururk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

enable-media-replace's Issues

Wordpress JSON API support

This is a great plugin, but I am trying to work out if I can use it with the Wordpress JSON API.

I want to be able to replace an image in the media library remotely (from a mobile app) using the JSON API. I can post, list and delete images with the API fine but can't work out how to replace an image.

I am a bit of a newbie with regards to PHP and Wordpress (I am a mobile dev). Maybe there is another way to do this, although tapping into your plugin looks like the best bet.

Programmatic usage

I want to replace the image file of an existing attachment (that also contains other meta data (ACF fields)). Does this plugin offer a simple function that the plugin could use to do this programmatically (as code)? Can this plugin be even used as kind of plugin library?

Bug in upload.php>emr_delete_current_files

Looks like a bug in line 16 of upload.php:
function emr_delete_current_files( $current_file, $metadta = null ) {

In the function body you refer to $metadata, whereas input param is $metadta.

Revised time in the Edit Media window does not reflect timezone

This is an excellent plug-in. It does exactly what we need. I just noticed that the "Revised" time/date in the Edit Media window is showing (for example) "Revised: January 6, 2017 9:13 pm" on a file that I uploaded at 3:13 pm in the "Chicago" timezone. This might be confusing to some of our less tech-savvy end-users.

Is this something that I can manually override? I'm fairly new to WordPress, PHP and Github.

Thanks!

is_writable check isn't right

Hello and thank you for Enable Media Replace,

I have an hopefully easy to fix issue. In upload.php, is_writable($current_file) should be is_writable(dirname($current_file)). unlink requires write access on the directory and doesn't even look at the file permissions.

A few sites have complicated permissions where the web-server doesn't have write access to the attachment files, but can remove them and add new attachments.

Thanks!

Plugin does not work with stream wrappers for media held off the filesystem.

We us an Amazon S3 storage plugin that stores all the media in an S3 bucket. This means that the files are referred to as s3://bucket/folder/file. Line 206 of upload.php is doing a replace on double forward slashes to convert to a single one, which breaks the protocol handler detection and causes the plugin to fail. Commenting out that line makes the plugin work correctly for files of the format protocol://foo/bar.

I'm happy to put a PR up, but wanted to know the best way to address this. It isn't obvious to me what case that replace is covering, but it is clearly there for a reason. Would it be okay to only run that replace where the // isn't preceded by a :? Or is there some better logic?

Many thanks.

chmod() warning

I received a warning when I tried to 'Replace the file, use new file name and update all links'. Here is the exact warning message:

Warning: chmod(): No such file or directory in /xx/xx/public_html/wp-content/plugins/enable-media-replace/upload.php on line 125

Which results to another warning 'headers already sent' and unable to continue the process.

Do you know how to fix this?
I tried to chmod the parent directory but still no luck. For the meantime I added a temporary fix by adding '@' before 'chmod' just to disable the warning message.

Please let me know if you have the fix. Thanks.

plugin does not replace image thumbnails

This is a really great plugin, but there is one little thing I am missing.

If you replace an image with a new filename, the plugin just search&replaces the original filename, but not the thumbnail images in the post content.

Setting to allow change of WP role level that can use plugin

Enhancement request -
Can you create a setting that would allow an administrator to set the role level that is allowed to use the plugin (ie. replace media).

I have novice WP contributors in several areas, but would like to enable our office manager to post updates to PDF based newsletters and calendars without giving away the keys to the kingdom.

D

Incorrect use of GUIDs during search and replacement

Thanks for the must-use plugin. I've had an instance where the post content wasn't updated for a specific post that contained a link to the old media file that was replaced. Looking at the code, I believe it's due to the search criteria $current_guid. Because the GUID represents the URL at a point in time, it's not always the current URL. Further, the current URL could be a relative URL, which would be missed.

It would seem the proper solution would be to look for either full URL matches to the old media file's current URL, AND relative URLs to the old media's URL. The GUID attribute should not be used.

See https://codex.wordpress.org/Changing_The_Site_URL#Important_GUID_Note for more information.

                // Search-and-replace filename in post database
                $sql = $wpdb->prepare(
                        "SELECT ID, post_content FROM $table_name WHERE post_content LIKE %s;",
                        '%' . $current_guid . '%'
                );

                $rs = $wpdb->get_results($sql, ARRAY_A);

                foreach($rs AS $rows) {

                        // replace old guid with new guid
                        $post_content = $rows["post_content"];
                        $post_content = addslashes(str_replace($current_guid, $new_guid, $post_content));

                        $sql = $wpdb->prepare(
                                "UPDATE $table_name SET post_content = '$post_content' WHERE ID = %d;",
                                $rows["ID"]
                        );

                        $wpdb->query($sql);
                }

Language files in root folder

Hi,

In github this is ok but in wordpress plugin repository you have language files in the plugin root folder and in language folder (duplicate).
I'm using my language file (pt_PT) that I've just pulled here and it works fine, so I believe the correct place is the language folder.
#8

Please check on this.
Thanks

Issues with umlauts in filenames

I am having issues with umlauts in file names.
Whenever I am uploading such a file directly in the Media Library (not even using Replace Image yet) I receive the following error:

Warning: filemtime(): stat failed for domain/html/wp-content/uploads/A?O?U?-a?o?u?-a?a?a?-ø-a?-æ-A?O?U?-ß2.jpg in domain/html/wp-content/plugins/enable-media-replace/enable-media-replace.php on line 131

And then when trying to replace the image with umlaut with another one

Warning: fileperms(): stat failed for domain/html/wp-content/uploads/A?O?U?-a?o?u?-a?a?a?-ø-a?-æ-A?O?U?-ß2.jpg in domain/html/wp-content/plugins/enable-media-replace/upload.php on line 93

Warning: Cannot modify header information - headers already sent by (output started at domain/html/wp-content/plugins/enable-media-replace/upload.php:93) in domain/html/wp-includes/pluggable.php on line 1207
Thank you for creating with WordPress.

The warning from the Media Library disappears when I deactivate the plugin.

404 - File or directory not found, when invoked

Not sure if this is related to my just updating to 3.2.1, but since doing so, I'm having issues. It shows uploading and percentage up to 99%, then fails with Server Error "404 - File or directory not found. The resource you are looking for might have been removed, had its name changed or is temporarily unavailable.

This is the first time I've ever seen this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.