BuddyBoss Home – Web Support Forums Plugins BuddyBoss Wall Auto delete images off server when activity stream update also deleted

Tagged: 

Viewing 5 posts - 1 through 5 (of 5 total)
  • Question

    #56933
    @markob17

    Hi, I’m wondering if anybody could tweak the following function to auto delete images from the server when an activity stream update (in which an image is attached when using the URL preview feature) is deleted. How it is set up now, when an activity stream update is deleted by a member, the URL preview image/images are left on the server wasting disk space. Other than this caveat, the URL preview feature of this plugin is flawless.

    I tweaked the following code from a function I found that auto deletes images from posts/custom posts when the post itself is deleted. My coding experience is very limited. I pretty much left the code intact but only added the $activity_id variable and bp_activity_action_delete_activity action thinking it would possibly work. Not sure if I’m even on the right track, I honestly just don’t have the knowledge set to figure this out. Maybe I am totally wrong, but hoping someone can make this work by modifying this function. Appreciate the input!

    function delete_attachments($activity_id) {
    	$args = array(
    		'post_type' => 'attachment',
    		'numberposts' => -1,
    		'post_status' => null,
    		'post_parent' => $activity_id
    	
    	);
    	$attachments = get_posts($args);
    	
    	if ($attachments) {
    		foreach($attachments as $attachment) {
    			wp_delete_attachment($attachment->ID, true);
    			
    		}
    	}
    }
    
    add_action('bp_activity_action_delete_activity', 'delete_attachments');

    Answers

    #57110
    @vapvarun

    Hi @markob17,
    It already inside our suggestion list and attached Activity is not a post type and we can not query like that.
    It depends on plugin specific in which way they have linked media to activity.
    Like BuddyPress activity plus stores media in different way, and media plugins stores in different way.

    From wall plugin we can delete only those images which have been posted by url submission.

    Regards

    #57159
    @markob17

    Hi @vapvarun,

    Thank you very much for the clarification and for adding this to your suggestion list, really appreciate it!

    Best Regards,

    Mark

    #60055
    @markob17

    Hi @vapvarun, thanks for taking care of this with the recent update! That was a quick turnaround, appreciate it.

    Best Regards,

    mark

    #60056
    @vapvarun

    Thanks, I will close this topic
    Regards
    Varun Dubey

Viewing 5 posts - 1 through 5 (of 5 total)
  • The question ‘Auto delete images off server when activity stream update also deleted’ is closed to new replies.