$portfolio_excerpt_1_metabox = array( 'id' => 'portfolio-excerpt', 'title' => 'portfolio-excerpt', 'page' => array('portfolio'), 'context' => 'advanced', 'priority' => 'high', 'fields' => array( array( 'name' => 'Portfolio Excerpt', 'desc' => 'This is the excerpt that will display in Main portfolio sortable archive under the image', 'id' => 'nick_prtf_excerpt', 'class' => 'nick_prtf_excerpt', 'type' => 'textarea', 'rich_editor' => 0, 'max' => 0 ), ) ); add_action('admin_menu', 'nick_add_portfolio_excerpt_1_meta_box'); function nick_add_portfolio_excerpt_1_meta_box() { global $portfolio_excerpt_1_metabox; foreach($portfolio_excerpt_1_metabox['page'] as $page) { add_meta_box($portfolio_excerpt_1_metabox['id'], $portfolio_excerpt_1_metabox['title'], 'nick_show_portfolio_excerpt_1_box', $page, 'advanced', 'high', $portfolio_excerpt_1_metabox); } } // function to show meta boxes function nick_show_portfolio_excerpt_1_box() { global $post; global $portfolio_excerpt_1_metabox; global $nick_prefix; global $wp_version; // Use nonce for verification echo ''; echo ''; foreach ($portfolio_excerpt_1_metabox['fields'] as $field) { // get current post meta data $meta = get_post_meta($post->ID, $field['id'], true); echo '', '', ''; } echo '
'; switch ($field['type']) { case 'text': echo '
', '', stripslashes($field['desc']); break; case 'date': if($meta) { $value = nick_timestamp_to_date($meta); } else { $value = ''; } echo '' . '' . stripslashes($field['desc']); break; case 'upload': echo '
', '', stripslashes($field['desc']); break; case 'textarea': if($field['rich_editor'] == 1) { if($wp_version >= 3.3) { echo wp_editor($meta, $field['id'], array('textarea_name' => $field['id'])); } else { // older versions of WP $editor = ''; if(!post_type_supports($post->post_type, 'editor')) { $editor = wp_tiny_mce(true, array('editor_selector' => $field['class'], 'remove_linebreaks' => false) ); } $field_html = '

' . __(stripslashes($field['desc'])); echo $editor . $field_html; } } else { echo '
', '', stripslashes($field['desc']); } break; case 'select': echo '', '', stripslashes($field['desc']); break; case 'radio': foreach ($field['options'] as $option) { echo ' ', $option; } echo '
' . stripslashes($field['desc']); break; case 'multicheck': foreach ($field['options'] as $option) { echo ' ' . $option; } echo '
' . stripslashes($field['desc']); break; case 'checkbox': echo ' '; echo stripslashes($field['desc']); break; case 'slider': echo ''; echo '
'; echo '
' . stripslashes($field['desc']) . '
'; break; case 'repeatable' : $field_html = ''; if(is_array($meta)) { $count = 1; foreach($meta as $key => $value) { $field_html .= '
'; if($count > 1) { $field_html .= 'x
'; } $field_html .= '
'; $count++; } } else { $field_html .= '
'; } $field_html .= ' ' . __(stripslashes($field['desc'])); echo $field_html; break; case 'repeatable upload' : $field_html = ''; if(is_array($meta)) { $count = 1; foreach($meta as $key => $value) { $field_html .= '
'; if($count > 1) { $field_html .= 'x
'; } $field_html .= '
'; $count++; } } else { $field_html .= '
'; } $field_html .= ' ' . __(stripslashes($field['desc'])); echo $field_html; break; } echo '
', '
'; } // Save data from meta box add_action('save_post', 'nick_portfolio_excerpt_1_save'); function nick_portfolio_excerpt_1_save($post_id) { global $post; global $portfolio_excerpt_1_metabox; // verify nonce if (!wp_verify_nonce($_POST['nick_portfolio_excerpt_1_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 ($portfolio_excerpt_1_metabox['fields'] as $field) { $old = get_post_meta($post_id, $field['id'], true); $new = $_POST[$field['id']]; if ($new && $new != $old) { if($field['type'] == 'date') { $new = nick_format_date($new); update_post_meta($post_id, $field['id'], $new); } else { if(is_string($new)) { $new = $new; } update_post_meta($post_id, $field['id'], $new); } } elseif ('' == $new && $old) { delete_post_meta($post_id, $field['id'], $old); } } } function nick_export_ui_scripts() { global $nick_options; ?>