added function to handle deletion of image when prof is deleted in case it was not taken care of

This commit is contained in:
asus
2024-04-16 11:41:17 +02:00
parent 5a78817979
commit f92e86a473

View File

@@ -127,7 +127,11 @@ function handle_prof_account_deletion_CIPF($user_id) {
wp_delete_user($user_id);
}
function prof_deletion_images_CIPF($user_id, $reassign, $user) {
/*
* it should not be necessary, but just in case
*
*/
function prof_deletion_ensure_images_are_deleted_CIPF($user_id, $reassign, $user) {
Plgntls::debug_infos();
$role_prof = Cipf::ROLE_PROF;
@@ -146,20 +150,17 @@ function prof_deletion_images_CIPF($user_id, $reassign, $user) {
}
foreach ($images as $image) {
$image_id = $image->ID;
// dont delete, for log
error_log('- delete image: ' . $image_id);
// Set the second argument to true to permanently delete the attachment
// $result = wp_delete_attachment($image_id, true);
// if ($result === false) {
// error_log('Failed to delete image with ID ' . $image_id);
// }
// else {
// error_log('Image with ID ' . $image_id . ' deleted successfully');
// }
$result = wp_delete_attachment($image_id, true);
if ($result === false) {
error_log('- failed to delete image: ' . $image_id);
}
else {
error_log('- delete image: ' . $image_id);
}
}
}
add_action('deleted_user', 'prof_deletion_images_CIPF', 10, 3);
add_action('deleted_user', 'prof_deletion_ensure_images_are_deleted_CIPF', 10, 3);