Action: postie_file_added

This action is called after Postie successfully extracts anĀ email attachment and adds it as a media item to the post. At the point it is called there is only a placeholder post, e.g. the content and metadata is not set yet.

add_action('postie_file_added', 'my_fileadded', 10, 3);

function my_fileadded($postid, $attachmentid, $fileinfo) {
    $file = $fileinfo['file'];
    $url = $fileinfo['url'];
    $mimetype = $fileinfo['type'];
    //Do something like set featured image
    if (strpos($mimetype, 'image', 0) === 0) { //only if attachment is an image
        set_post_thumbnail($postid, $attachmentid);
    }
}

Comments are closed.