<?php

// Dental Care Meta Data
function dentist_dental_care_custom_meta_services_icon() {
    add_meta_box( 
    	'bn_meta', __( 'Dental Care Icon Meta Feilds', 'dentist-dental-care' ), 
    	'dentist_dental_care_meta_callback_services_icon', 
    	'post', 
    	'normal', 
    	'high' 
    );
}

/* Hook things in for admin*/
if (is_admin()){
  add_action('admin_menu', 'dentist_dental_care_custom_meta_services_icon');
}

function dentist_dental_care_meta_callback_services_icon( $post ) {
    wp_nonce_field( basename( __FILE__ ), 'dentist_dental_care_meta_nonce_services_icon' );
    $bn_stored_meta = get_post_meta( $post->ID );
    $dentist_dental_care_service_icon = get_post_meta( $post->ID, 'dentist_dental_care_icon', true );
    ?>
    <div id="services_icon_meta">
        <table id="list">
            <tbody id="the-list" data-wp-lists="list:meta">
                <tr id="meta-8">
                    <td class="left">
                        <h3 style="margin:0"><?php esc_html_e( 'Services Icon', 'dentist-dental-care' )?></h3>
                        <p style="margin-top:0"><?php esc_html_e( 'Add the fontawesome icon class. Example: "fas fa-tooth".', 'dentist-dental-care' )?></p>
                        <input type="text" placeholder="fas fa-tooth" name="dentist_dental_care_icon" id="dentist_dental_care_icon" value="<?php echo esc_attr($dentist_dental_care_service_icon); ?>" />
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <?php
}

/* Saves the custom meta input */
function dentist_dental_care_meta_save_services_icon( $post_id ) {
    if (!isset($_POST['dentist_dental_care_meta_nonce_services_icon']) || !wp_verify_nonce( strip_tags( wp_unslash( $_POST['dentist_dental_care_meta_nonce_services_icon']) ), basename(__FILE__))) {
        return;
    }

    if (!current_user_can('edit_post', $post_id)) {
        return;
    }

    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }

    // Save Package Amount
    if( isset( $_POST[ 'dentist_dental_care_icon' ] ) ) {
        update_post_meta( $post_id, 'dentist_dental_care_icon', strip_tags( wp_unslash( $_POST[ 'dentist_dental_care_icon' ]) ) );
    }   
}
add_action( 'save_post', 'dentist_dental_care_meta_save_services_icon' );