sparkweb

Add Your Own Metabox To Product Screen

Sep 4th, 2011
154
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Add Author Meta Boxes to Products
  2. add_action('admin_init','foxyshop_author_details_init');
  3. function foxyshop_author_details_init() {
  4.     add_meta_box('foxyshop_author_details_meta', 'Extra Product Details', 'foxyshop_author_details_meta', 'foxyshop_product', 'normal', 'high');
  5.     add_action('foxyshop_save_product','foxyshop_author_details_meta_save');
  6. }
  7.  
  8. function foxyshop_author_details_meta() {
  9.     global $post;
  10.     ?>
  11.     <div class="foxyshop_field_control">
  12.         <label for="_author"><?php _e('Author'); ?></label>
  13.         <input type="text" name="_author" id="_author" value="<?php echo htmlspecialchars(get_post_meta($post->ID,'_author',TRUE)); ?>" style="width: 400px;" />
  14.     </div>
  15.  
  16.     <div class="foxyshop_field_control">
  17.         <label for="_illustrator"><?php _e('Illustrator'); ?></label>
  18.         <input type="text" name="_illustrator" id="_illustrator" value="<?php echo htmlspecialchars(get_post_meta($post->ID,'_illustrator',TRUE)); ?>" style="width: 400px;" />
  19.     </div>
  20.  
  21.     <div class="foxyshop_field_control">
  22.         <label for="_translator"><?php _e('Translator'); ?></label>
  23.         <input type="text" name="_translator" id="_translator" value="<?php echo htmlspecialchars(get_post_meta($post->ID,'_translator',TRUE)); ?>" style="width: 400px;" />
  24.     </div>
  25.  
  26.     <div class="foxyshop_field_control">
  27.         <label for="_isbn"><?php _e('ISBN'); ?></label>
  28.         <input type="text" name="_isbn" id="_isbn" value="<?php echo htmlspecialchars(get_post_meta($post->ID,'_isbn',TRUE)); ?>" style="width: 400px;" />
  29.     </div>
  30.  
  31.     <div class="foxyshop_field_control">
  32.         <label for="_ebook_link"><?php _e('E-book Link'); ?></label>
  33.         <input type="text" name="_ebook_link" id="_ebook_link" value="<?php echo htmlspecialchars(get_post_meta($post->ID,'_ebook_link',TRUE)); ?>" style="width: 400px;" />
  34.     </div>
  35.  
  36.     <div class="foxyshop_field_control">
  37.         <label for="_kindle_link"><?php _e('Kindle Link'); ?></label>
  38.         <input type="text" name="_kindle_link" id="_kindle_link" value="<?php echo htmlspecialchars(get_post_meta($post->ID,'_kindle_link',TRUE)); ?>" style="width: 400px;" />
  39.     </div>
  40.  
  41.     <div class="foxyshop_field_control">
  42.         <label for="_ibooks_link"><?php _e('iBooks Link'); ?></label>
  43.         <input type="text" name="_ibooks_link" id="_ibooks_link" value="<?php echo htmlspecialchars(get_post_meta($post->ID,'_ibooks_link',TRUE)); ?>" style="width: 400px;" />
  44.     </div>
  45.  
  46.     <div class="foxyshop_field_control">
  47.         <label for="_nook_link"><?php _e('Nook Link'); ?></label>
  48.         <input type="text" name="_nook_link" id="_nook_link" value="<?php echo htmlspecialchars(get_post_meta($post->ID,'_nook_link',TRUE)); ?>" style="width: 400px;" />
  49.     </div>
  50.  
  51.  
  52.     <?php
  53. }
  54.  
  55. function foxyshop_author_details_meta_save($post_id) {
  56.     global $post_id;
  57.     foxyshop_save_meta_data('_author',$_POST['_author']);
  58.     foxyshop_save_meta_data('_illustrator',$_POST['_illustrator']);
  59.     foxyshop_save_meta_data('_translator',$_POST['_translator']);
  60.     foxyshop_save_meta_data('_isbn',$_POST['_isbn']);
  61.     foxyshop_save_meta_data('_ebook_link',$_POST['_ebook_link']);
  62.     foxyshop_save_meta_data('_kindle_link',$_POST['_kindle_link']);
  63.     foxyshop_save_meta_data('_ibooks_link',$_POST['_ibooks_link']);
  64.     foxyshop_save_meta_data('_nook_link',$_POST['_nook_link']);
  65.     return $post_id;
  66. }
RAW Paste Data