Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php function post_save_details(){
- global $post;
- if ( ! wp_verify_nonce( $_POST['recipes_subtitle'], 'recipes_subtitle', 'recipes_subtitle' ) )
- return;
- $ingredients = array();
- for ( $i = 0, $j = min( count( $_POST['recipe_ingredients']), count( $_POST['recipe_qty'] ) ); $i < $j; $i++ ) {
- if ( empty( $_POST['recipe_ingredients'] ) )
- continue;
- $ingredients[] = array( $_POST['recipe_ingredients'][ $i ], $_POST['recipe_qty'][ $i ] );
- }
- update_post_meta( $post->ID, '_recipe_ingredients', $ingredients );
- update_post_meta($post->ID, "sub", $_POST["sub"]);
- update_post_meta($post->ID, "notes", $_POST["notes"]);
- update_post_meta($post->ID, "directions", $_POST["directions"]);
- update_post_meta($post->ID, "serving", $_POST["serving"]);
- }
- function recipe_admin_init(){
- add_meta_box("sub-meta", "Sub Title", "recipe_sub", "post", "side", "high");
- add_meta_box("notes_meta", "Notes and Directions", "recipe_notesandmethods_meta", "post", "normal", "high");
- add_meta_box("recipe_meta", "Ingredients And Qty.", "recipe_ingqty_meta", "post", "normal", "high");
- add_action( 'admin_footer-post.php', 'recipe_post_scripts' );
- add_action( 'admin_footer-post-new.php', 'recipe_post_scripts' );
- }
- function recipe_sub(){
- global $post;
- $custom = get_post_custom($post->ID);
- $sub = $custom["sub"][0];
- wp_nonce_field( 'recipes_subtitle', 'recipes_subtitle' );
- ?>
- <label>Sub Title: </label>
- <input type="text" name="sub" value="<?php echo $sub; ?>" />
- <?php
- }
- function recipe_notesandmethods_meta() {
- global $post;
- $custom = get_post_custom($post->ID);
- $notes = $custom["notes"][0];
- $serving = $custom["serving"][0];
- $directions = $custom["directions"][0];
- ?>
- <table>
- <tr>
- <td style="vertical-align: top;"><label>Notes: </label></td>
- <td><textarea cols="50" rows="10" type="text" name="notes"><?php echo $notes;?></textarea></td>
- </tr>
- <tr>
- <td style="vertical-align: top;"><label>Serving size: </label></td>
- <td><input type="text" name="serving" value="<?php echo $serving; ?>" /></td>
- </tr>
- <tr>
- <td style="vertical-align: top;"><label>Method: </label></td>
- <td><textarea cols="50" rows="10" type="text" name="directions"><?php echo $directions;?></textarea></td>
- </tr>
- </table>
- <?php
- }
- function recipe_ingqty_meta() {
- global $post;
- $ingredients = get_post_meta( $post->ID, '_recipe_ingredients', true );
- echo '<div id="recipe_ingredients">';
- foreach ( $ingredients as $ingredient ) {
- echo '<p><label>Ingredient: <input name="recipe_ingredients[]" type="text" value="' . esc_attr( $ingredient[ 0 ] ) . '" /></label>';
- echo ' <label>Qty: <input name="recipe_qty[]" type="text" value="' . esc_attr( $ingredient[ 1 ] ) . '" /></label> <a href="#" class="remove button">Remove</a></p>';
- }
- echo '</div><p><a href="#" class="button-primary" id="recipe_new_ingredient">New ingredient</a></p>';
- }
- function recipe_post_scripts() {
- if ( $GLOBALS['post_type'] != 'post' )
- return;
- $js = <<<JS
- <script type="text/javascript">
- jQuery(document).ready( function($) {
- $('#recipe_new_ingredient').click( function() {
- $('#recipe_ingredients').append( '<p><label>Ingredient: <input name="recipe_ingredients[]" type="text" /></label> <label>Qty: <input name="recipe_qty[]" type="text" /></label> <a href="#" class="remove button">Remove</a></p>' );
- return false;
- });
- $('#recipe_ingredients .remove').live('click', function() {
- $(this).parent().remove();
- return false;
- });
- });
- </script>
- JS;
- echo $js;
- }
- add_action( 'admin_init', 'add_recipe_ingqty_meta_box' );
- function add_recipe_ingqty_meta_box() {
- add_meta_box( 'recipe_meta', 'Ingredients And Qty.', 'recipeingqty_meta', 'post', 'normal', 'high' );
- add_action( 'admin_footer-post.php', 'recipe_post_scripts' );
- add_action( 'admin_footer-post-new.php', 'recipe_post_scripts' );
- }
- add_action("admin_init", "recipe_admin_init");
- add_action('save_post', 'post_save_details');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement