Title: Feature request
Last modified: November 16, 2023

---

# Feature request

 *  Resolved [mehdimoradi7172](https://wordpress.org/support/users/mehdimoradi7172/)
 * (@mehdimoradi7172)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/feature-request-1010/)
 * hi
 * thank you for ur great plugin, i need to see some cool features in ASE.
    - Delete all images of a post or product or CPT after deleting the post/product.
      at the moment the images remain in the database and bloat it. after the post
      was deleted, all images (featured image, gallery and images in the content)
      should be deleted
    - wordpress and woocommerce makes different image sizes like medium, medium 
      large, single 600 and etc, being able to disable them will be a great option
      and let us decide which one should be generated.
 * note: please at this features to the free version
    -  This topic was modified 2 years, 6 months ago by [mehdimoradi7172](https://wordpress.org/support/users/mehdimoradi7172/).

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Bowo](https://wordpress.org/support/users/qriouslad/)
 * (@qriouslad)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/feature-request-1010/#post-17208495)
 * What are you using/doing to achieve the first one? i.e. delete images as you 
   delete a post.
 * The second one has been requested as well, most likely will go into the Pro version.
   Please understand that the free version is already generous enough with 40+ modules.
 *  Thread Starter [mehdimoradi7172](https://wordpress.org/support/users/mehdimoradi7172/)
 * (@mehdimoradi7172)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/feature-request-1010/#post-17208516)
 * For both i use a code from chat gpt.
 * 1- code to delete images:
 *     ```wp-block-code
       // Hook into post deletion
       add_action('before_delete_post', 'delete_related_images_bulk');
   
       function delete_related_images_bulk($post_id) {
           static $all_attachment_ids = array(); // Store all attachment IDs
   
           if (function_exists('is_product') && is_product($post_id)) {
               // If it's a WooCommerce product, get the product gallery attachments
               $product = wc_get_product($post_id);
               $attachment_ids = $product->get_gallery_image_ids();
           } else {
               // For regular posts, get attached images including featured image
               $attachment_ids = get_attached_media('image', $post_id);
               $featured_image_id = get_post_thumbnail_id($post_id); // Get the featured image ID
               if ($featured_image_id) {
                   $attachment_ids[] = $featured_image_id; // Add the featured image to the array
               }
           }
   
           if (!empty($attachment_ids)) {
               $all_attachment_ids = array_merge($all_attachment_ids, $attachment_ids);
           }
   
           // Final deletion action after all posts are processed
           add_action('delete_post', function() use ($all_attachment_ids) {
               foreach ($all_attachment_ids as $attachment_id) {
                   // Check if the attachment is used in other posts or products
                   $usage_count = count(get_posts(array('post_type' => array('post', 'product'), 'post_status' => 'any', 'meta_query' => array(array('key' => '_thumbnail_id', 'value' => $attachment_id)))));
   
                   if ($usage_count <= 1) { // If used only in the current post/product
                       wp_delete_attachment($attachment_id, true); // Delete the attachment
                   }
               }
           });
       }
       ```
   
 *  Plugin Author [Bowo](https://wordpress.org/support/users/qriouslad/)
 * (@qriouslad)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/feature-request-1010/#post-17208528)
 * Thanks for the code snippets. Great that it also has a check to see if an image
   is used in another post or not.
 *  Thread Starter [mehdimoradi7172](https://wordpress.org/support/users/mehdimoradi7172/)
 * (@mehdimoradi7172)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/feature-request-1010/#post-17208544)
 * Yes, hope to see it in your plugin 🌹🙏

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Feature request’ is closed to new replies.

 * ![](https://ps.w.org/admin-site-enhancements/assets/icon-256x256.png?rev=3099794)
 * [Admin and Site Enhancements (ASE)](https://wordpress.org/plugins/admin-site-enhancements/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/admin-site-enhancements/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/admin-site-enhancements/)
 * [Active Topics](https://wordpress.org/support/plugin/admin-site-enhancements/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/admin-site-enhancements/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/admin-site-enhancements/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [mehdimoradi7172](https://wordpress.org/support/users/mehdimoradi7172/)
 * Last activity: [2 years, 6 months ago](https://wordpress.org/support/topic/feature-request-1010/#post-17208544)
 * Status: resolved