Skip to content

Instantly share code, notes, and snippets.

@max-kk
Last active May 15, 2018 09:20
Show Gist options
  • Save max-kk/f428b13486197639805c31ef57e064f4 to your computer and use it in GitHub Desktop.
Save max-kk/f428b13486197639805c31ef57e064f4 to your computer and use it in GitHub Desktop.
WP Foto Vote - Trigger when Youtube Video is uploaded and Video thumbnail parsed by Video addon
<?php
## Trigger when Youtube Video is uploaded and Video thumbnail parsed by Video addon
add_action("wp_youtube_upload_attachment_thumbnail_saved", function($att){
// Update competitor Thumbnail& change type to Video
$competitor = ModelCompetitors::q()->where('image_id', $att->get_post_id() )->findRow();
if ( !$competitor ) {
fv_log("wp_youtube_upload_attachment_thumbnail_saved >> no competitor!");
return;
}
if ( $competitor->storage != 'youtube' ) {
fv_log("wp_youtube_upload_attachment_thumbnail_saved >> storage is not youyube!");
return;
}
$postdata = array(
'post_title' => 'New Video from ' . $competitor->name,
'post_content' => '<iframe src="' . $competitor->url . '" width="800" height="600"></iframe>',
'post_author' => $competitor->user_id, // Admin ?
'post_type' => 'post', ## YOUR POST TYPE HERE ££
'post_status' => 'publish',
);
$post_id = wp_insert_post( $postdata );
if ( ! is_wp_error($post_id) ) {
add_post_meta( $post_id, '_thumbnail_id', $att->get_post_id() );
}
}, 99, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment