Support

Account

Home Forums Backend Issues (wp-admin) Can I delete images permanently?

Solved

Can I delete images permanently?

    • pjeaje

    • September 9, 2013 at 1:02 pm

    Can I delete images permanently (from the custom field image on the edit page) without having to go into the media manager?

    Thanks

    • Elliot

    • September 9, 2013 at 1:14 pm

    Hi @pjeaje

    By default, no.

    However, you could hook into the image update_value action and look for an empty value. If found, you could lookup the old value (get_field) and then use the ID to remove it from the DB completely.

    You can target all image update_value actions like so:

    
    function my_acf_update_value( $value, $post_id, $field  )
    {
        // do something else to the $post object via the $post_id
     
        return $value;
    }
     
    add_filter('acf/update_value/type=image', 'my_acf_update_value', 10, 3);
    

    Learn more:
    http://www.advancedcustomfields.com/resources/filters/acfupdate_value/

    • pjeaje

    • September 9, 2013 at 1:17 pm
    This reply has been marked as private.
    • Elliot

    • September 10, 2013 at 12:55 pm

    Hi @pjeaje

    No, the above code will not delete images.
    It is a demonstration of how you can hook into the update_value filter and delete it with code.

    Please remember that this is a support forum, not a free development service. I can point you in the right direction with functions, docs and general help, but I will not write your custom code for you.

    Thanks
    E

    • pjeaje

    • September 10, 2013 at 1:13 pm

    Please remember that this is a support forum, not a free development service.

    Thanks I never forgot, I was just asking as i didn’t know what the code did.

  • Do we have to use a specific field name for this, to get the previous value? I mean does this apply: get_field($field, $post_id) or we have to specify a field name like this ‘get_field(‘field_name’, $post_id)’. could you possibly write this tutorial, it would be much appreciated. Anyone found a solution on this?

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.