• moxymore

    (@moxymore)


    Hello,

    Just my two cents, but why make a plugin like this if the permalinks aren’t updated? It’s just useless to rename a file and having 404 errors because permalinks are wrong.

    Do you plan to implement a such features in order to edit my review or not?

    • This topic was modified 8 years ago by moxymore.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Pablo Pacheco

    (@karzin)

    Thanks for the feedback.
    Can you give me an example?

    I’m going to take a look when i can

    Thread Starter moxymore

    (@moxymore)

    Hi there,

    Sorry, I have missed your post. Do you use a such function in your plugin? https://codex.www.ads-software.com/Function_Reference/update_attached_file

    https://wordpress.stackexchange.com/a/31172

    Plugin Author Pablo Pacheco

    (@karzin)

    Hello, no problem.
    No i don’t.

    What i am using to change file name is only one hook.
    A filter called ‘sanitize_file_name’.

    And for what i can say, it’s called before the image is uploaded. So i think there is no need to use update_attached_file().

    But I’m going to take a look again. Anyway, can you give me an example of the problem?
    Thanks

    Thread Starter moxymore

    (@moxymore)

    Hi there, sorry I was busy.

    I have probably found the issue. If you take a look closely at what your plugin does, it simply rename the file on upload without changing its metadata. And because of that, the post created for the attachment (every single image has an internal wordpress post) has an url which references the name BEFORE the rename.

    In short, you probably have to use wp_update_attachment_metadata() just after having renamed the image in order to update the image’s metadata (here, the post’s name).

    Take a look at this example :

    [215] => WP_Post Object
            (
                [ID] => 215
                [post_author] => 1
                [post_date] => 2016-12-10 20:46:16
                [post_date_gmt] => 2016-12-10 19:46:16
                [post_content] => 
                [post_title] => Alternative - League of Legends - 03
                [post_excerpt] => 
                [post_status] => inherit
                [comment_status] => open
                [ping_status] => closed
                [post_password] => 
                [post_name] => league-of-legends-faire-un-penta-avec-le-mur-d-anivia-c-est-possible_20890_wide1
                [to_ping] => 
                [pinged] => 
                [post_modified] => 2016-12-10 20:48:51
                [post_modified_gmt] => 2016-12-10 19:48:51
                [post_content_filtered] => 
                [post_parent] => 126
                [guid] => https://voluntary_hidden_path.jpg
                [menu_order] => 0
                [post_type] => attachment
                [post_mime_type] => image/jpeg
                [comment_count] => 0
                [filter] => raw
            )

    Here is a part of the array extracted with get_attached_media( ‘image’ ). For this image, you can see all its related metadata. You can clearly see that [post_name] hasn’t been modified during upload and corresponds to the original filename BEFORE upload.

    And because the standard permalink structure for images posts take this [post_name] for the url, this leads to a 404 error if you click on the link related to the post image.

    The only thing you have to do is to update this [post_name] just AFTER the rename process in order to give it the same value as your sanitize_file_name (without omitting to add a $count=++ in order to avoid duplicates and potential error).

    Do you get it?

    • This reply was modified 7 years, 11 months ago by moxymore.
    Thread Starter moxymore

    (@moxymore)

    Well, this is not as simple. In facts, what I have written doesn’t solve the issue… because the database reference isn’t updated.

    I don’t know if you are able to solve this, but if not, you have to inform the user on How to redirect attachments pages to the original post, because if not, google referenced image will lead to a 404 page.

    Plugin Author Pablo Pacheco

    (@karzin)

    Hum thanks! I’m going to take a look

    Plugin Author Pablo Pacheco

    (@karzin)

    Hello @moxymore,
    I’m making some improvements on the next version of the plugin.

    I uploaded a bunch of files and i couldn’t get any 404 errors.
    The post name is used to create the permalink indeed. But i don’t know if i should change this. If the user uploads a file with a name i think he wants to keep that name on the permalink right? I’m only changing the filename for SEO reasons and to make the file upload work.

    Do you still think it’s a good idea?
    Thanks!

    Plugin Author Pablo Pacheco

    (@karzin)

    Hello @moxymore.
    I’ve updated the plugin to version 2.0.0 and i’ve created the update permalink option.

    Can you see if it’s working like you wanted?
    Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Useless because it doesn’t change permalinks’ is closed to new replies.