<?php

// Slide Post Meta
function curtains_fabric_bn_custom_meta_feature() {
    add_meta_box( 'bn_meta', __( 'Custom fields for Slider Post', 'curtains-fabric' ), 'curtains_fabric_meta_callback_feature', 'post', 'normal', 'high' );
}

if (is_admin()){
  add_action('admin_menu', 'curtains_fabric_bn_custom_meta_feature');
}

function curtains_fabric_meta_callback_feature( $post ) {
    wp_nonce_field( basename( __FILE__ ), 'curtains_fabric_feature_meta_nonce' );
    $bn_stored_meta = get_post_meta( $post->ID );
    $text1 = get_post_meta( $post->ID, 'curtains_fabric_text_1', true );
    ?>
    <div id="feature">
        <table id="list">
            <tbody id="the-list" data-wp-lists="list:meta">
                <tr id="meta-1">
                    <td class="left">
                        <?php esc_html_e( 'Post Short Heading', 'curtains-fabric' )?>
                    </td>
                    <td class="left">
                        <input type="text" name="curtains_fabric_text_1" id="curtains_fabric_text_1" value="<?php echo esc_attr($text1); ?>" />
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <?php
}

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

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

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

    // Save
    if( isset( $_POST[ 'curtains_fabric_text_1' ] ) ) {
        update_post_meta( $post_id, 'curtains_fabric_text_1', strip_tags( wp_unslash( $_POST[ 'curtains_fabric_text_1' ]) ) );
    }

}
add_action( 'save_post', 'curtains_fabric_bn_metadesig_save' );