Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: PHP  |  size: 2.48 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. /*
  4. * @package Eddie2
  5. * @subpackage Displays two meta boxes (book meta data & book->sections structure on the edit book page)
  6. * @author dev@libris.dk
  7.  */
  8.  
  9.  
  10.  
  11.  
  12. /*
  13.  * SCOPE: /post.php?post=9999&action=edit
  14.  */
  15.  
  16.  
  17.    
  18.  
  19.  
  20. // Add the custom functions to wp hooks
  21. add_action( 'add_meta_boxes', 'eddie_book_add_custom_boxes' );
  22. add_action( 'save_post', 'eddie_book_save_postdata' );
  23.  
  24.  
  25. // Adds boxes on the Book-Edit page
  26. function eddie_book_add_custom_boxes() {
  27.        
  28.    
  29.     //Display all sections for a selected book -begin
  30.         include 'eddie2_getBookStructure.php';
  31.     //Display all sections for a selected book -end
  32.  
  33.     add_meta_box(
  34.         'eddie_book_meta_data_id',
  35.         'Book meta data',
  36.         'eddie_book_meta_data_box',
  37.         'book',
  38.         'normal',
  39.         'high'
  40.     );
  41.  
  42.     add_meta_box(
  43.         'eddie_book_structure_box_id',
  44.         'Book structure',
  45.         'eddie_book_structure_box',
  46.         'book',
  47.         'normal',
  48.         'high'
  49.     );
  50.  
  51. }
  52.  
  53.    
  54. // Construct Book meta data box
  55. function eddie_book_meta_data_box() {
  56.  
  57.     global $post;
  58.  
  59.     // Use nonce for verification
  60.     wp_nonce_field( 'eddie_save_book_meta', 'eddie_book_meta_noncename' );
  61.  
  62.     // The actual fields for data entry
  63.  
  64.     echo '<label for="isbn">ISBN nr.</label> ';
  65.     $isbn = get_post_meta( $post->ID, 'isbn', true );
  66.     echo '<input type="text" id="isbn" name="isbn" value="' . $isbn . '" size="25" />';
  67. }
  68.  
  69. // When the post is saved, saves our custom data
  70. function eddie_book_save_postdata( $post_id ) {
  71.  
  72.     // verify if this is an auto save routine.
  73.     // If it is our form has not been submitted, so we dont want to do anything
  74.     if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
  75.         return;
  76.  
  77.     // verify this came from the our screen and with proper authorization,
  78.     // because save_post can be triggered at other times
  79.     if ( !wp_verify_nonce( $_POST['eddie_book_meta_noncename'], 'eddie_save_book_meta' ) )
  80.         return;
  81.  
  82.     // Check permissions
  83.     if ( !current_user_can( 'edit_post', $post_id ) )
  84.         return;
  85.  
  86.     // OK, we're authenticated: we need to find and save the data
  87.     $isbn = $_POST['isbn'];
  88.    
  89.  
  90.     add_post_meta( $post_id, 'isbn', $isbn, true ) or update_post_meta( $post_id, 'isbn', $isbn );
  91.    
  92.     $sections_array = getSections();
  93.     add_post_meta( $post_id, 'menu_order', $sections_array, true ) or update_post_meta( $post_id, 'menu_order', $sections_array );
  94.    
  95.    
  96. }
  97.  
  98. ?>