Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*========================================
- VIDEOS
- ========================================== */
- add_action('init', 'video_register');
- function video_register() {
- $labels = array(
- 'name' => _x('Videos', 'post type general name'),
- 'singular_name' => _x('Video', 'post type singular name'),
- 'add_new' => _x('Add New', 'video'),
- 'add_new_item' => __('Add New video'),
- 'edit_item' => __('Edit Video'),
- 'new_item' => __('New Video'),
- 'view_item' => __('View Video'),
- 'search_items' => __('Search Videos'),
- 'not_found' => __('Nothing found'),
- 'not_found_in_trash' => __('Nothing found in Trash'),
- 'parent_item_colon' => ''
- );
- $args = array(
- 'labels' => $labels,
- 'public' => true,
- 'publicly_queryable' => true,
- 'show_ui' => true,
- 'query_var' => true,
- 'rewrite' => true,
- 'capability_type' => 'post',
- 'menu_icon' => get_bloginfo('template_directory').'/images/calendar-icon.png',
- 'menu_position' => 15,
- 'hierarchical' => false,
- 'menu_position' => null,
- 'supports' => array('title', 'thumbnail')
- );
- register_post_type( 'videos' , $args );
- }
- add_action("admin_init", "videos_admin_init");
- function videos_admin_init(){
- add_meta_box("video_meta", "Video Details", "video_details_meta", "videos", "high", "default");
- }
- function video_details_meta() {
- $ret = $ret . '<p><label>Video ID: </label><input type="text" size="10" name="videoid" value="' . get_video_field("videoid") . '" /></p>';
- $ret .= '<p><label class="videos">Video Site: </label>';
- $ret .= '<select type="select" id="videosite" name="videosite">';
- $ret .= '<option value="youtube">youtube</option>';
- $ret .= '<option value="vimeo">vimeo</option>';
- $ret .= '</select>';
- $ret .= '<script>jQuery(document).ready(function(){ jQuery("#videosite").val(' . get_video_field("videosite") . ') });</script>';
- echo $ret;
- }
- function get_video_field($video_field) {
- global $post;
- $custom = get_post_custom($post->ID);
- if (isset($custom[$video_field])) {
- return $custom[$video_field][0];
- }
- }
- add_action('save_post', 'save_video_details');
- function save_video_details(){
- global $post;
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
- return;
- if ( get_post_type($post) != 'videos')
- return;
- save_video_field("videoid");
- save_video_field("videosite");
- }
- function save_video_field($video_field) {
- global $post;
- if(isset($_POST[$video_field])) {
- update_post_meta($post->ID, $video_field, $_POST[$video_field]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement