From 2466bee08e2a9a485fcc58e0d01567542be095ae Mon Sep 17 00:00:00 2001 From: denisbaranov Date: Wed, 26 Aug 2020 12:32:32 +0300 Subject: [PATCH] Fix: Don't delete photo that belongs to the Social Activity post or Groups post --- includes/core/class-uploader.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/includes/core/class-uploader.php b/includes/core/class-uploader.php index 7867dda4..8cfadff9 100644 --- a/includes/core/class-uploader.php +++ b/includes/core/class-uploader.php @@ -1350,7 +1350,21 @@ if ( ! class_exists( 'um\core\Uploader' ) ) { continue; } - unlink( $file ); + // Don't delete photo that belongs to the Social Activity post or Groups post + if ( strstr( $str, 'stream_photo' ) ) { + global $wpdb; + $is_post_image = $wpdb->get_var( " + SELECT COUNT(*) FROM {$wpdb->postmeta} + WHERE `meta_key`='_photo' AND `meta_value`='{$str}';" ); + if ( $is_post_image ) { + continue; + } + } + + $can_unlink = apply_filters( 'um_can_remove_uploaded_file', true, $user_id, $str ); + if ( $can_unlink ) { + unlink( $file ); + } } } }