From 48ecd1d97b2f2430f77e126462fc5d36d0bd1495 Mon Sep 17 00:00:00 2001 From: asus Date: Tue, 16 Apr 2024 11:25:00 +0200 Subject: [PATCH] wip handle deleting images for prof deletion --- .../cipf_plugin/php/profs_handle_states.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/plugins/cipf_plugin/php/profs_handle_states.php b/plugins/cipf_plugin/php/profs_handle_states.php index 5c94b3f..59e1dcf 100644 --- a/plugins/cipf_plugin/php/profs_handle_states.php +++ b/plugins/cipf_plugin/php/profs_handle_states.php @@ -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); +