'aurestaurant_custom_header', 'title' => __('Featured custom page header','aurestaurant'), 'page' => 'page', 'context' => 'normal', 'priority' => 'default', 'fields' => array( array( 'name' => __('Color Header line bottom','aurestaurant'), 'desc' => '', 'id' => 'header_line_color', 'type' => 'text', 'std' => '' ), array( 'name' => __('Image header','aurestaurant'), 'desc' => '', 'id' => 'meta-image-header', 'type' => 'text', 'std' => '' ), array( 'name' => __('Position image','aurestaurant'), 'desc' => '', 'id' => 'position-image', 'type' => 'select', 'choices' => array( 'top' => 'top', 'center' => 'center', 'bottom' => 'bottom', ), ), array( 'name' => __('Header Title 1','aurestaurant'), 'desc' => '', 'id' => 'header-title1', 'type' => 'text', 'std' => '' ), array( 'name' => __('Header Title 2','aurestaurant'), 'desc' => '', 'id' => 'header-title2', 'type' => 'text', 'std' => '' ) ) ); add_meta_box($meta_box['id'], $meta_box['title'], 'aurestaurant_show_header_meta_box_customization', $meta_box['page'], $meta_box['context'], $meta_box['priority']); } // Callback function to show fields in meta box function aurestaurant_show_header_meta_box_customization() { global $meta_box, $post; // Use nonce for verification echo ''; echo '
'; _e( 'Customize the header image and color line', 'aurestaurant' ); foreach ($meta_box['fields'] as $field) { // get current post meta data $meta = get_post_meta($post->ID, $field['id'], true); switch ($field['id']) { case 'header_line_color': ?> ', '
', $field['desc']; break; case 'meta-image-header' : ?>

'.esc_html__( 'Enter Header Title 1', 'aurestaurant' ).''; echo '', '
', $field['desc']; break; case 'header-title2' : echo ''; echo '', '
', $field['desc']; break; /* default : echo '', '
', $field['desc']; break;*/ } } ?> '; } // SAVE add_action('save_post', 'aurestaurant_save_data_meta_box_header') ; // Save data from meta box. function aurestaurant_save_data_meta_box_header($post_id) { global $meta_box; global $typenow; if( isset($meta_box) && $typenow == 'page' ) { // verify nonce if ( isset( $_POST['aurestaurant_meta_box_nonce'] ) && !wp_verify_nonce($_POST['aurestaurant_meta_box_nonce'], basename(__FILE__))) { return $post_id; } // check autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // check permissions if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } elseif (!current_user_can('edit_post', $post_id)) { return $post_id; } foreach ($meta_box['fields'] as $field) { if( isset($_POST[$field['id']]) ){ $old = get_post_meta($post_id, $field['id'], true); $new = $_POST[$field['id']]; echo '
old:'.$old; echo '
new:'.$new; echo '
field id:'.$field['id']; //die(); if ($new && $new != $old) { update_post_meta($post_id, $field['id'], $new); } elseif ('' == $new && $old) { update_post_meta($post_id, $field['id'], $old); } } } } } function aurestaurant_add_stylesheet_header_image() { wp_enqueue_style( 'aurestaurant-header-image', get_template_directory_uri().'/aurestaurant-custom-page-header-image/aurestaurant-header-image-options.css' ); } add_action( 'admin_enqueue_scripts', 'aurestaurant_add_stylesheet_header_image' ); /** * Loads the color picker javascript */ function aurestaurant_color_enqueue() { global $typenow; if( $typenow == 'page' ) { wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'meta-box-color-js', get_template_directory_uri() .'/aurestaurant-custom-page-header-image/js/meta-box-color.js', array( 'wp-color-picker' ) ); } } add_action( 'admin_enqueue_scripts', 'aurestaurant_color_enqueue' ); /** * Loads the image management javascript */ function aurestaurant_image_enqueue() { global $typenow; if( $typenow == 'page' ) { wp_enqueue_media(); // Registers and enqueues the required javascript. wp_register_script( 'meta-box-image', get_template_directory_uri() .'/aurestaurant-custom-page-header-image/js/meta-box-image.js', array( 'jquery' ) ); wp_localize_script( 'meta-box-image', 'meta_image', array( 'title' => __( 'Choose or Upload an Image', 'aurestaurant' ), 'button' => __( 'Use this image', 'aurestaurant' ), ) ); wp_enqueue_script( 'meta-box-image' ); } } add_action( 'admin_enqueue_scripts', 'aurestaurant_image_enqueue' ); /* Metabox in contact page to upload icon marker for map */ function aurestaurant_add_meta_boxes_contact_page() { global $post; // ONLY DISPLAY THE MAP MARKER ICON IMAGE IN CONTACT PAGE TEMPLATE if ( 'page-contact.php' == get_post_meta( $post->ID, '_wp_page_template', true ) ) { $args = array( 'name' => 'icon-marker-metabox-id-url', 'desc' => 'Icon marker url', 'id' => 'icon-marker-metabox-id-url', 'type' => 'text', 'std' => '' ); add_meta_box( 'icon-marker-metabox', // ID attribute of metabox __('Icon Marker','aurestaurant'), // Title of metabox visible to user 'callback_marker_icon', // Function that prints box in wp-admin 'page', // Show box for posts, pages, custom, etc. 'normal', // Where on the page to show the box. context//'normal', 'side', and 'advanced'. 'high', // Priority of box in display order ('high', 'low'). $args ); } } add_action( 'add_meta_boxes_page', 'aurestaurant_add_meta_boxes_contact_page' ); function callback_marker_icon(){ global $meta_box, $post; // Use nonce for verification echo ''; $metaId = get_post_meta($post->ID, 'icon-marker-metabox-id-url', true); ?>