On upload media title renamed too
-
Before the last update if I uploaded a media, its title was ok from the filename.
Now the title is “renamed” too which is bad.
Can you please fix it?
Thanks
-
What do you mean? Do you have an example? The title is (normally) only renamed if the option is checked, did you check it? I have tested my current version but can’t reproduce this issue at all.
I have a file: “G?ztisztító Ariete MULTI VAPORI.png”
After upload:
-Without the plugin:
Media Title: G?ztisztító Ariete MULTI VAPORI
File name: G?ztisztító-Ariete-MULTI-VAPORI.png
-With the plugin:
Media Title: goztisztito-ariete-multi-vapori
File name: goztisztito-ariete-multi-vapori.pngActually, that was not a new bug introduced with a new version. Before, the rename on upload was only working if the Title was detected (from EXIF) or if there was an attached post.
Then the last version renamed it also if those conditions were not met, basically replacing the spaces, the big letters, basically doing some cleaning. As a side effect, the title was also changed by WordPress, but not by the plugin.
I found a way to fix that.
There is a new version: 3.7.2. Can you try it?
I upgraded to 3.7.2
Now the title is ok. The filename is ok.
Except:
If the filename begins with accent character, then it is cropped off from both.
Filename: “állvány láb.png”
Media title:”llvány láb”
Filename: “llvany-lab.png”Something is weird: I actually make sure I keep the previous filename to generate the new title through the process. It’s a trick so that WordPress doesn’t use my new filename to create the title. It works because you get to keep the space. So the fact that the first letter is removed happens somewhere else.
I tried to reproduce your issue, with exactly the same filename but it works for me.
With the plugin off, does it work? I think it’s a problem linked to the install, not really the plugin.
It’s weird really. I switched off all other plugin, and the first character is still cropped.
Can I switch debug mode on or something?
I have programing skills, so if you could point me at a file or function I can investigate the issue.
Thanks!I just found the line.
The problem is that the wp_read_image_metadata() give back the wrong name.
I suspected the gimp first, but now just picked a random file from the net renamed it and the first char was cropped again.
So the problem is with wp_read_image_metadata()
I think it use some image lib so the problem is with my php/server environment (becouse the problem doesn’t affect you)
Thanks for helping, I will find some workaround to solve this.I was wrong.
The pathinfo() is bad.
I found an old thread about this:
https://stackoverflow.com/questions/32115609/basename-fail-when-file-name-start-by-an-accent
It’s weird, becouse my php is newer, but it seems, the bug is still there.I just leave it here, maybe somebody, can use it.
This fix the first character croping with bad php pathinfo()diff -ruN ./core.php ../../media-file-renamer/core.php --- ./core.php 2017-11-08 14:02:17.000000000 +0100 +++ ../../media-file-renamer/core.php 2017-11-08 20:29:49.288881000 +0100 @@ -404,6 +404,9 @@ $pp = pathinfo( $file['name'] ); + $pp['basename']=end(explode('/',$file['name'])); + $pp['filename']=preg_replace('/\.[^.]*$/','',$pp['basename']); + // If everything's fine, renames in based on the Title in the EXIF $method = apply_filters( 'mfrh_method', 'media_title' ); if ( $method == 'media_title' ) { @@ -430,7 +433,7 @@ add_filter( 'wp_read_image_metadata', array( $this, 'wp_read_image_metadata' ), 10, 2 ); // Modify the filename - $pp = pathinfo( $file['name'] ); + //$pp = pathinfo( $file['name'] ); $file['name'] = $this->new_filename( null, $pp['basename'] ); return $file; } @@ -908,6 +911,8 @@ else { // It's an upload, let's check if the extension is provided in the text $pp = pathinfo( $text ); + $pp['basename']=end(explode('/',$text)); + $pp['filename']=preg_replace('/\.[^.]*$/','',$pp['basename']); $new_ext = empty( $pp['extension'] ) ? "" : $pp['extension']; $text = $pp['filename']; }
Thank you for finding this ?? If you don’t mind, maybe you should create a new support thread with a status “not a support question” and with an explicit title like “First character is cropped – Pathinfo issue – UTF8”. And paste your code in that article. It will be then easier to found and well referenced. Thanks a lot again!
done ??
one more thing I mentioned earlier:
the replace_special_chars function.
I just patched it as well, because I heated the ? -> oe, ü -> ue convertion.
(we have other chars like ??íóú and the function ignores these, so the whole thing is inconsistent, and anyway, in Hungary we don’t use this type of conversions, since – I don’t know – 1990)
Is it only for German characters?
An option, to disable this, would be good ??
While I’m using this php version, I have to patch the plugin anyway, I just wanted to inform you about this ??
Thanks
- The topic ‘On upload media title renamed too’ is closed to new replies.