wip handle deleting images for prof deletion

This commit is contained in:
asus
2024-04-16 11:25:00 +02:00
parent ba432acbfc
commit 48ecd1d97b

View File

@@ -121,9 +121,46 @@ function handle_prof_account_deletion_CIPF($user_id) {
send_emails_CIPF('account_deleted', $user_id);
include_once(ABSPATH.'wp-admin/includes/user.php');
$user = get_user_by('id', $user_id);
// dont delete, for log
error_log("delete prof: " . $user->user_login);
wp_delete_user($user_id);
}
function prof_deletion_images_CIPF($user_id, $reassign, $user) {
Plgntls::debug_infos();
$role_prof = Cipf::ROLE_PROF;
if (!in_array($role_prof, $user->roles)) {
return;
}
$images = get_posts(array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'posts_per_page' => -1,
'author' => $user_id,
));
if (empty($images)) {
return;
}
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');
// }
}
}
add_action('deleted_user', 'prof_deletion_images_CIPF', 10, 3);