• Resolved ninsan

    (@jennyrigsjo)


    Hello,

    I have enabled the “move to trash” functionality for media library files by adding define( ‘MEDIA_TRASH’, true ); in wp-config.php. My question is, is it possible to customize the number of days that pass before the trashed media files are permanently deleted? I know of the ‘EMPTY_TRASH_DAYS’ constant, but from what I can tell this seems to only apply to posts (including custom post types), pages and comments. I’m looking for a way to target the amount of time that trashed files are stored in the media library trash specifically.

    Thanks. ??

    /jenny

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hey,

    I’m just guessing here, but media is just a post type ( of attachment ) so why would it not apply? Have you seen that or found out another way?

    Thread Starter ninsan

    (@jennyrigsjo)

    @fullworks Hello, thank you for replying. ?? You make a good point and, admittedly, I have not tested whether setting the ‘EMPTY_TRASH_DAYS’ constant has any effect on media library files. However, as I am interested in targeting trashed files in the media library exclusively, it wouldn’t be an option anyway as setting the constant would also alter the auto-delete interval of posts, pages and comments. The site I am building requires trashed media files to be saved for 14 days before permanent removal, while other post types should be saved for the default period of 30 days before permanent deletion.

    /jenny

    It would be interesting to see if there is a ‘built in’ method to do that.

    Of course it is possible and could be done with probably less than 20 lines of code. If you are a coder I can point you in the right direction.

    There may well already be a plugin to do similar.

    • This reply was modified 4 years, 1 month ago by fullworks.
    • This reply was modified 4 years, 1 month ago by fullworks.
    Thread Starter ninsan

    (@jennyrigsjo)

    If there is a built-in function, I haven’t had any luck in finding it. :/

    I have some coding experience, so if there is a way to do it without using a plugin, I’d be happy to try it. ??

    This should do it ( untested ) – read and understand.

    In reality it is best installed as a plugin as it is functionality.

    I have written the basics of a plugin to do this here, it should work, but untested.

    The concept is you can define define('EMPTY_MEDIA_TRASH_DAYS', 7);

    Enable the plugin and away it goes. No guarantee / warrantee / untested / backup first don’t use on alive site till you are tested type of caveats.

    https://gist.github.com/alanef/c70819c94f9712e2b73cd78ac5dbbee3

    • This reply was modified 4 years, 1 month ago by fullworks.
    Thread Starter ninsan

    (@jennyrigsjo)

    @fullworks I just realized I never got back to you on this. I just wanted to let you know that I tried the code you provided (placed it a mu-plugin file) and it works excellently. Thank you for your help! ??

    Alan Fuller

    (@alanfuller)

    Thank you for taking the time to thank me ??

    Thread Starter ninsan

    (@jennyrigsjo)

    @alanfuller You’re welcome and thank you again! ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Auto-delete trashed media files after {custom number} of days?’ is closed to new replies.