WordPress.org

Ready to get started?Download WordPress

Forums

Transform Media Files back into Attachment pages (11 posts)

  1. Tk808
    Member
    Posted 9 months ago #

    Alright, i have over 8500 files uploaded to several pages in my wp site. All the files are media links, which is the direct download from the page they are on.

    I want to convert all those media files and link them back to their attachment pages without doing all 8500 files manually

    One solution could be redirecting the media file to the corresponding attachment ID. But i'm totally lost, need any information to get me pointed in the correct direction.

    Cheers!

    [Moderator Note: No bumping. If it's that urgent, consider hiring someone.]

  2. Ryan Hellyer
    Member
    Posted 8 months ago #

    I need exactly the same functionality. If you find a solution, please post back here with the answer :)

  3. Ryan Hellyer
    Member
    Posted 8 months ago #

    This should be possible to do in an automated fashion. The URLs used by WordPress look like <a href="$URL" so we should be able to write a plugin which parses that for each media file URL attached to the post, then string replace it and resave it into the database via wp_update_post().

    I'm hoping some kind soul out there has already written such a tool though as I'm keen to avoid writing it myself :/

  4. Tk808
    Member
    Posted 8 months ago #

    Here is an update of what i've found Ryan.

    Function for direct media file links falls under " Wp_Get_... "
    That can be found in WP-Includes/post-template.php

    http://codex.wordpress.org/Function_Reference/wp_get_attachment_url

    and
    Functions for attachment page files falls under just " Get_...
    Which can be found in WP-Includes/link-template.php

    http://codex.wordpress.org/Function_Reference/get_attachment_link

    Basically, you are going to force attachment pages on the media file links. I'll keep looking into it.

  5. Ryan Hellyer
    Member
    Posted 8 months ago #

    Yep, that sounds about right. Unfortunately it's putting all that together into something which can automate the changeover for us that is time consuming.

    I had a good Google around for this and asked on Twitter, but no one was able to help. So I might end up writing a plugin to do this myself. I have some things to do tonight, but if I can get them done quickly then I might tackle this tonight before I go to bed. If I don't do it this evening then it will likely need to wait a few months as I'm about to move to Germany and I'm sure I'll have lots of distractions there which will stop me from doing this upgrade (I've been thinking about doing this for a REALLY long time now).

  6. Ryan Hellyer
    Member
    Posted 8 months ago #

    Here's a very crude hack which does what you want ... http://geek.ryanhellyer.net/products/media-file-attachment-page-converter/

    If you have lots of posts it will explode. I have lots of posts on my own site, so I still need to set it up to iterate through each post individually to ensure that it will eventually process all my posts. I don't think I'll get that completed any time soon though.

  7. Ryan Hellyer
    Member
    Posted 8 months ago #

    I tested this out on a unimportant blog of mine and it worked perfectly ... http://random.ryanhellyer.net/

    I also tested it on my local server with my biggest site with over 500 posts and thousands of images and it worked fine on that too, so I'm probably not going to bother with designing it to scale up after all.

  8. Ryan Hellyer
    Member
    Posted 8 months ago #

    This has worked really well on my own site ... http://ryanhellyer.net/

    I made a few changes since I posted last, to correct for issues when using it with domain mapped multisite installs.
    http://geek.ryanhellyer.net/products/media-file-attachment-page-converter/

    Hopefully this does what you are trying to achieve :)

    The only issue I found is that most of my older images are not attached to their posts, so they were not converted. So now I need another plugin to automatically attach images to posts :/

  9. Tk808
    Member
    Posted 8 months ago #

    Hey man, i totally appreciate all your time and effort into writing that code/plugin.

    So I tested your code and inserted it into a php file, installed it like a plugin and activated it through the URL link you had posted on your awesome site... unfortunately, no success.

    I'll give it a shot again tomorrow though, maybe i overlooked something.

    On a side note, all my files are currently attached to pages and are RAR and ZIP files, so maybe image files are having a different effect.

    Cheers dude and good luck in Germany!

  10. Ryan Hellyer
    Member
    Posted 8 months ago #

    Am I able to see an example of the site so I can see what the links look like?

  11. Tk808
    Member
    Posted 8 months ago #

    radrom.com

    I'm about to give your plugin another go, i'll keep you updated.

Reply

You must log in to post.

About this Topic