[wp-trac] [WordPress Trac] #21323: wp_delete_attachment (leaves stale image class wp-image-### in content of post).

WordPress Trac wp-trac at lists.automattic.com
Fri Jul 20 13:33:57 UTC 2012


#21323: wp_delete_attachment (leaves stale image class wp-image-### in content of
post).
--------------------------+-----------------------------
 Reporter:  eliddon       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Media         |    Version:  3.4.1
 Severity:  trivial       |   Keywords:  needs-patch
--------------------------+-----------------------------
 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.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/21323>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list