This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Sep 21st, 2012  |  syntax: None  |  size: 2.65 KB  |  views: 20  |  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.               $headers = get_headers('http://gdata.youtube.com/feeds/api/videos/' . $video_id);
  32.               if (strpos($headers[0], '200')) {
  33.                   $video_url = $vid_url;
  34.               } else {
  35.                   $output .= 'This is not an existing youtube video<br/>';
  36.               }
  37.             } else {
  38.               $output .= 'This is not an existing youtube video<br/>';
  39.             }
  40.         } else {
  41.               $output .= 'This is not an existing youtube video<br/>';
  42.         }
  43.         $tags = $_POST['post_tags'];
  44.  
  45.         // Add the content of the form to $post as an array
  46.         $new_post = array(
  47.             'post_title'    => $title,
  48.             'post_content'  => $description,
  49.             'tags_input'    => array($tags),
  50.             'post_category' => array(12),
  51.             'post_status'   => 'publish',           // Choose: publish, preview, future, draft, etc.
  52.             'post_type' => fod_videos  // Use a custom post type if you want to
  53.         );
  54.  
  55.         // If No Errors, Save Post and Redirect //
  56.         if ($output == null) {
  57.             $pid = wp_insert_post($new_post);
  58.             update_post_meta($pid,'video_code',$video_url);
  59.             wp_redirect( get_permalink($pid));
  60.         // If Errors, Return Errors for Display in Template //
  61.         } else {
  62.             echo $output;
  63.         }
  64.     }
  65.     do_action('wp_insert_post', 'wp_insert_post');
  66. }
  67. add_action( 'pre_get_posts', 'video_process_form' );
clone this paste RAW Paste Data