Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Sep 21st, 2012  |  syntax: None  |  size: 3.01 KB  |  views: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function video_process_form( $query ) {
  2.     if ( $query->is_page( 'submit-video' ) && 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] )) {
  3.  
  4.         $output = null;
  5.  
  6.         if ( ! function_exists( 'wp_handle_upload' )) {
  7.             require_once(ABSPATH . "wp-admin" . '/includes/image.php');
  8.             require_once(ABSPATH . "wp-admin" . '/includes/file.php');
  9.             require_once(ABSPATH . "wp-admin" . '/includes/media.php');
  10.         }
  11.  
  12.         $file = $_FILES;
  13.  
  14.         // Do some minor form validation to make sure there is content
  15.         if ($_POST['title'] != null && $_POST['title'] != 'Video Title') {
  16.             $title =  $_POST['title'];
  17.         } else {
  18.             $output .= 'Please enter a video  title<br/>';
  19.         }
  20.  
  21.         if ($_POST['description'] != null && $_POST['description'] != 'Video Description') {
  22.             $description = $_POST['description'];
  23.         } else {
  24.             $output .= 'Please enter a description<br/>';
  25.         }
  26.  
  27.         if ($_POST['video_url'] != null && $_POST['video_url'] != 'Youtube URL') {
  28.             $vid_url = $_POST['video_url'];
  29.             $video_id = getVideoId($vid_url);
  30.             if ($video_id) {
  31.               $curr_curl = "http://gdata.youtube.com/feeds/api/videos/".$video_id."?alt=json&v=2";
  32.               $ch = curl_init();
  33.               curl_setopt($ch, CURLOPT_URL, $curr_curl);
  34.               curl_setopt($ch, CURLOPT_HEADER, false);
  35.               curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  36.               $response = curl_exec($ch);
  37.               $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  38.               printf($code);
  39.               curl_close($ch);
  40.               if($code == 200) {
  41.                   $video_url = $vid_url;
  42.               } else {
  43.                   $output .= 'This is not an existing youtube video<br/>';
  44.               }
  45.             } else {
  46.               $output .= 'This is not an existing youtube video<br/>';
  47.             }
  48.         } else {
  49.               $output .= 'This is not an existing youtube video<br/>';
  50.         }
  51.         $tags = $_POST['post_tags'];
  52.  
  53.         // Add the content of the form to $post as an array
  54.         $new_post = array(
  55.             'post_title'    => $title,
  56.             'post_content'  => $description,
  57.             'tags_input'    => array($tags),
  58.             'post_category' => array(12),
  59.             'post_status'   => 'publish',           // Choose: publish, preview, future, draft, etc.
  60.             'post_type' => fod_videos  // Use a custom post type if you want to
  61.         );
  62.  
  63.         // If No Errors, Save Post and Redirect //
  64.         if ($output == null) {
  65.             $pid = wp_insert_post($new_post);
  66.             update_post_meta($pid,'video_code',$video_url);
  67.             wp_redirect( get_permalink($pid));
  68.         // If Errors, Return Errors for Display in Template //
  69.         } else {
  70.             echo $output;
  71.         }
  72.     }
  73.     do_action('wp_insert_post', 'wp_insert_post');
  74. }
  75. add_action( 'pre_get_posts', 'video_process_form' );
clone this paste RAW Paste Data