array( 'title' => 'Link post format', 'applicableto' => 'post', 'location' => 'normal', 'display_condition' => 'post-format-link', 'priority' => 'high', 'fields' => array( 'title_link' => array( 'title' => 'Link', 'type' => 'text', 'description' => '' ) ) ), 'quote_post_format' => array( 'title' => 'Quote post format', 'applicableto' => 'post', 'location' => 'normal', 'display_condition' => 'post-format-quote', 'priority' => 'high', 'fields' => array( 'quote_format' => array( 'title' => 'Quote', 'type' => 'text', 'description' => '' ) ) ), 'video_post_format' => array( 'title' => 'Video post format', 'applicableto' => 'post', 'location' => 'normal', 'display_condition' => 'post-format-video', 'priority' => 'high', 'fields' => array( 'video_format_choose' => array( 'title' => 'Choose Video Type', 'type' => 'selectbox', 'description' => '', 'values' => array( 'youtube' => 'Youtube', 'vimeo' => 'Vimeo', 'self' => 'Self Hosted', ) ), 'video_format_link' => array( 'title' => 'Video ID', 'type' => 'text', 'description' => '' ), 'video_format_image' => array( 'title' => 'Video image', 'type' => 'image', 'description' => '' ), 'video_format_webm' => array( 'title' => 'Video webm', 'type' => 'text', 'description' => '' ), 'video_format_mp4' => array( 'title' => 'Video mp4', 'type' => 'text', 'description' => '' ), 'video_format_ogv' => array( 'title' => 'Video ogv', 'type' => 'text', 'description' => '' ) ) ), 'audio_post_format' => array( 'title' => 'Audio post format', 'applicableto' => 'post', 'location' => 'normal', 'display_condition' => 'post-format-audio', 'priority' => 'high', 'fields' => array( 'audio_link' => array( 'title' => 'Audio Link', 'type' => 'text', 'description' => '' ) ) ), 'gallery_post_format' => array( 'title' => 'Gallery post format', 'applicableto' => 'post', 'location' => 'normal', 'display_condition' => 'post-format-gallery', 'priority' => 'high', 'fields' => array( 'gallery_type' => array( 'title' => 'Gallery Type', 'type' => 'selectbox', 'values' => array( 'slider' => 'Slider', 'masonry' => 'Masonry' ), 'description' => 'Choose gallery typr for Blog Compound list' ), ) ) ); function add_metaboxes() { global $metaboxes; if ( ! empty( $metaboxes ) ) { foreach ( $metaboxes as $id => $metabox ) { add_meta_box( $id, $metabox['title'], 'show_metaboxes', $metabox['applicableto'], $metabox['location'], $metabox['priority'], $id ); } } } // show meta boxes function show_metaboxes( $post, $args ) { global $metaboxes; $custom = get_post_custom( $post->ID ); $fields = $metaboxes[$args['id']]['fields']; /** Nonce **/ $output = ''; if ( sizeof( $fields ) ) { foreach ( $fields as $id => $field ) { if(isset($custom[$id][0]) && $custom[$id][0] != ""){ $value = $custom[$id][0]; }else{ $value = ""; } $output .= '
'; $output .= '
'; $output .= '
'; switch ( $field['type'] ) { default: case "text": $output .= '
'; break; case "image": $output .= '
'; break; case "selectbox": $output .= '
'; break; } $output .= '
'; } } echo $output; } function save_metaboxes( $post_id ) { global $metaboxes; if(isset($_POST['post_format_meta_box_nonce'])){ $nonce = $_POST['post_format_meta_box_nonce']; } else { $nonce = wp_create_nonce( 'post_format_meta_box_nonce' ); } // verify nonce if ( !wp_verify_nonce( $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; } $post_type = get_post_type(); // loop through fields and save the data foreach ( $metaboxes as $id => $metabox ) { // check if metabox is applicable for current post type if ( $metabox['applicableto'] == $post_type ) { $fields = $metaboxes[$id]['fields']; foreach ( $fields as $id => $field ) { $old = get_post_meta( $post_id, $id, true ); $new = $_POST[$id]; if ( $new && $new != $old ) { update_post_meta( $post_id, $id, $new ); } elseif ( '' == $new && $old || ! isset( $_POST[$id] ) ) { delete_post_meta( $post_id, $id, $old ); } } } } } add_action( 'admin_print_scripts', 'display_metaboxes', 1000 ); function display_metaboxes() { global $metaboxes; if ( get_post_type() == "post" ) : ?>