SHARE
TWEET

VCPT1

keihead Jul 3rd, 2013 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*========================================
  2.                                    VIDEOS
  3. ========================================== */
  4.  
  5. add_action('init', 'video_register');
  6. function video_register() {
  7.  
  8.     $labels = array(
  9.         'name' => _x('videos', 'post type general name'),
  10.         'singular_name' => _x('video', 'post type singular name'),
  11.         'add_new' => _x('Add New', 'video'),
  12.         'add_new_item' => __('Add New video'),
  13.         'edit_item' => __('Edit video'),
  14.         'new_item' => __('New video'),
  15.         'view_item' => __('View video'),
  16.         'search_items' => __('Search videos'),
  17.         'not_found' =>  __('Nothing found'),
  18.         'not_found_in_trash' => __('Nothing found in Trash'),
  19.         'parent_item_colon' => ''
  20.     );
  21.  
  22.     $args = array(
  23.         'labels' => $labels,
  24.         'public' => true,
  25.         'publicly_queryable' => true,
  26.         'show_ui' => true,
  27.         'query_var' => true,
  28.         'rewrite' => true,
  29.         'capability_type' => 'post',
  30.         'hierarchical' => false,
  31.         'menu_position' => 5,
  32.         'supports' => array('title', 'thumbnail')
  33.       );
  34.  
  35.     register_post_type( 'videos' , $args );
  36. }
  37.  
  38. add_action("admin_init", "videos_admin_init");
  39.  
  40. function videos_admin_init(){
  41.   add_meta_box("video_meta", "video Details", "video_details_meta", "videos", "normal", "default");
  42. }
  43.  
  44. function video_details_meta() {
  45.     $ret = $ret . '<div class="videos-meta"><p><label class="videos">Video ID: </label><input type="text" size="10" name="videoid" value="' . get_video_field("videoid") . '" /></p>';
  46.         $ret .= '<p><label>Status: </label>';
  47.         $ret .= '<select id="videotype" name="videotype">';
  48.         $ret .= '<option value="">Select</option>';
  49.         $ret .= '<option value="youtube">Youtube</option>';
  50.         $ret .= '<option value="vimeo">Vimeo</option>';
  51.         $ret .= '</select>';
  52.         $ret .= '<script>jQuery(document).ready(function(){ jQuery("#videotype").val(' . get_video_field("videotype") . ') });</script></div>';
  53.  
  54.        
  55.  
  56.     echo $ret;
  57. }
  58. function get_video_field($video_field) {
  59.     global $post;
  60.  
  61.     $custom = get_post_custom($post->ID);
  62.  
  63.     if (isset($custom[$video_field])) {
  64.         return $custom[$video_field][0];
  65.     }
  66. }
  67. add_action('save_post', 'save_video_details');
  68.  
  69. function save_video_details(){
  70.    global $post;
  71.  
  72.    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
  73.       return;
  74.  
  75.    if ( get_post_type($post) != 'videos')
  76.       return;
  77.  
  78.    save_video_field("videoid");
  79.    save_video_field("videotype");
  80.  
  81. }
  82. function save_video_field($video_field) {
  83.     global $post;
  84.  
  85.     if(isset($_POST[$video_field])) {
  86.         update_post_meta($post->ID, $video_field, $_POST[$video_field]);
  87.     }
  88. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top