How to force_delete files in custom uploads folder?

Support MB Custom Post Type How to force_delete files in custom uploads folder?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #15367
    webdevwebdev
    Participant

    It's a bit of an edge case.

    Specifically, with these settings for a custom post type:

                'type'             => 'file',
                'force_delete'     => true,
                'upload_dir' => WP_CONTENT_DIR . '/resources/',
    

    File deletes as expected when deleted from CPT edit screen, but if the containing post is binned and the bin emptied, the uploaded file remains. I can write a hook if you could suggest the best action/filter, but was wondering if there are any other parameters that can be passed to ensure the file is deleted?
    Thanks

    #15377
    Anh TranAnh Tran
    Keymaster

    Hi, at the moment there's no params to delete files when a post is permanently deleted from the Trash. However, WordPress has a hook delete_post (https://codex.wordpress.org/Plugin_API/Action_Reference/delete_post) to let you do custom actions. In this case, you can get the post files and delete them.

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