/**
 * Delete the attachments related to the specified post.
 *
 * @param $post_id
 */
function wl_delete_post_attachments($post_id)
{
    // Get all the attachments related to the post.
    $attachments = wl_get_attachments($post_id);
    // Delete each attachment.
    foreach ($attachments as $attachment) {
        if (false === wp_delete_attachment($attachment->ID)) {
            wl_write_log("wl_delete_post_attachments : error [ post id :: {$post_id} ]");
        }
    }
}
 function testSaveExistingImages()
 {
     $images = array('http://upload.wikimedia.org/wikipedia/commons/f/ff/Tim_Berners-Lee-Knight.jpg', 'http://upload.wikimedia.org/wikipedia/commons/3/3a/Tim_Berners-Lee_closeup.jpg', 'http://upload.wikimedia.org/wikipedia/commons/c/c2/Tim_Berners-Lee_2012.jpg', 'http://upload.wikimedia.org/wikipedia/commons/3/3a/Tim_Berners-Lee_closeup.jpg');
     $entity_post = wl_save_entity(array('uri' => 'http://example.org/entity', 'label' => 'Entity', 'main_type' => 'http://schema.org/Thing', 'description' => 'An example entity.', 'type_uris' => array(), 'related_post_id' => null, 'image' => $images, 'same_as' => array()));
     // Get all the attachments for the entity post.
     $attachments = wl_get_attachments($entity_post->ID);
     // Check that there is one attachment.
     $this->assertEquals(3, count($attachments));
     // Check that the attachments are found by source URL.
     foreach ($images as $image) {
         $image_post = wl_get_attachment_for_source_url($entity_post->ID, $image);
         $this->assertNotNull($image_post);
     }
 }