function video_process_form( $query ) { if ( $query->is_page( 'submit-video' ) && 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] )) { $output = null; if ( ! function_exists( 'wp_handle_upload' )) { require_once(ABSPATH . "wp-admin" . '/includes/image.php'); require_once(ABSPATH . "wp-admin" . '/includes/file.php'); require_once(ABSPATH . "wp-admin" . '/includes/media.php'); } $file = $_FILES; // Do some minor form validation to make sure there is content if ($_POST['title'] != null && $_POST['title'] != 'Video Title') { $title = $_POST['title']; } else { $output .= 'Please enter a video title
'; } if ($_POST['description'] != null && $_POST['description'] != 'Video Description') { $description = $_POST['description']; } else { $output .= 'Please enter a description
'; } if ($_POST['video_url'] != null && $_POST['video_url'] != 'Youtube URL') { $vid_url = $_POST['video_url']; $video_id = getVideoId($vid_url); if ($video_id) { $curr_curl = "http://gdata.youtube.com/feeds/api/videos/".$video_id."?alt=json&v=2"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $curr_curl); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); printf($code); curl_close($ch); if($code == 200) { $video_url = $vid_url; } else { $output .= 'This is not an existing youtube video
'; } } else { $output .= 'This is not an existing youtube video
'; } } else { $output .= 'This is not an existing youtube video
'; } $tags = $_POST['post_tags']; // Add the content of the form to $post as an array $new_post = array( 'post_title' => $title, 'post_content' => $description, 'tags_input' => array($tags), 'post_category' => array(12), 'post_status' => 'publish', // Choose: publish, preview, future, draft, etc. 'post_type' => fod_videos // Use a custom post type if you want to ); // If No Errors, Save Post and Redirect // if ($output == null) { $pid = wp_insert_post($new_post); update_post_meta($pid,'video_code',$video_url); wp_redirect( get_permalink($pid)); // If Errors, Return Errors for Display in Template // } else { echo $output; } } do_action('wp_insert_post', 'wp_insert_post'); } add_action( 'pre_get_posts', 'video_process_form' );