Skip to content

Instantly share code, notes, and snippets.

@waelio
Last active December 29, 2015 13:06
Show Gist options
  • Save waelio/31976cadcac0a01745a4 to your computer and use it in GitHub Desktop.
Save waelio/31976cadcac0a01745a4 to your computer and use it in GitHub Desktop.
Remove unreal images from wp
<?php
$imgs = get_posts("post_type=attachment&numberposts=-1");
$x=0;
foreach($imgs as $img){
$file = get_attached_file($img->ID);
$Image_size = getimagesize($file);
if(!is_array($Image_size)){
wp_delete_post( $img->ID, false );
echo $x .'- Deleting attachment #'.$img->ID;
}else{
echo $x .'- OK! attachment #'.$img->ID;
}
echo '<br />';
$x++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment