<?php/*----------------------------------------------------------------------------------- Add Post Format meta boxes-----------------------------------------------------------------------------------*//*-----------------------------------------------------------------------------------*//* Define Metabox Fields/*-----------------------------------------------------------------------------------*/$prefix = 'tj_';$meta_box_video = array( 'id' => 'tj-meta-box-video', 'title' => __('Video Settings', 'themejunkie'), 'page' => 'post', 'context' => 'normal', 'priority' => 'high', 'fields' => array( array( "name" => __('Video Embed Code','themejunkie'), "desc" => __('Here you could enter the video embed code.','themejunkie'), "id" => $prefix."video_embed", "type" => "textarea" ), array( "name" => __('Video Thumbnail URL','themejunkie'), "desc" => __('Specify an image here or set Featured Image as the video thumbnail. (best size: 216px x 120px)','themejunkie'), "id" => $prefix."video_img_url", "type" => "text", ) ));add_action('admin_menu', 'tj_add_box');/*-----------------------------------------------------------------------------------*//* Add metabox to edit page/*-----------------------------------------------------------------------------------*/function tj_add_box() { global $meta_box_video; add_meta_box($meta_box_video['id'], $meta_box_video['title'], 'tj_show_box_video', $meta_box_video['page'], $meta_box_video['context'], $meta_box_video['priority']);}function tj_show_box_video() { global $meta_box_video, $post; echo '<p style="padding:10px 0 0 0;">'.__('You could fill the video details below.', 'themejunkie').'</p>'; // Use nonce for verification echo '<input type="hidden" name="tj_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />'; echo '<table class="form-table">'; foreach ($meta_box_video['fields'] as $field) { // get current post meta data $meta = get_post_meta($post->ID, $field['id'], true); switch ($field['type']) { //If Text case 'text': echo '<tr>', '<th style="width:25%"><label for="', $field['id'], '"><strong>', $field['name'], '</strong><span style=" display:block; color:#999; margin:5px 0 0 0; line-height: 18px;">'. $field['desc'].'</span></label></th>', '<td>'; echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : stripslashes(htmlspecialchars(( $field['std']), ENT_QUOTES)), '" size="30" style="width:75%; margin-right: 20px; float:left;" />'; break; //If textarea case 'textarea': echo '<tr style="border-top:1px solid #eeeeee;">', '<th style="width:25%"><label for="', $field['id'], '"><strong>', $field['name'], '</strong><span style="line-height:18px; display:block; color:#999; margin:5px 0 0 0;">'. $field['desc'].'</span></label></th>', '<td>'; echo '<textarea name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : stripslashes(htmlspecialchars(( $field['std']), ENT_QUOTES)), '" rows="8" cols="5" style="width:100%; margin-right: 20px; float:left;">', $meta ? $meta : stripslashes(htmlspecialchars(( $field['std']), ENT_QUOTES)), '</textarea>'; break; //If Button case 'button': echo '<input style="float: left;" type="button" class="button" name="', $field['id'], '" id="', $field['id'], '"value="', $meta ? $meta : $field['std'], '" />'; echo '</td>', '</tr>'; break; } } echo '</table>';}add_action('save_post', 'tj_save_data');/*-- Save data when post is edited --*/function tj_save_data($post_id) { global $meta_box_video; // verify nonce if (!wp_verify_nonce($_POST['tj_meta_box_nonce'], basename(__FILE__))) { return $post_id; } // check autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // check permissions if ('page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } elseif (!current_user_can('edit_post', $post_id)) { return $post_id; } foreach ($meta_box_video['fields'] as $field) { $old = get_post_meta($post_id, $field['id'], true); $new = $_POST[$field['id']]; if ($new && $new != $old) { update_post_meta($post_id, $field['id'], stripslashes(htmlspecialchars($new))); } elseif ('' == $new && $old) { delete_post_meta($post_id, $field['id'], $old); } }}