I want to check if a user has uploaded a video so that i can send it to vimeo then delete the local file after updating the url in the database
function check_attachment(){
$video_mimes = array(
'video/mpeg',
'video/mp4',
'video/quicktime'
);
foreach ($video_mimes as $video_mime) {
if($video_mime == get_post_mime_type( $attachment->ID )){
$upload_url = get_attached_file( $attachment->ID);
$response = upload_to_vimeo($upload_url);//e.g videos/987654
update_attached_file( $attachment->ID, $response );
unlink($upload_url);//delete local file
echo "<script type='text/javascript'> alert('success'); </script>";
}
}
add_action('save_post', 'check_attachment');
my issue is get_post_mime_type
is returning false
and whenever i refresh the page the script executes even when its not a ‘new post’. Maybe the save_post
hook causes this, not sure