<?php
/*
* @package Eddie2
* @subpackage Displays two meta boxes (book meta data & book->sections structure on the edit book page)
* @author dev@libris.dk
*/
/*
* SCOPE: /post.php?post=9999&action=edit
*/
// Add the custom functions to wp hooks
add_action( 'add_meta_boxes', 'eddie_book_add_custom_boxes' );
add_action( 'save_post', 'eddie_book_save_postdata' );
// Adds boxes on the Book-Edit page
function eddie_book_add_custom_boxes() {
//Display all sections for a selected book -begin
include 'eddie2_getBookStructure.php';
//Display all sections for a selected book -end
add_meta_box(
'eddie_book_meta_data_id',
'Book meta data',
'eddie_book_meta_data_box',
'book',
'normal',
'high'
);
add_meta_box(
'eddie_book_structure_box_id',
'Book structure',
'eddie_book_structure_box',
'book',
'normal',
'high'
);
}
// Construct Book meta data box
function eddie_book_meta_data_box() {
global $post;
// Use nonce for verification
wp_nonce_field( 'eddie_save_book_meta', 'eddie_book_meta_noncename' );
// The actual fields for data entry
echo '<label for="isbn">ISBN nr.</label> ';
$isbn = get_post_meta( $post->ID, 'isbn', true );
echo '<input type="text" id="isbn" name="isbn" value="' . $isbn . '" size="25" />';
}
// When the post is saved, saves our custom data
function eddie_book_save_postdata( $post_id ) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( !wp_verify_nonce( $_POST['eddie_book_meta_noncename'], 'eddie_save_book_meta' ) )
return;
// Check permissions
if ( !current_user_can( 'edit_post', $post_id ) )
return;
// OK, we're authenticated: we need to find and save the data
$isbn = $_POST['isbn'];
add_post_meta( $post_id, 'isbn', $isbn, true ) or update_post_meta( $post_id, 'isbn', $isbn );
$sections_array = getSections();
add_post_meta( $post_id, 'menu_order', $sections_array, true ) or update_post_meta( $post_id, 'menu_order', $sections_array );
}
?>