Opened 12 years ago
Closed 11 years ago
#21323 closed defect (bug) (wontfix)
wp_delete_attachment (leaves stale image class wp-image-### in content of post).
Reported by: | eliddon | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.4.1 |
Component: | Media | Keywords: | |
Focuses: | Cc: |
Description
Here is my Example I'm using:
Running a script below (placed in the wordpress docroot) to delete all thumbnails from the database:
require_once("wp-load.php"); echo 'Working... '; ob_flush(); global $wpdb; $attachments = $wpdb->get_results("SELECT * FROM $wpdb->postmeta WHERE meta_key = '_thumbnail_id'"); foreach($attachments as $attachment){ $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_id = '$attachment->meta_id' LIMIT 1"); wp_delete_attachment($attachment->meta_value, true); } echo 'done!';
Now after running something like above I'm left with (inside my content of each post) a stale image class tag that no longer points anywhere.
I think a simple regex replace of the post_content for wp-image-#### Inside an Image tag would remove the stale element.
I haven't checked this with other attachment types to see if it also exists, but my guess is it would.
Change History (2)
Note: See
TracTickets for help on using
tickets.
Removing old image references in all posts can be a non-trivial task on large sites, and it's not really a job for
wp_delete_attachment()
. If necessary, it should be done in the same script that calls it. Suggest wontfix.