Support » Plugin: Media Library Assistant » How to make image/attachment dates change to post publication date instead of up

  • Resolved TekGirlyMama

    (@tekgirlymama)


    Hi and thanks for this plugin!

    How to make image/attachment dates change to post-publication date instead of the folder upload date I see in source code as the image path?

    Is there a way to automate this task in the background, maybe some filter, so when I have future dated posts or backdated posts, their images and other possible file attachments look like they were uploaded in a relevant date to post being published.

    Is it possible to make some filter that replaces the dates, removes them or updates them with the actual post-publication date – for images, videos etc added to posts generated by a plugin that works on the principle of CPT [custome post type] and for any page/post?

    Thanks and a happy, successful 2019 to you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thanks for an interesting question. If I understand it correctly, you want to change the path name/folder location of the file(s) attached to a Media Library item; is that right? WordPress provides some hooks that you could use during the upload process:

    Plugin API/Filter Reference/wp handle upload prefilter

    Using this, in conjunction with the upload_dir, you can dynamically determine which directory to upload to, based on the files you upload.

    Plugin API/Filter Reference/upload dir

    This hook allows you to change the directory where files are uploaded to.

    MLA adds some metadata features to these hooks and provides hooks of its own; see the “MLA Custom Field and IPTC/EXIF Mapping Actions and Filters (Hooks)” section of the Settings/Media Library Assistant Documentation tab:

    mla_upload_prefilter – gives you an opportunity to record the original IPTC, EXIF and WordPress image_metadata before the file is stored in the Media Library. You can also modify the file name that will be used in the Media Library. Many plugins and image editing functions alter or destroy this information, so this may be your last change to preserve it.

    mla_upload_filter – gives you an opportunity to record some additional metadata for audio and video media after the file is stored in the Media Library.

    However, MLA does not provide any features to move the item’s file once the upload is complete. I do not know of any other plugin that will do that, either.

    Your desired application is more complex, moving and renaming files based on their association with a post/page. As you probably know, an item can be inserted or used in multiple posts/pages, so the folder structure can only agree with at most one of them. I imagine that you could use WordPress hooks to accomplish your goal if your application conforms to some sort of “one post/page per item” rule, but I do not think a general solution is possible.

    You can get a better sense of what’s involved by studying these plugins:

    Enable Media Replace

    Media File Renamer Auto

    I hope that gives you a better sense of what a solution would take to implement. I regret that I do not see how MLA could be of much use without quite a lot of custom PHP coding.

    I am marking this topic resolved because the question has been answered to the best of my ability. Please update it if you have any further questions I can try to help you with. Thanks for your interest in the plugin.

    Hi David,

    Thank you so much for your great support and super fast response. And for your time to detail useful info in your reply and for your good thoughts to help. Good karma to you!

    I asked since your plugin seems to be such a great Swiss army knife for media library, I thought perhaps there’s some capability to do this cosmetic date change with it.

    Actually, I was not thinking of moving files, just editing the date of the post attachment [image/other] to match the post-publication date instead of the media library upload date, as that file’s path is visible in source code ../uploads/yyyy/mm/….jpg and would be odd looking for backdated or future dated posts to have images in their content [post body] with an upload date that does not match!

    Well, just in case this helps others, I think I found some potential solutions for this in a CodeCanyon plugin ‘hide my wp’ which can change this path to a custom name [probably has a pretty link redirect or something] or possibly even better, from another CodeCanyon plugin by Coderevolution called Kraken – https://codecanyon.net/item/kraken-automatic-post-editor-plugin-for-wordpress/20620891 which can match the dates as I need.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update with the kind words and the additional information and for taking the time to post information on the other plugins you found.

    You wrote “Actually, I was not thinking of moving files, just editing the date of the post attachment [image/other] to match the post-publication date instead of the media library upload date, as that file’s path is visible in source code ../uploads/yyyy/mm/….jpg and would be odd looking

    The “date of the attachment” is stored in the database as the “upload date”, and MLA provides support for changing that value on the Media/Assistant page and the Media/Edit Media screen. Those changes were motivated by this earlier topic:

    Sorting a gallery, once again

    Your request is somewhat different. The “file’s path” that includes the year and month of the upload date is not a database entry, it is part of the file system directory structure within your site. The only way I know to change the path and URL values for the file attached to the item is to move the files to a different directory within the file system. You could also, as you suggest, use URL redirect rules to make the URLs look different. This approach strikes me as creating more problems than it solves, but you know your application better than I do.

    Again, thanks for your comments and I hope you find a solution that meets you needs.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.