Hi @navinachettri,
I hope you are well today and thank you for your question.
You can achieve this by adding the following code in the functions.php file of your child theme.
function delete_activity_plus_images( $args ) {
if (!defined('BPFB_BASE_IMAGE_DIR')) {
define('BPFB_BASE_IMAGE_DIR', $wp_upload_dir['basedir'] . '/bpfb/', true);
}
// Get the contents of the activity we are about to delete
global $wpdb;
$content = $wpdb->get_var( $wpdb->prepare( "SELECT content FROM ".$wpdb->prefix."bp_activity WHERE id = %d;", $args['id'] ) );
if ($content != '') {
// Look for the shortcode surrounding image filenames uploaded the BPAP
$matches = array();
preg_match('/\[bpfb_images\](.*?)\[\/bpfb_images\]/s', $content, $matches);
// If there are any images, delete each one and its thumbnail
if ($matches) {
foreach ($matches as $match) {
$images = array();
$images = explode('\n', trim(strip_tags($match)));
if (!empty($images)) {
foreach ($images as $image) {
unlink(BPFB_BASE_IMAGE_DIR.$image);
$image_fn = substr($image, 0, strrpos($image, '.'));
$image_ext = substr($image, strrpos($image, '.') + 1);
unlink(BPFB_BASE_IMAGE_DIR.$image_fn.'-bpfbt.'.$image_ext);
}
}
}
}
}
}
add_action( 'bp_before_activity_delete', 'delete_activity_plus_images');
This functionality will be added in the future version of BuddyPress Activity Plus plugin so you don’t have to add this code manually but sorry i can’t publish exact ETAs.
Best Regards,
Vinod Dalvi
Hi there,
We have now added the plugin option to delete images from the folder whenever it is deleted from the activity stream.
To enable this option just check the checkbox of plugin option “Clean up images?” on the following path.
Admin Area -> Settings -> Activity Plus -> Misc
Cheers,
Vinod Dalvi