Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('add_meta_boxes', 'mycpt_meta_boxes');
- function mycpt_meta_boxes()
- {
- add_meta_box( 'cpt_metabox-1', __( 'Extra fields' ), 'mycpt_meta_box_content', 'post', 'normal', 'high');
- }
- // }}}
- // {{{
- function mycpt_meta_box_content()
- {
- global $post;
- include 'form.php';
- wp_nonce_field('mycpt_save', 'mycpt_nonce');
- }
- add_action('save_post', 'mycpt_save_postdata', 10, 2);
- function mycpt_save_postdata( $post_id )
- {
- global $wpdb;
- if ( !wp_verify_nonce( $_POST['mycpt_nonce'], 'mycpt_save' ) ) {
- return $post_id;
- }
- if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
- return $post_id;
- }
- // Check permissions ....
- /*
- * Videos names/titles
- */
- $videos_titulos = $_POST['video_title'];
- // First is empty
- array_shift($videos_titulos);
- /*
- * Video URLs
- */
- $videos_urls = $_POST['video_url'];
- // first is empty
- array_shift($videos_urls);
- // How many ?
- $videos_count = sizeof($videos_titulos);
- $videos = array();
- $content = '';
- for ($i = 0; $i <= $videos_count; $i++) {
- $title = $videos_titulos[$i];
- $url = $videos_urls[$i];
- // check if empty
- if (!empty($title) && !empty($url)) {
- $videos[] = array(
- 'title' => $title,
- 'url' => $url,
- 'image' => get_youtube_video_thumb($url)
- );
- }
- }
- // Serializamos videos en caso que existan, si no, eliminar el post meta
- if ( sizeof($videos) > 0 ) {
- $content = serialize($videos);
- }
- update_post_meta($post_id, 'videos', $content);
- }
- /**
- *
- *
- */
- function get_youtube_video_thumb($video_url)
- {
- $thumb = '';
- $myurl = parse_url($video_url);
- parse_str($myurl['query'], $myquery);
- $video = trim($myquery['v']);
- if ( !empty($video) && strlen($video) > 3 ) {
- $thumb = 'http://img.youtube.com/vi/' . $video . '/default.jpg';
- }
- return $thumb;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement