Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $portfolioextrafields_1_metabox = array(
- 'id' => 'portfolioextrafields',
- 'title' => 'Portfolio Extra Fields',
- 'page' => array('portfolio'),
- 'context' => 'normal',
- 'priority' => 'high',
- 'fields' => array(
- array(
- 'name' => 'Employee Name',
- 'desc' => 'Enter the name of the employee',
- 'id' => 'nick_empname',
- 'class' => 'nick_empname',
- 'type' => 'text',
- 'rich_editor' => 0,
- 'max' => 0 ),
- array(
- 'name' => 'Employee Lines',
- 'desc' => 'Enter the lines separated by <br/>',
- 'id' => 'nick_empline',
- 'class' => 'nick_empline',
- 'type' => 'text',
- 'rich_editor' => 0,
- 'max' => 0 ),
- )
- );
- add_action('admin_menu', 'nick_add_portfolioextrafields_1_meta_box');
- function nick_add_portfolioextrafields_1_meta_box() {
- global $portfolioextrafields_1_metabox;
- foreach($portfolioextrafields_1_metabox['page'] as $page) {
- add_meta_box($portfolioextrafields_1_metabox['id'], $portfolioextrafields_1_metabox['title'], 'nick_show_portfolioextrafields_1_box', $page, 'normal', 'high', $portfolioextrafields_1_metabox);
- }
- }
- // function to show meta boxes
- function nick_show_portfolioextrafields_1_box() {
- global $post;
- global $portfolioextrafields_1_metabox;
- global $nick_prefix;
- global $wp_version;
- // Use nonce for verification
- echo '<input type="hidden" name="nick_portfolioextrafields_1_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';
- echo '<table class="form-table">';
- foreach ($portfolioextrafields_1_metabox['fields'] as $field) {
- // get current post meta data
- $meta = get_post_meta($post->ID, $field['id'], true);
- echo '<tr>',
- '<th style="width:20%"><label for="', $field['id'], '">', stripslashes($field['name']), '</label></th>',
- '<td class="nick_field_type_' . str_replace(' ', '_', $field['type']) . '">';
- switch ($field['type']) {
- case 'text':
- if (!isset($field['std'])) {$ttemp_string = "";} else {$ttemp_string = $field['std'];}
- echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $ttemp_string, '" size="30" style="width:97%" /><br/>', '', stripslashes($field['desc']);
- break;
- }
- echo '<td>',
- '</tr>';
- }
- echo '</table>';
- }
- // Save data from meta box
- add_action('save_post', 'nick_portfolioextrafields_1_save');
- function nick_portfolioextrafields_1_save($post_id) {
- global $post;
- global $portfolioextrafields_1_metabox;
- // verify nonce
- if ( ! isset( $_POST['nick_portfolioextrafields_1_meta_box_nonce'] ) || ! wp_verify_nonce($_POST['nick_portfolioextrafields_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 ($portfolioextrafields_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, $post;
- ?>
- <script type="text/javascript">
- jQuery(document).ready(function($)
- {
- // add new repeatable field
- $(".nick_add_new_field").on('click', function() {
- var field = $(this).closest('td').find("div.nick_repeatable_wrapper:last").clone(true);
- var fieldLocation = $(this).closest('td').find('div.nick_repeatable_wrapper:last');
- // set the new field val to blank
- $('input', field).val("");
- field.insertAfter(fieldLocation, $(this).closest('td'));
- return false;
- });
- // remove repeatable field
- $('.nick_remove_repeatable').on('click', function(e) {
- e.preventDefault();
- var field = $(this).parent();
- $('input', field).val("");
- field.remove();
- return false;
- });
- });
- </script>
- <?php
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement