Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function menu_item_save_details(){
- global $post;
- $menu_items = array();
- for ( $i = 0, $j = min(
- count( $_POST['menu_item_name']),
- count( $_POST['menu_item_price']),
- count( $_POST['menu_item_description']),
- count( $_POST['menu_item_notes'])
- ); $i < $j; $i++ ) {
- if ( empty( $_POST['menu_item_name'] ) )
- continue;
- $menu_items[] = array(
- $_POST['menu_item_name'][ $i ],
- $_POST['menu_item_price'][ $i ],
- $_POST['menu_item_description'][ $i ],
- $_POST['menu_item_notes'][ $i ]
- );
- }
- update_post_meta( $post->ID, '_menu_items', $menu_items );
- }
- function menu_items_init(){
- add_meta_box("menu_items", "Menu Items", "menu_items_meta", "gavin_landd_menu", "normal", "high");
- add_action( 'admin_footer-post.php', 'menu_items_scripts' );
- add_action( 'admin_footer-post-new.php', 'menu_items_scripts' );
- }
- function menu_items_meta() {
- global $post;
- $menu_items = get_post_meta( $post->ID, '_menu_items', true );
- echo '<div id="menu_item">';
- echo '<table class="form-table">';
- foreach ( $menu_items as $menu_item ) {
- echo '
- <tr>
- <th style="width: 20%;">
- <label>Menu Item Name</label>
- </th>
- <td>
- <input name="menu_item_name[]" type="text" size="30" style="width:300px;" value="' . esc_attr( $menu_item[ 0 ] ) . '" />
- </td>
- </tr>
- <tr>
- <th style="width: 20%;">
- <label>Menu Item Price</label>
- </th>
- <td>
- <input name="menu_item_price[]" type="text" class="code" size="6" style="width: 100px;" value="' . esc_attr( $menu_item[ 1 ] ) . '" /><br/>
- <span class="description">With or without the $</span>
- </td>
- </tr>
- <tr>
- <th style="width: 20%;">
- <label>Menu Item Description</label>
- </th>
- <td>
- <textarea name="menu_item_description[]" type="textarea" cols="80" rows="5">' . esc_attr( $menu_item[ 2 ] ). '</textarea>
- </td>
- </tr>
- <tr>
- <th style="width: 20%;">
- <label>Menu Item Notes</label>
- </th>
- <td>
- <input name="menu_item_notes[]" type="text" size="30" style="width:300px;" value="' . esc_attr( $menu_item[ 3 ] ) .'" /><br/>
- <span class="description">Do you reccommend anything for this item?</span>
- </td>
- </tr>
- <tr>
- <th style="width:20%;"><a href="#" class="remove button">Remove Menu Item</a></th>
- </tr>
- <tr>
- <td colspan="100%"><hr /></th>
- </tr>';
- }
- echo '</table>';
- echo '<table class="form-table"><tbody><tr><th style="width: 100%;"><a href="#" class="button-primary" id="new_menu_item">New Menu Item</a></th></tr></tbody></table>';
- echo '</div>';
- }
- function menu_item_scripts() {
- if ( $GLOBALS['post_type'] != 'gavin_landd_menu' )
- return;
- $js = <<<JS
- <script type="text/javascript">
- jQuery(document).ready( function($) {
- $('#new_menu_item').click( function() {
- $('<table class="form-table"><tr><th style="width: 20%;"><label>Menu Item Name</label></th><td><input name="menu_item_name[]" type="text" style="width: 300px;"/></td></tr><tr><th><label>Menu Item Price</label></th><td><input name="menu_item_price[]" type="text" class="code" length="12" style="width: 100px;"/><br/><span class="description">With or without the $</span></td></tr><tr><th style="width: 20%;"><label>Menu Item Description</label></th><td><textarea name="menu_item_description[]" cols="80" rows="5"></textarea></td></tr><tr><th><label style="width: 20%;">Menu Item Notes</label></th><td><input name="menu_item_notes[]" type="text" style="width: 300px;"/><br/><span class="description">Do you reccommend anything for this item?</span></td></tr><tr><th style="width:20%;"><a href="#" class="remove button">Remove Menu Item</a></th></tr><tr><td colspan="100%"><hr/></td></tr></table>').hide().appendTo('#menu_item').fadeIn(600)
- return false;
- });
- $('#menu_item .remove').live('click', function() {
- $(this).parent().find('#menu_item').fadeOut(600);
- return false;
- });
- });
- </script>
- JS;
- echo $js;
- }
- add_action( 'admin_init', 'add_menu_items_meta_box' );
- function add_menu_items_meta_box() {
- add_meta_box( 'menu_items', 'Menu Items', 'menu_items_meta', 'gavin_landd_menu', 'normal', 'high' );
- add_action( 'admin_footer-post.php', 'menu_item_scripts' );
- add_action( 'admin_footer-post-new.php', 'menu_item_scripts' );
- }
- add_action('admin_init', 'menu_items_init');
- add_action('save_post', 'menu_item_save_details');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement