Make WordPress Core

Opened 11 years ago

Closed 10 years ago

#21323 closed defect (bug) (wontfix)

wp_delete_attachment (leaves stale image class wp-image-### in content of post).

Reported by: eliddon's profile eliddon Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4.1
Component: Media Keywords:
Focuses: Cc:


Here is my Example I'm using:
Running a script below (placed in the wordpress docroot) to delete all thumbnails from the database:

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)

#1 @SergeyBiryukov
10 years ago

  • Keywords close added; needs-patch removed

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.

#2 @SergeyBiryukov
10 years ago

  • Keywords close removed
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Severity changed from trivial to normal
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.