Support » Plugin: Autoremove Attachments » newbie help – remove by tag?

  • Resolved catsfoto1se

    (@catsfoto1se)


    hi!

    I hope you’re still around 😉

    I have really looked for a function like this, I think its stupid of wordpress to not delete attachments automatically.

    Now to my issue, I’m pretty new, and didn’t understand your faq to restrict what posts and so on.

    Is it possible to tell the plugin to remove attachment to specific tags / categories?
    If would be great if it did, because then I could tell it to only delete attachments to posts that have the tag “delete_all”, and that way be sure it don’t delete anything else by mistake..

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Contributor Eusebiu Oprinoiu

    (@eusebiuoprinoiu)

    Hello, catsfoto1se!

    There is no relationship between attachments and tags, so you can’t mark attachments for deletion that way.

    If you want an image to be removed automatically when the parent post is removed, you must add it from the New Post/Page/CPT screen. If you add it using the global Media menu, your image won’t have a parent and won’t be removed automatically.
    To make things clear, I made a small visual guide here: https://i.imgur.com/GiGcXmZ.png

    The only real limitation of the plugin is how you use your media. If an image is added as a child for a specific post, it should only be used inside that post. If you start reusing that image by inserting it in other posts/pages/CPTs, you will end up with missing images if you delete the parent post. If you need to use the same image in multiple locations on your website, upload it from Media > Add New. This way it won’t have a parent and it won’t be removed automatically.

    I hope this helps. If it’s still not clear, let me know!

    Best regards,
    Eusebiu Oprinoiu

    Hi again.

    Yes, that part does I understand (now), but I’m using different plug-in and editors, and I don’t want this plug-in to remove pictures from other parts, because I do use some images several times.

    I have front end posting on my site, and all post there are automatically tagged “outside”.

    To be absolutely sure that it don’t remove pictures from other plug-in, (that also uses post, like ups-pro, I wondered if it was possible to tell your plug-in to ONLY process posts that have a specific tag.
    That way I can be sure of that it don’t removes images from other posts..

    Plugin Contributor Eusebiu Oprinoiu

    (@eusebiuoprinoiu)

    Unfortunately, it’s not possible. This is a very edge-case scenario and I don’t plan to add something like this to the core plugin.
    However, I can add a filter you can use to add your own custom rules.

    So this is what I am going to do:
    1. I will release an update that adds this filter
    2. I’ll take some time to properly test this, so I won’t cause any issues for those already using the plugin
    3. I’ll come back here with instructions for your specific case.

    While I do this, please, let me know exactly what rules you need. From what you’ve told me so far, the removal should be done only for posts that have the tag “outside”. Is this correct? Is there any other rule you need?

    Hi again.
    I would really appreciate it, it will be used on my site rainbowcats.org , and the tags are:

    Allow my cat to be listed
    Don’t show my cat on that list!

    Thx a lot

    Plugin Contributor Eusebiu Oprinoiu

    (@eusebiuoprinoiu)

    Hello!

    I released the update. After updating to the latest version, add the following code snippet in a custom plugin or as a code snippet using this plugin:
    https://wordpress.org/plugins/code-snippets

    IMPORTANT: Make sure you add the actual slugs of your tags in the $allowed_tags variable. You can find those slugs on the Tags page.

    
    function autoremove_attachments_custom_rule() {
    	global $post_id;
    
    	$allowed_to_remove = false;
    	$allowed_tags = array (
    		'tag-1-slug',
    		'tag-2-slug',
    		'tag-3-slug',
    	);
    	
    	if ( has_tag( $allowed_tags, $post_id ) ) {
    		$allowed_to_remove = true;
    	}	
    
    	return $allowed_to_remove;
    }
    add_filter( 'autoremove_attachments_allowed', 'autoremove_attachments_custom_rule' );
    

    After you add this code snippet on your website, please make a test and let me know if it works.

    Best regards,
    Eusebiu Oprinoiu

    Hi again!
    It worked perfectly, I added 2 tag-slugs in the code, created 3 post, (1 with another tag)

    Deleted the post 1 after 1, while watching the image directory in real-time, and all photos, except the last post’s photo, vanished from the server.

    It was a total success! Thx a lot!

    I’m sure other users can benefit from this, because now they don’t need to be worried about images vanishing, unless they have the right tag assigned!

    Plugin Contributor Eusebiu Oprinoiu

    (@eusebiuoprinoiu)

    Awesome! I’m glad I could help! 🙂
    Would you consider leaving a review?

    Best regards,
    Eusebiu Oprinoiu

    I actually just did!, I’ve would have given 10 Stars, but they only had 5

    Plugin Contributor Eusebiu Oprinoiu

    (@eusebiuoprinoiu)

    Thank you! You’re awesome! 🙂

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘newbie help – remove by tag?’ is closed to new replies.