Advertisement
keihead

Videos CPT

Jun 30th, 2013
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.69 KB | None | 0 0
  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.         'menu_icon' => get_bloginfo('template_directory').'/images/calendar-icon.png',
  31.         'menu_position' => 15,
  32.         'hierarchical' => false,
  33.         'menu_position' => null,
  34.         'supports' => array('title', 'thumbnail')
  35.       );
  36.  
  37.     register_post_type( 'videos' , $args );
  38. }
  39.  
  40.  
  41. add_action("admin_init", "videos_admin_init");
  42.  
  43. function videos_admin_init(){
  44.   add_meta_box("video_meta", "Video Details", "video_details_meta", "videos", "high", "default");
  45. }
  46.  
  47. function video_details_meta() {
  48.     $ret = $ret . '<p><label>Video ID: </label><input type="text" size="10" name="videoid" value="' . get_video_field("videoid") . '" /></p>';
  49.     $ret .= '<p><label class="videos">Videio Site: </label>';
  50.     $ret .= '<select type="select" id="videosite" name="videosite">';
  51.     $ret .= '<option value="youtube">youtube</option>';
  52.     $ret .= '<option value="vimeo">vimeo</option>';
  53.     $ret .= '</select>';
  54.     $ret .= '<script>jQuery(document).ready(function(){ jQuery("#videosite").val(' . get_video_field("videosite") . ') });</script>';
  55.  
  56.     echo $ret;
  57. }
  58.  
  59. function get_video_field($video_field) {
  60.     global $post;
  61.  
  62.     $custom = get_post_custom($post->ID);
  63.  
  64.     if (isset($custom[$video_field])) {
  65.         return $custom[$video_field][0];
  66.     }
  67. }
  68. add_action('save_post', 'save_video_details');
  69.  
  70. function save_video_details(){
  71.    global $post;
  72.  
  73.    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
  74.       return;
  75.  
  76.    if ( get_post_type($post) != 'videos')
  77.       return;
  78.            
  79.     save_video_field("videoid");
  80.     save_video_field("videosite");
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement