<?php 
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
}

/*Constant define some varrible like table name etc*/

global $fbbttm_table_foodbooking,$fbbttm_foodbooking_cart, $fbbttm_table_packagelist, $charset_collate, $fbbttm_table_fooddeliverymanage, $fbbttm_table_payments, $fbbttm_table_setting,$wpdb;

	$fbbttm_table_foodbooking = $wpdb->prefix . 'fbbttm_foodbooking';
	$fbbttm_table_foodbooking_cart = $wpdb->prefix . 'fbbttm_foodbooking_cart';
	$fbbttm_table_foodbooking_cart_info = $wpdb->prefix . 'fbbttm_foodbooking_cart_iteminfo';
	$fbbttm_table_foodbooking_iteminfo = $wpdb->prefix . 'fbbttm_foodbooking_iteminfo';
	$fbbttm_table_packagelist = $wpdb->prefix . 'fbbttm_packagelist';
	$fbbttm_table_payments	  = $wpdb->prefix . 'fbbttm_payments';
	$fbbttm_table_setting 	  = $wpdb->prefix . 'fbbttm_setting';
	$fbbttm_table_delivery_address = $wpdb->prefix . 'fbbttm_delivery_address';

	$fbbttm_table_countries   = $wpdb->prefix . 'fbbttm_countries';
	$fbbttm_table_states 	  = $wpdb->prefix . 'fbbttm_states';
	$fbbttm_table_currencies  = $wpdb->prefix . 'fbbttm_currencies';	

	// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery 
	// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching
	// phpcs:disable WordPress.Security.ValidatedSanitizedInput.MissingUnslash
	// phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
	// phpcs:disable WordPress.Security.NonceVerification.Missing

	$tables = $wpdb->get_results("SHOW TABLES", ARRAY_N);

		// Look for the users table
		$users_table = '';
		foreach ($tables as $table) {
		    if (strpos($table[0], '_users') !== false) {
		        $users_table = $table[0];
		        break;
		    }
		}
		
	$fbbttm_table_wp_user = $users_table;

			

	define( 'FBBTTM_TB_FOODBOOKING_CART', $fbbttm_table_foodbooking_cart );
	define( 'FBBTTM_TB_FOODBOOKING_CART_ITEMINFO', $fbbttm_table_foodbooking_cart_info );
	define( 'FBBTTM_TB_FOODBOOKING', $fbbttm_table_foodbooking );
	define( 'FBBTTM_TB_FOODBOOKING_ITEMINFO', $fbbttm_table_foodbooking_iteminfo );
	define( 'FBBTTM_TB_PACKAGELIST', $fbbttm_table_packagelist );
	define( 'FBBTTM_TB_PAYMENT', $fbbttm_table_payments );
	define( 'FBBTTM_TB_SETTING', $fbbttm_table_setting );
	define( 'FBBTTM_WP_USER', $fbbttm_table_wp_user );
	define( 'FBBTTM_DELIVERY_ADDRESS', $fbbttm_table_delivery_address );

	define( 'FBBTTM_COUNTRIES', $fbbttm_table_countries );
	define( 'FBBTTM_STATES', $fbbttm_table_states);
	define( 'FBBTTM_CURRENCIES', $fbbttm_table_currencies );

	function fbbttm_install()
        {

			global $wpdb, $fbbttm_tabledataobj,$fbbttm_pageconfigobj;
			global $fbbttm_db_version;
			global  $charset_collate;

			$fbbttm_table_foodbooking = FBBTTM_TB_FOODBOOKING;
			$fbbttm_table_foodbooking_iteminfo = FBBTTM_TB_FOODBOOKING_ITEMINFO;
			
			$fbbttm_table_foodbooking_cart = FBBTTM_TB_FOODBOOKING_CART;
			$fbbttm_table_foodbooking_cart_iteminfo = FBBTTM_TB_FOODBOOKING_CART_ITEMINFO;
			
			$fbbttm_table_packagelist = FBBTTM_TB_PACKAGELIST;
			$fbbttm_table_setting = FBBTTM_TB_SETTING;

			$fbbttm_table_delivery_address = FBBTTM_DELIVERY_ADDRESS;

			$fbbttm_table_countries = FBBTTM_COUNTRIES;
			$fbbttm_table_states = FBBTTM_STATES;

			$fbbttm_table_currencies = FBBTTM_CURRENCIES;

			$fbbttm_table_payments = FBBTTM_TB_PAYMENT;
			
			$charset_collate = $wpdb->get_charset_collate();
			
			include_once ABSPATH . 'wp-admin/includes/upgrade.php';
			// phpcs:disable Squiz.PHP.DiscouragedFunctions.Discouraged 
          
            $charset_collate = '';

            if ($wpdb->has_cap('collation') ) {
                if (! empty($wpdb->charset) ) {
                    $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
                }
                if (! empty($wpdb->collate) ) {
                    $charset_collate .= " COLLATE $wpdb->collate";
                }
            }
				
			$fbbttm_dbtbl_create = array();
			
			$sql_table = "CREATE TABLE IF NOT EXISTS `{$fbbttm_table_foodbooking}`(
				`fbbttm_fdbid` bigint(11) NOT NULL AUTO_INCREMENT,
				`fbbttm_order_key` VARCHAR(255) NOT NULL,
				`fbbttm_user_id` INTEGER(11) NOT NULL,
				`fbbttm_fdcartid` INTEGER(11) NOT NULL,
				`fbbttm_booking_status` INTEGER(11) NOT NULL,
				`fbbttm_payment_id` INTEGER(11) NOT NULL,
				`fbbttm_payment_method` VARCHAR(50) NOT NULL,
				`fbbttm_payment_status` VARCHAR(255) NOT NULL,
				`fbbttm_sub_total` FLOAT(10,2) NOT NULL,
				`fbbttm_tax` FLOAT(10,2) NOT NULL,
				`fbbttm_discount` FLOAT(10,2) NOT NULL,
				`fbbttm_grand_total` FLOAT(10,2) NOT NULL,
				`fbbttm_expire_link` INTEGER(11) NOT NULL,
				`fbbttm_created_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
				`fbbttm_update_date` DATETIME  NOT NULL,

				PRIMARY KEY (`fbbttm_fdbid`)
			) {$charset_collate};";

			$fbbttm_dbtbl_create[ $fbbttm_table_foodbooking ] = dbDelta($sql_table);
		

			$sql_table = "CREATE TABLE IF NOT EXISTS `{$fbbttm_table_foodbooking_iteminfo}`(
				`fbbttm_fbitem_id` bigint(11) NOT NULL AUTO_INCREMENT,
				`fbbttm_fdbid` INTEGER(11) NOT NULL,
				`fbbttm_fbcartitem_id` INTEGER(11) NOT NULL,
				`fbbttm_pack_id` INTEGER(11) NOT NULL,
				`fbbttm_fd_id` INTEGER(11) NOT NULL,
				`fbbttm_food_name` VARCHAR(255) NOT NULL,
				`fbbttm_food_details` text NOT NULL,
				`fbbttm_food_time` VARCHAR(255) NOT NULL,
				`fbbttm_lunch_qty` INTEGER(11) NOT NULL,
				`fbbttm_dinner_qty` INTEGER(11) NOT NULL,
				`fbbttm_total_food` INTEGER(11) NOT NULL,
				`fbbttm_booking_deliveryday` VARCHAR(255) NOT NULL,
				`fbbttm_food_startdate` DATE  NOT NULL,
				`fbbttm_food_enddate` DATE  NOT NULL,
				`fbbttm_pack_name` VARCHAR(63) DEFAULT NULL,
				`fbbttm_fitem_price` FLOAT(10,2) NOT NULL,
				`fbbttm_package_price` FLOAT(10,2) NOT NULL,
				`fbbttm_special_price` FLOAT(10,2) NOT NULL,
				`fbbttm_package_day` INTEGER(11) NOT NULL,
				`fbbttm_package_description` text NOT NULL,
				`fbbttm_iteminfo_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
				`fbbttm_iteminfo_update_date` DATETIME  NOT NULL,
				PRIMARY KEY (`fbbttm_fbitem_id`)
			) {$charset_collate};";
			$fbbttm_dbtbl_create[ $fbbttm_table_foodbooking_iteminfo ] = dbDelta($sql_table);
				


			$sql_table = "CREATE TABLE IF NOT EXISTS `{$fbbttm_table_packagelist}`(
				`fbbttm_pack_id` bigint(11) NOT NULL AUTO_INCREMENT,
				`fbbttm_pack_status` INTEGER(11) NOT NULL DEFAULT 1,
				`fbbttm_package_name` VARCHAR(255) NOT NULL,
				`fbbttm_package_image` VARCHAR(255) NOT NULL,
				`fbbttm_fitem_price`  FLOAT(10,2) NOT NULL,
				`fbbttm_package_price` FLOAT(10,2) NOT NULL,
				`fbbttm_special_price` FLOAT(10,2) NOT NULL,
				`fbbttm_total_day` INTEGER(11) NOT NULL,
				`fbbttm_package_description` VARCHAR(63) DEFAULT NULL,
				`fbbttm_f_id` INTEGER(11) NOT NULL,
				`fbbttm_packagelist_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
				`fbbttm_packagelist_update_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,

				PRIMARY KEY (`fbbttm_pack_id`)
			) {$charset_collate};";
			$fbbttm_dbtbl_create[ $fbbttm_table_packagelist ] = dbDelta($sql_table);

			$sql_table = "CREATE TABLE IF NOT EXISTS `{$fbbttm_table_payments}`(
				`fbbttm_payment_id` bigint(11) NOT NULL AUTO_INCREMENT,
				`fbbttm_user_id` INTEGER(11) NOT NULL,
				`fbbttm_package_name` VARCHAR(70) NOT NULL,
				`fbbttm_transaction_id` VARCHAR(255) NOT NULL,
				`fbbttm_payment_intent_client_secret` VARCHAR(255) NOT NULL,
				`fbbttm_purchase_amount` FLOAT(10,2) NOT NULL,
				`fbbttm_currency_code` VARCHAR(50) NOT NULL,
				`fbbttm_payment_status` VARCHAR(100) NOT NULL,
				`fbbttm_payer_id` VARCHAR(255) DEFAULT NULL,
				`fbbttm_payer_name` VARCHAR(70) DEFAULT NULL,
				`fbbttm_payer_email` VARCHAR(50) DEFAULT NULL,
				`fbbttm_merchant_id` VARCHAR(255) DEFAULT NULL,
				`fbbttm_merchant_email` VARCHAR(50) DEFAULT NULL,
				`fbbttm_fdbid` VARCHAR(50) DEFAULT NULL,
				`fbbttm_payment_amount`  FLOAT(10,2) DEFAULT NULL,
				`fbbttm_payment_amount_currency` VARCHAR(10) DEFAULT NULL,
				`fbbttm_payment_source` VARCHAR(30) NOT NULL,
				`fbbttm_payment_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
				`fbbttm_payment_modified` DATETIME  NOT NULL,
				PRIMARY KEY (`fbbttm_payment_id`)
			) {$charset_collate};";
			$fbbttm_dbtbl_create[ $fbbttm_table_payments ] = dbDelta($sql_table);
			
			$sql_table = "CREATE TABLE IF NOT EXISTS `{$fbbttm_table_setting}`(
				`fbbttm_setting_id` bigint(11) NOT NULL AUTO_INCREMENT,
				`fbbttm_setting_name` VARCHAR(255) NOT NULL,
				`fbbttm_setting_value` text NOT NULL,
				`fbbttm_setting_type` VARCHAR(255) NOT NULL,
				`fbbttm_setting_updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
				PRIMARY KEY (`fbbttm_setting_id`)
			) {$charset_collate};";
			$fbbttm_dbtbl_create[ $fbbttm_table_setting ] = dbDelta($sql_table);

			$sql_table = "CREATE TABLE IF NOT EXISTS `{$fbbttm_table_foodbooking_cart}`(
				`fbbttm_fdcartid` bigint(11) NOT NULL AUTO_INCREMENT,
				`fbbttm_user_id` INTEGER(11) NOT NULL,
				`fbbttm_token_id` VARCHAR(255) NOT NULL,
				`fbbttm_sub_total` FLOAT(10,2) NOT NULL,
				`fbbttm_tax` FLOAT(10,2) NOT NULL,
				`fbbttm_discount` FLOAT(10,2) NOT NULL,
				`fbbttm_grand_total` FLOAT(10,2) NOT NULL,
				`order_placed` INTEGER(11) NOT NULL,
				`fbbttm_ordid` INTEGER(11) NOT NULL,
				`fbbttm_cartcreated_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
				`fbbttm_cartupdate_date` DATETIME  NOT NULL,
				 PRIMARY KEY (`fbbttm_fdcartid`)
			) {$charset_collate};";

			$fbbttm_dbtbl_create[ $fbbttm_table_foodbooking_cart ] = dbDelta($sql_table);

			$sql_table = "CREATE TABLE IF NOT EXISTS `{$fbbttm_table_foodbooking_cart_iteminfo}`(
				`fbbttm_fbcartitem_id` bigint(11) NOT NULL AUTO_INCREMENT,
				`fbbttm_fdcartid` INTEGER(11) NOT NULL,
				`fbbttm_pack_id` INTEGER(11) NOT NULL,
				`fbbttm_fd_id` INTEGER(11) NOT NULL,
				`fbbttm_food_name` VARCHAR(255) NOT NULL,
				`fbbttm_food_details` text NOT NULL,
				`fbbttm_food_time` VARCHAR(255) NOT NULL,
				`fbbttm_lunch_qty` INTEGER(11) NOT NULL,
				`fbbttm_dinner_qty` INTEGER(11) NOT NULL,
				`fbbttm_total_food` INTEGER(11) NOT NULL,
				`fbbttm_booking_deliveryday` VARCHAR(255) NOT NULL,
				`fbbttm_food_startdate` DATE NOT NULL,
				`fbbttm_food_enddate` DATE NOT NULL,
				`fbbttm_lastday_info` VARCHAR(255) NOT NULL,
				`fbbttm_pack_name` VARCHAR(255) NOT NULL,
				`fbbttm_fitem_price` FLOAT(10,2) NOT NULL,
				`fbbttm_package_price` FLOAT(10,2) NOT NULL,
				`fbbttm_special_price` FLOAT(10,2) NOT NULL,
				`fbbttm_package_day` INTEGER(11) NOT NULL,
				`fbbttm_package_description` TEXT NOT NULL,
				`fbbttm_iteminfo_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
				`fbbttm_iteminfo_update_date` DATETIME  NOT NULL,

				PRIMARY KEY (`fbbttm_fbcartitem_id`)
			) {$charset_collate};";

			$fbbttm_dbtbl_create[ $fbbttm_table_foodbooking_cart_iteminfo ] = dbDelta($sql_table);

			$sql_table = "CREATE TABLE IF NOT EXISTS `{$fbbttm_table_delivery_address}`(
				`fbbttm_delivery_id` INTEGER(11) NOT NULL AUTO_INCREMENT,
				`fbbttm_user_id` INTEGER(11) NOT NULL,
				`fbbttm_first_name` VARCHAR(255) NOT NULL,
				`fbbttm_last_name` VARCHAR(255) NOT NULL,
				`fbbttm_user_email` VARCHAR(255) NOT NULL,
				`fbbttm_user_country` VARCHAR(255) NOT NULL,
				`fbbttm_user_state` VARCHAR(255) NOT NULL,
				`fbbttm_street_1` VARCHAR(255) NOT NULL,
				`fbbttm_street_2` VARCHAR(255) NOT NULL,
				`fbbttm_city` VARCHAR(255) NOT NULL,
				`fbbttm_pincode` VARCHAR(255) NOT NULL,
				`fbbttm_phone` VARCHAR(255) NOT NULL,
				`fbbttm_address_create_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
				`fbbttm_address_update` DATETIME  NOT NULL,
				PRIMARY KEY (`fbbttm_delivery_id`)
			) {$charset_collate};";

			$fbbttm_dbtbl_create[ $fbbttm_table_delivery_address ] = dbDelta($sql_table);	

			$sql_table = "CREATE TABLE IF NOT EXISTS `{$fbbttm_table_countries}`(
				`id` INTEGER(11) NOT NULL AUTO_INCREMENT,
				`shortname` VARCHAR(3) NOT NULL,
				`name` VARCHAR(255) NOT NULL,
				`phonecode` INTEGER(11) NOT NULL,
				PRIMARY KEY (`id`)
			) {$charset_collate};";

			$fbbttm_dbtbl_create[ $fbbttm_table_countries ] = dbDelta($sql_table);

			$sql_table = "CREATE TABLE IF NOT EXISTS `{$fbbttm_table_states}`(
				`id` INTEGER(11) NOT NULL AUTO_INCREMENT,
				`name` VARCHAR(255) NOT NULL,
				`country_id` INTEGER(11) NOT NULL DEFAULT '1',
				PRIMARY KEY (`id`)
			) {$charset_collate};";

			$fbbttm_dbtbl_create[ $fbbttm_table_states ] = dbDelta($sql_table);

			/*currency table*/

			$sql_table = "CREATE TABLE IF NOT EXISTS `{$fbbttm_table_currencies}`(
				`id` INTEGER(11) NOT NULL AUTO_INCREMENT,
				`name` VARCHAR(255) NOT NULL,
				`symbol` VARCHAR(255) NOT NULL,
				`symbolNative` VARCHAR(255) NOT NULL,
				`decimalDigits` VARCHAR(255) NOT NULL,
				`rounding` VARCHAR(255) NOT NULL,
				`code` VARCHAR(255) NOT NULL,
				`namePlural` VARCHAR(255) NOT NULL,
				PRIMARY KEY (`id`)
			) {$charset_collate};";

			$fbbttm_dbtbl_create[ $fbbttm_table_currencies ] = dbDelta($sql_table);

			add_option( 'fbbttm_db_version', $fbbttm_db_version );
		}

		function fbbttm_run_at_activation(){

			global $fbbttm_pageconfigobj;

			$fbbttm_pageconfigobj->fbbttm_newall_create_pages();

			fbbttm_install();
			 
		}
		register_activation_hook( FBBTTM_MAIN_FILE, 'fbbttm_run_at_activation' );

		function fbbttm_uninstall()
        {
            do_action('fbbttm_foodboxbooker_after_uninstall');
        }
		
		add_action('admin_menu', 'fbbttm_menu' );


		function fbbttm_menu()
         {
		add_menu_page('FoodBox Booker', 'FoodBox Booker', 'manage_options', 'foodboxbooker', 'fbbttm_dashboard_form', 'dashicons-calendar-alt',30);

				add_submenu_page('foodboxbooker', 'Dashboard', 'Dashboard', 'manage_options','fbbttm_dashboard', 'fbbttm_currentplan_list');

			add_submenu_page(
		        'foodboxbooker',           // Parent slug (your custom plugin menu)
		        'All Fooditems',    // Page title
		        'All Fooditems',    // Submenu title
		        'manage_options',          // Capability required to access this menu
		        'edit.php?post_type=fbbttm_fooditems' // URL to the taxonomy edit page
		    );
	 
				
			


		     // Add a custom submenu slug for the Fooditems Categories
		    add_submenu_page(
		        'foodboxbooker',               // Parent slug (your custom plugin menu)
		        'Fooditems Categories',        // Page title
		        'Fooditems Categories',        // Submenu title
		        'manage_options',              // Capability required to access this menu
		        'fooditems-categories-page',   // Custom page slug
		        'fbbttm_fooditems_categories_redirect' // Callback function to handle the redirect
		    );

		

			add_submenu_page('foodboxbooker', 'Booking list', 'Booking list', 'manage_options','fbbttm_booking_list', 'fbbttm_dashboard_form');
			
			add_submenu_page('foodboxbooker', 'Package List', 'Package List', 'manage_options','fbbttm_packagelist', 'fbbttm_packagelist');
			add_submenu_page('foodboxbooker', 'Setting', 'Setting', 'manage_options','fbbttm_setting', 'fbbttm_setting');

		    remove_submenu_page('foodboxbooker', 'foodboxbooker');
        }

		add_action('admin_init', 'fbbttm_fooditems_categories_redirect');
        function fbbttm_fooditems_categories_redirect() {
           // phpcs:disable WordPress.Security.NonceVerification.Recommended 
		   if (isset($_GET['page']) && $_GET['page'] === 'fooditems-categories-page') {
		        $taxonomy = 'fbbttm_fooditems_category';
		        $post_type = 'fbbttm_fooditems';
		        $redirect_url = admin_url("edit-tags.php?taxonomy=$taxonomy&post_type=$post_type");
		        wp_redirect($redirect_url);
		        exit;
  		   }
		}


	// Ensure main menu stays highlighted for custom post type pages
	add_action('admin_head', 'fbbttm_highlight_menu');

	function fbbttm_highlight_menu() {
	    global $parent_file, $submenu_file, $post_type;
// phpcs:disable WordPress.Security.NonceVerification.Recommended 
	    if ($post_type === 'fbbttm_fooditems') {
	        $parent_file = 'foodboxbooker'; // Keep 'Food Box Booker' main menu open
	        $submenu_file = 'edit.php?post_type=fbbttm_fooditems'; // Highlight 'All Fooditems' submenu
	    }
	}	


	// Ensure correct submenu item is highlighted for Fooditems Categories
	function fbbttm_set_active_submenu($parent_file) {
	    global $pagenow, $taxonomy;

	    if ($pagenow === 'edit-tags.php' && isset($_GET['taxonomy']) && $_GET['taxonomy'] === 'fbbttm_fooditems_category') {
	        $parent_file = 'foodboxbooker';
	    }

	    return $parent_file;
	}
	add_filter('parent_file', 'fbbttm_set_active_submenu');


	// Highlight the specific submenu item when the page is active
function fbbttm_set_active_menu($submenu_file) {
    global $pagenow, $taxonomy;

    // phpcs:disable WordPress.Security.NonceVerification.Recommended 
    if ($pagenow === 'edit-tags.php' && isset($_GET['taxonomy']) && $_GET['taxonomy'] === 'fbbttm_fooditems_category') {
        $submenu_file = 'fooditems-categories-page';
    }

    return $submenu_file;
}
add_filter('submenu_file', 'fbbttm_set_active_menu');

        function fbbttm_currentplan_list()
        {
        	include_once FBBTTM_DIR . '/main/foodboxbooker-customplanlist.php';	
        }


       function fbbttm_setting () {
			include_once FBBTTM_DIR . '/main/foodboxbooker-setting.php';
		} 


		function fbbttm_packagelist(){
			include_once FBBTTM_DIR . '/main/foodboxbooker-packagelist.php';
			//fbbttm_packagelist_remove_data();

		}

	   function fbbttm_dashboard_form() {
	 
		include_once FBBTTM_DIR . '/main/foodboxbooker-dashboard.php';
	
		
		}
	

	add_action( 'admin_post_delete_booking', 'fbbttm_booking_remove_data' );

	function fbbttm_booking_remove_data(){

		

		global $wpdb, $fbbttm_pack_id;

		$foodbooking_table  = FBBTTM_TB_FOODBOOKING;
		$foodbookingitem_table  = FBBTTM_TB_FOODBOOKING_ITEMINFO;

		if(isset($_POST["delete"]) || isset($_POST["deleteall"])){

			if ( isset( $_POST['checked_id'] ) && is_array( $_POST['checked_id'] ) ) {
    				$checked_id = array_map( 'sanitize_text_field', wp_unslash( $_POST['checked_id'] ) );
				} 
			
				$placeholders = implode(',', array_fill(0, count($checked_id), '%d'));

				// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery
				// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching 
				// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
				// phpcs:disable WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
				$query = $wpdb->prepare(
					// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared 
				    "DELETE FROM {$foodbooking_table} WHERE fbbttm_fdbid IN ($placeholders)",
				    $checked_id
				);
				$wpdb->query($query //phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
			);

				// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery
			// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching 
				$query = $wpdb->prepare(
					//phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare 
				    "DELETE FROM {$foodbookingitem_table} WHERE fbbttm_fdbid IN ($placeholders)",
				    $checked_id
				);

			if($wpdb->query(
			$query //phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
			)){

				wp_redirect( admin_url( 'admin.php?page=fbbtttm_booking_list&message=deleted' ) );

			}
			else
			{
				 wp_redirect( admin_url( 'admin.php?page=fbbtttm_booking_list&message=error' ) );
			}

		}
		 wp_redirect( admin_url( 'admin.php?page=fbbtttm_booking_list&message=select_error' ) );
	     exit;

	}


	add_action( 'admin_post_delete_package', 'fbbttm_packagelist_remove_data' );


	function fbbttm_packagelist_remove_data()
	 {
		global $wpdb, $fbbttm_pack_id;

		$fbbttm_table_packagelist = $wpdb->prefix . 'fbbttm_packagelist';

		if(isset($_POST["delete"]) || isset($_POST["deleteall"])){
			

			if ( isset( $_POST['checked_id'] ) && is_array( $_POST['checked_id'] ) ) {
    				$checked_id = array_map( 'sanitize_text_field', wp_unslash( $_POST['checked_id'] ) );
				} 	
				

			$placeholders = implode(',', array_fill(0, count($checked_id), '%d'));

			// Construct the query using $wpdb->prepare
			$query = $wpdb->prepare(
				//phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
				//phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
			    "DELETE FROM {$fbbttm_table_packagelist} WHERE fbbttm_pack_id IN ($placeholders)",
			    $checked_id
			);


			if($wpdb->query(
				$query //phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
				)){
				 	wp_redirect( admin_url( 'admin.php?page=fbbtttm_packagelist&message=deleted' ) );
				}
				else {
          			 wp_redirect( admin_url( 'admin.php?page=fbbtttm_packagelist&message=error' ) );
        		}
			}
		 wp_redirect( admin_url( 'admin.php?page=fbbtttm_packagelist&message=select_error' ) );
	     exit;
   		}


/* Single post type template load*/
add_filter( 'single_template', 'fbbttm_override_single_template' );
function fbbttm_override_single_template( $single_template ){

    global $post;

    if($post->post_type==FBBTTM_CPT){
    	
    $file = FBBTTM_DIR .'templates/single-'. $post->post_type .'.php';

    if( file_exists( $file ) ) $single_template = $file;

	    return $single_template;
    }
     else{

    	return  $single_template;
    }
}

function fbbttm_get_template_part($slug, $name = null) {

	  do_action("fbbttm_get_template_part_{$slug}", $slug, $name);

	  $templates = array();
	  if (isset($name))
	      $templates[] = "{$slug}-{$name}.php";

	  $templates[] = "{$slug}.php";

	  fbbttm_get_template_path($templates, true, false);
}

/* Extend locate_template from WP Core 
* Define a location of your plugin file dir to a constant in this case = FBBTTM_TEMPLATE_DIR 
* Note: FBBTTM_PATH - can be any folder/subdirectory within your plugin files 
*/ 

function fbbttm_get_template_path($template_names, $load = false, $require_once = true ) {
    $located = ''; 
    foreach ( (array) $template_names as $template_name ) { 

      if ( !$template_name ) 
        continue; 

      /* search file within the FBBTTM_DIR only */ 
      if ( file_exists(FBBTTM_TEMPLATE_DIR . $template_name)) { 
        $located = FBBTTM_TEMPLATE_DIR . $template_name; 
        break; 
      } 
    }

    if ( $load && '' != $located )
        load_template( $located, $require_once );

    return $located;
}

/**
 *  Ajax code for addtocart
 */ 
function fbbttm_my_dataaddto_cart(){


	
		global $fbbttm_helperobj,$fbbttm_cartobj;

		check_ajax_referer( 'fbbttm_nonce_action', 'security' );

		$message = array();

		$cartmessage = $fbbttm_cartobj->fbbttm_add_tocart();
		// phpcs:disable WordPress.WP.AlternativeFunctions.wp_json_encode_wp_json_encode 
		echo wp_json_encode($cartmessage);

		die;

}

add_action( 'wp_ajax_fbbttm_my_dataaddto_cart', 'fbbttm_my_dataaddto_cart' );
add_action( 'wp_ajax_nopriv_fbbttm_my_dataaddto_cart', 'fbbttm_my_dataaddto_cart' );

/**
 * Code for remove item from  cart page
 */ 

function fbbttm_remove_item_cart(){

	global $fbbttm_helperobj,$fbbttm_cartobj;
	$itemid = '';
	if(isset($_POST['remid'])){
		$itemid = sanitize_text_field(wp_unslash($_POST['remid']));
	}

	check_ajax_referer( 'fbbttm_nonce_action', 'security' );

	$cartmessage = $fbbttm_cartobj->fbbttm_remove_item_intocart($itemid);	
	$message = array();

	if(!empty($cartmessage)){
		$message['successmessage'] = esc_html__('Delete item from cart ','foodboxbooker');
	}

	return $message;
	die;

}

add_action( 'wp_ajax_remove_item_cart', 'fbbttm_remove_item_cart' );
add_action( 'wp_ajax_nopriv_remove_item_cart', 'fbbttm_remove_item_cart' );

/*Place order for foodbookig*/
function fbbttm_place_order(){

	global $fbbttm_helperobj,$fbbttm_checkoutobj,$fbbttm_cartobj;

	$message = array();

	check_ajax_referer( 'fbbttm_nonce_action', 'security' );

	

	$currentuserid ='';
	if(isset($_POST['userid']))
	{
		$currentuserid = sanitize_text_field( wp_unslash($_POST['userid']));
	}


	$tokenid = $fbbttm_helperobj->fbbttm_get_user_cookie_data();

	$fbbttm_fullcartinfo = $fbbttm_cartobj->fbbttm_get_full_cartinfo($currentuserid,$tokenid);

	$noncename = '';
	if(isset($_POST['fbbttm_meta_box_noncename'])){
	$noncename = sanitize_text_field(wp_unslash($_POST['fbbttm_meta_box_noncename']));
	}

	if ( ! isset( $noncename ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash($noncename) ), 'fbbttm_meta_box_nonce' ) ) {

		$message['error'] = esc_html__('Sorry, Your request can not be processed due to security reason.','foodboxbooker'); 	
	}
	else{

		if(!empty($fbbttm_fullcartinfo))
		  {
			$fbbttm_place_orderinfo = $fbbttm_checkoutobj->fbbttm_place_order($fbbttm_fullcartinfo,'cod');
			$message['success'] = esc_html__('Succesfully place order','foodboxbooker'); 	
			$message['orderkey'] = $fbbttm_place_orderinfo;
		  }
		  else
		  {
			$message['error'] = esc_html__('Your cart is empty please add package in your cart','foodboxbooker'); 	
		  }

	  }
	  // phpcs:disable WordPress.WP.AlternativeFunctions.wp_json_encode_wp_json_encode 
		echo wp_json_encode($message);
		exit;
	}
add_action( 'wp_ajax_place_order', 'fbbttm_place_order' );
add_action( 'wp_ajax_nopriv_place_order', 'fbbttm_place_order' );

/**
 *  Function for update cart table and delete order entry
 **/ 
function fbbttm_update_order()
{
	global $fbbttm_checkoutobj;

	check_ajax_referer( 'fbbttm_nonce_action', 'security' );
	$orderid = $noncename = '';
	if(isset($_POST['orderid']))
	{
		$orderid = sanitize_text_field(wp_unslash($_POST['orderid']));
	}
	if(isset($_POST['fbbttm_meta_box_noncename'])){
		$noncename = sanitize_text_field(wp_unslash($_POST['fbbttm_meta_box_noncename']));
	}
	
	if ( ! isset( $noncename ) || ! wp_verify_nonce( $noncename, 'fbbttm_meta_box_nonce' ) ) 
	 {
		  $message['error_message'] = esc_html__('Sorry, Your request can not be processed due to security reason.','foodboxbooker'); 
	 }
	else
	 {
		$message = $fbbttm_checkoutobj->fbbttm_update_cart_chewcan($orderid);
	 }

	 // phpcs:disable WordPress.WP.AlternativeFunctions.wp_json_encode_wp_json_encode 
	 echo wp_json_encode($message);
	 die;
}

add_action( 'wp_ajax_update_order', 'fbbttm_update_order' );
add_action( 'wp_ajax_nopriv_update_order', 'fbbttm_update_order' );

/*
 * Get state drop down
 */
function fbbttm_getstate(){

	global $fbbttm_helperobj;
	$id = $sid = '';
	if(isset($_POST['id'])){
		$id = sanitize_text_field(wp_unslash($_POST['id']));
	}
	if(isset($_POST['hdnsid'])){
		$sid = sanitize_text_field(wp_unslash($_POST['hdnsid']));
	}


	$statehtml = array();

	$statedata = $fbbttm_helperobj->fbbttm_comman_single_tableinfo(FBBTTM_STATES,'country_id',$id,'name');	


	if(!empty($statedata)){

		$stateoptiondrop = $fbbttm_helperobj->fbbttm_create_option_html($statedata,$sid);

		$statehtml['stateoption'] = $stateoptiondrop;
	}
	// phpcs:disable WordPress.WP.AlternativeFunctions.wp_json_encode_wp_json_encode 
	echo wp_json_encode($statehtml);
	exit;
}

add_action( 'wp_ajax_get_state_as_country', 'fbbttm_getstate' );
add_action( 'wp_ajax_nopriv_get_state_as_country', 'fbbttm_getstate' );

 /**
 *  Delivery form submit 
 */ 
 function fbbttm_deliveryformsubmit(){

	global $fbbttm_helperobj;

	check_ajax_referer( 'fbbttm_nonce_action', 'security' );

	$submitdata  = $fbbttm_helperobj->fbbttm_form_data_validatesubmit();
	// phpcs:disable WordPress.WP.AlternativeFunctions.wp_json_encode_wp_json_encode 
	echo wp_json_encode($submitdata);
	die;
 } 

 add_action( 'wp_ajax_delivery_formsubmit', 'fbbttm_deliveryformsubmit' );
 add_action( 'wp_ajax_nopriv_delivery_formsubmit', 'fbbttm_deliveryformsubmit' );
 /**
 * Account details submit
 */ 
 function fbbttm_account_formsubmit()
 {
	global $fbbttm_helperobj;
	check_ajax_referer( 'fbbttm_nonce_action', 'security' );
	
	$submitdata  = $fbbttm_helperobj->fbbttm_set_user_data();	
	// phpcs:disable WordPress.WP.AlternativeFunctions.wp_json_encode_wp_json_encode 
	echo wp_json_encode($submitdata);
	exit;
 }

add_action( 'wp_ajax_account_edit_formsubmit', 'fbbttm_account_formsubmit' );
add_action( 'wp_ajax_nopriv_account_edit_formsubmit', 'fbbttm_account_formsubmit' );

function fbbttm_ajax_login_init(){

    wp_register_script('ajax-login-script', get_template_directory_uri() . '/ajax-login-script.js', array('jquery'),'1.0.0',true ); 
    wp_enqueue_script('ajax-login-script');

    wp_localize_script( 'ajax-login-script', 'ajax_login_object', array( 
        'ajaxurl' => admin_url( 'admin-ajax.php' ),
        'redirecturl' => home_url(),
        'loadingmessage' => __('Sending user info, please wait...','foodboxbooker')
    ));

    // Enable the user with no privileges to run ajax_login() in AJAX
    add_action( 'wp_ajax_nopriv_ajaxlogin', 'ajax_login' );
}

/**
 * Function for login in site
 */ 
function fbbttm_login()
{

	global $fbbttm_helperobj;

	$message = array();
	$error_msg = array();

	// Execute the action only if the user isn't logged in
	if (!is_user_logged_in()) {
	    add_action('init', 'fbbttm_ajax_login_init');
	}

	check_ajax_referer( 'fbbttm_nonce_action', 'security' );

	$submitdata  = $fbbttm_helperobj->fbbttm_user_login_form();	
	echo wp_json_encode($submitdata);
	die();
}

add_action( 'wp_ajax_fbbttm_login', 'fbbttm_login' );
add_action( 'wp_ajax_nopriv_fbbttm_login', 'fbbttm_login' );

function fbbttm_user_register(){

	global $fbbttm_helperobj;
	// Execute the action only if the user isn't logged in
	if (!is_user_logged_in()) {
	    add_action('init', 'fbbttm_ajax_login_init');
	}
	check_ajax_referer( 'fbbttm_nonce_action', 'security' );

	

	$submitdata  = $fbbttm_helperobj->fbbttm_user_register();	
	echo wp_json_encode($submitdata);
	die();
}
add_action( 'wp_ajax_fbbttm_register', 'fbbttm_user_register' );
add_action( 'wp_ajax_nopriv_fbbttm_register', 'fbbttm_user_register' );

function fbbttm_user_lostpassword(){

	global $fbbttm_helperobj;
	check_ajax_referer( 'fbbttm_nonce_action', 'security' );
	
	$submitdata  = $fbbttm_helperobj->fbbttm_user_lost_password();	
	echo wp_json_encode($submitdata);
	die();
}
add_action( 'wp_ajax_fbbttm_lostpassword', 'fbbttm_user_lostpassword' );
add_action( 'wp_ajax_nopriv_fbbttm_lostpassword', 'fbbttm_user_lostpassword' );
function fbbttm_user_resetpass(){
	global $fbbttm_helperobj,$fbbttm_myaccountobj;

	check_ajax_referer( 'fbbttm_nonce_action', 'security' );

	$submitdata  = $fbbttm_myaccountobj->fbbttm_user_reset_password();	
	echo wp_json_encode($submitdata);
	die();
}

add_action( 'wp_ajax_fbbttm_resetpass', 'fbbttm_user_resetpass' );
add_action( 'wp_ajax_nopriv_fbbttm_resetpass', 'fbbttm_user_resetpass' );




function fbbttm_custom_login_redirect( $redirect_to, $request, $user ) {
    // Get the current user's role
    if(!empty($user->roles)){
	    $user_role = $user->roles[0];
	    // Set the URL to redirect users to based on their role
	    if ( $user_role == 'subscriber' ) {
	        $redirect_to = get_site_url();
	    } elseif ( $user_role == 'contributor' ) {
	       $redirect_to = get_site_url();
	    }
 	}
    return $redirect_to;
}
add_filter( 'login_redirect', 'fbbttm_custom_login_redirect', 10, 3 );
/**
 * function for checkout email check user exist or not
 */ 
function fbbttm_user_checkemail()
{
	global $fbbttm_helperobj;
	$searcharray = array();
	check_ajax_referer( 'fbbttm_nonce_action', 'security' );
	$email = '';
	if(isset($_POST['emailid'])){
		$email = sanitize_text_field(wp_unslash($_POST['emailid']));
	}
	$submitdata  = $fbbttm_helperobj->fbbttm_user_email_checkajx($email);	
	echo wp_json_encode($submitdata);
	die();
}
add_action( 'wp_ajax_fbbttm_checkemail', 'fbbttm_user_checkemail' );
add_action( 'wp_ajax_nopriv_fbbttm_checkemail', 'fbbttm_user_checkemail' );

function fbbttm_renew_get_packinfo()
	{

		global $fbbttm_helperobj,$fbbttm_orderinfoobj;
		$bokitemid = '';
		if(isset($_POST['bokitemid'])){
			$bokitemid = sanitize_text_field(wp_unslash($_POST['bokitemid']));
		}

		check_ajax_referer( 'fbbttm_nonce_action', 'security' );

		$packinfo = $fbbttm_orderinfoobj->fbbttm_iteminfo_forrenew( $bokitemid);

		echo wp_json_encode($packinfo);

		die();

	}

add_action( 'wp_ajax_renew_get_packinfo', 'fbbttm_renew_get_packinfo' );
add_action( 'wp_ajax_nopriv_renew_get_packinfo', 'fbbttm_renew_get_packinfo' );

add_action('init', 'fbbttm_set_custom_cookie');

function fbbttm_set_custom_cookie() {

	global $fbbttm_orderinfoobj;
		 $tokenid =	uniqid('user_', true);


		 $httphost = '';
		 if(isset($_SERVER['HTTP_HOST']))
		 {
		 	$httphost = sanitize_text_field(wp_unslash($_SERVER['HTTP_HOST']));
		 }

	    if (!isset($_COOKIE['custom_token_cookie'])) {

	        // Ensure the constants are defined
	        if (!defined('COOKIEPATH')) {
	            define('COOKIEPATH', '/');
	        }
	        if (!defined('COOKIE_DOMAIN')) {
	            define('COOKIE_DOMAIN', $httphost);
	        }

	       
	        // Set the cookie if it doesn't already exist
	        setcookie('custom_token_cookie', $tokenid , strtotime('+30 day'), COOKIEPATH, COOKIE_DOMAIN, false, true);
	        $_COOKIE['custom_token_cookie'] = $tokenid ; // Make the cookie available immediately
	    }
	    else{

	    	$custom_token_cookie ='';

	    	if (isset($_COOKIE['custom_token_cookie'])) {
	    			$custom_token_cookie = sanitize_text_field(wp_unslash($_COOKIE['custom_token_cookie']));
	    	}

	    	$fbbttmkey = 'fbbttm_order_'.$custom_token_cookie;
	        $orderinfo = $fbbttm_orderinfoobj->fbbttm_get_orderinfo_byorder_key($fbbttmkey,'');
	        if(!empty($orderinfo)){
		        if (!defined('COOKIEPATH')) {
		            define('COOKIEPATH', '/');
		        }
		        if (!defined('COOKIE_DOMAIN')) {
		            define('COOKIE_DOMAIN', $httphost);
		        }
		        setcookie('custom_token_cookie', $tokenid , strtotime('+30 day'), COOKIEPATH, COOKIE_DOMAIN, false, true);
		        $_COOKIE['custom_token_cookie'] = $tokenid ; // Make the cookie available immediately
	        }
	    }
   }

add_action('template_redirect', 'fbbttm_my_custom_plugin_delete_cookie');

function fbbttm_my_custom_plugin_delete_cookie() {
    // Check if we are on the specific page to delete the cookie
    if (is_page('fbbttm-order-received')) {

    	 $httphost = '';
		 if(isset($_SERVER['HTTP_HOST']))
		 {
		 	$httphost = sanitize_text_field(wp_unslash($_SERVER['HTTP_HOST']));
		 }
        if (headers_sent($file, $line)) {
        } else {

        	if (!defined('COOKIEPATH')) {
	            define('COOKIEPATH', '/');
	        }
	        if (!defined('COOKIE_DOMAIN')) {
	            define('COOKIE_DOMAIN', $httphost);
	        }
            setcookie('custom_token_cookie', '', time() - 3600, COOKIEPATH, COOKIE_DOMAIN, false, true); // Expire the cookie

            $_COOKIE['custom_token_cookie'] = '';
            unset($_COOKIE['custom_token_cookie']); 
        }
    }
}


add_filter( 'admin_body_class', 'fbbttm_add_admin_body_class' );

function fbbttm_add_admin_body_class( $classes ) {
    // Check if we are on your plugin page
    $screen = get_current_screen();
   
    if ( $screen && $screen->id === 'foodbox-booker_page_fbbttm_packagelist' ) { 
        $classes .= 'foodboxbooker foodboxbooker-page'; // Add your custom class
    }
    if ( $screen && $screen->id === 'foodbox-booker_page_fbbttm_booking_list' ) { 
        $classes .= 'foodboxbooker foodboxbooker-page'; // Add your custom class
    }
    if ( $screen && $screen->id === 'foodbox-booker_page_fbbttm_dashboard' ) { 
        $classes .= 'foodboxbooker foodboxbooker-page'; // Add your custom class
    }
     if ( $screen && $screen->id === 'foodbox-booker_page_fbbttm_setting' ) { 
        $classes .= 'foodboxbooker foodboxbooker-page'; // Add your custom class
    }
    return $classes;
}

function fbbttm_body_class($classes) {
    
     $classes[] = 'foodboxbooker ';
     $classes[] = 'foodboxbooker-page';

    if(fbbttm_check_cart()){
   		 $classes[] = 'foodboxbooker-cart';
		 $classes[] = 'foodboxbooker-page';
    }

    if(fbbttm_check_itemlist())
    {
    	 $classes[] = 'foodboxbooker-listpage';
		 $classes[] = 'foodboxbooker-page';
    }

    if(fbbttm_check_checkout())
    {
    	 $classes[] = 'foodboxbooker-checkoutpage';
		 $classes[] = 'foodboxbooker-page';
    }

    if(fbbttm_check_orderrecived())
    {
    	 $classes[] = 'foodboxbooker-order-received-page';
		 $classes[] = 'foodboxbooker-page';
    }
    if(fbbttm_check_myaccount())
    {
    	 $classes[] = 'foodboxbooker-myaccount-page';
		 $classes[] = 'foodboxbooker-page';
    }
    return $classes;
}

	add_filter('body_class', 'fbbttm_body_class');

	function fbbttm_check_myaccount()
	{
		global $fbbttm_helperobj;
		$accountpage = $fbbttm_helperobj->fbbttm_get_single_commonquery('fbbttm_myaccount_page');
		$pageid = '';
		if(!empty($accountpage))
		{
			$pageid = $accountpage[0]['fbbttm_setting_value'];
		}
		else
		{
			$pageid = get_option( 'fbbttm_fbbttm-myaccount_page_id' );
		}
		return ( $pageid && is_page( $pageid ) );
	}

	function fbbttm_check_orderrecived()
	{
		global $fbbttm_helperobj;
		$orderpage = $fbbttm_helperobj->fbbttm_get_single_commonquery('fbbttm_order_received');
		$pageid = '';
		if(!empty($orderpage))
		{
			$pageid = $orderpage[0]['fbbttm_setting_value'];
		}
		else{

			$pageid = get_option( 'fbbttm_fbbttm-order-received_page_id' );

		}

		return ( $pageid && is_page( $pageid ) );
	}

   function fbbttm_check_itemlist()
	{
		global $fbbttm_helperobj;
		$shoppage = $fbbttm_helperobj->fbbttm_get_single_commonquery('fbbttm_shop_page');
		$pageid = '';
		if(!empty($shoppage))
		{
			$pageid = $shoppage[0]['fbbttm_setting_value'];
		}
		else{
			$pageid = get_option( 'fbbttm_fbbttm-shop_page_id' );
		}
		return ( $pageid && is_page( $pageid ) );
	}



	function fbbttm_check_checkout()
	{
		global $fbbttm_helperobj;
		$checkoutpage = $fbbttm_helperobj->fbbttm_get_single_commonquery('fbbttm_checkout_page');
		$pageid ='';
		if(!empty($checkoutpage))
		{
			$pageid = $checkoutpage[0]['fbbttm_setting_value'];
		}
		else{
		$pageid = get_option( 'fbbttm_fbbttm-checkout_page_id' );
		}
		return ( $pageid && is_page( $pageid ) );
	}


	function fbbttm_check_cart()
	{
		global $fbbttm_helperobj;
		$cartpage = $fbbttm_helperobj->fbbttm_get_single_commonquery('fbbttm_cart_page');

		$pageid ='';
			
		if(!empty($cartpage))
		{
			$pageid = $cartpage[0]['fbbttm_setting_value'];
		}
		else
		{
			$pageid = get_option( 'fbbttm_fbbttm-cart_page_id' );
		}
		return ( $pageid && is_page( $pageid ) );
	}

	add_action('init','fbbttm_check_register_param');
	function fbbttm_check_register_param() { 
	    global $wp; 
	    $wp->add_query_var('fbbttmkey'); 
	}


	function fbbttm_limit_text($text, $limit = 100) {
	    if (strlen($text) > $limit) {
	        $text = substr($text, 0, $limit);
	        $text = substr($text, 0, strrpos($text, ' ')); 
	        $text .= '...'; 
	    }
	    return $text;
	}

 function fbbttm_wp_kses($content=null)
	{
 	   return  wp_kses(
					    $content,
					    array(
					        'a'      => array(
					            'href'  => array(),
					            'title' => array(),
					        ),
					        'div'     => array(
					        	'class'  => array(),
					        	'id'  => array(),
					        ),
					        'h1'   => array(
								'class'  => array(),
								'style'  => array(),
								'id'	 => array(),
							),
							'h2'   => array(
								'class'  => array(),
								'style'  => array(),
								'id'	 => array(),
							),
							'h3'   => array(
								'class'  => array(),
								'style'  => array(),
								'id'	 => array(),
							),
							'h4'   => array(
								'class'  => array(),
								'style'  => array(),
								'id'	 => array(),
							),
					        'h5'     => array(
					        	'class'  => array(),
					        	'id'  => array(),
					        ),
					        'h6'   => array(
								'class'  => array(),
								'style'  => array(),
								'id'	 => array(),
							),
					        'span'     => array(
					        'class'  => array(),
					        	'id'  => array(),
					        ),
					        'br'     => array(),
					        'em'     => array(),
					        'strong' => array(),
					        'img'     => array(
					        	'class'  => array(),
					        	'id'  => array(),
					        	'src'  => array(),
					        	'title'  => array(),
					        	'height'  => array(),
					        	'width'  => array(),
					        ),
					    )
					);

		 }
	

	global $fbbttm_allowed_html;
	$fbbttm_allowed_html = array(
		'aside' => array(
			'class' => array(),
			'id'    => array(),
			'role'  => array(),
			'style'	=> array(),
			'name'	=> array(),
		),
		'div'		=> array(
			'class'			=> array(),
			'id'			=> array(),
			'style'			=> array(),
			'role'			=> array(),
			'data-tm-bg'		=> array(),
			'data-iconset'	=> array(),
			'data-tm-icon'		=> array(),
			'data-tm-show'		=> array(),
			'data-tm-column'	=> array(),
			'data-appear-animation'	=> array(),
			'data-from'			=> array(),
			'data-to'			=> array(),
			'data-interval'		=> array(),
			'data-before'		=> array(),
			'data-before-style'	=> array(),
			'data-after'		=> array(),
			'data-after-style'	=> array(),
			'data-digit'		=> array(),
			'data-fill'			=> array(),
			'data-emptyfill'	=> array(),
			'data-thickness'	=> array(),
			'data-filltype'		=> array(),
			'data-gradient1'	=> array(),
			'data-gradient2'	=> array(),
			'data-fbbttm-loop'		=> array(),
			'data-fbbttm-autoplay'	=> array(),
			'data-fbbttm-centermode'=> array(),
			'data-fbbttm-centerpadding'=> array(),
			'data-fbbttm-nav'		=> array(),
			'data-fbbttm-dots'		=> array(),
			'data-fbbttm-slidestoscroll'=> array(),
			'data-fbbttm-autoplayspeed'=> array(),
			'data-fbbttm-margin'	=> array(),
		),
		'span'		=> array(
			'class'				=> array(),
			'id'				=> array(),
			'style'				=> array(),
			'data-appear-animation'	=> array(),
			'data-from'			=> array(),
			'data-to'			=> array(),
			'data-interval'		=> array(),
			'data-before'		=> array(),
			'data-before-style'	=> array(),
			'data-after'		=> array(),
			'data-after-style'	=> array(),
			'data-digit'		=> array(),
			'data-fill'			=> array(),
			'data-emptyfill'	=> array(),
			'data-thickness'	=> array(),
			'data-filltype'		=> array(),
			'data-gradient1'	=> array(),
			'data-gradient2'	=> array(),
			'data-percentage-value'	=> array(),
			'data-value'		=> array(),

		),
		'i'   => array(
			'class'  => array(),
			'style'		=> array(),
		),
		'h1'   => array(
			'class'  => array(),
			'style'  => array(),
			'id'	 => array(),
		),
		'h2'   => array(
			'class'  => array(),
			'style'  => array(),
			'id'	 => array(),
		),
		'h3'   => array(
			'class'  => array(),
			'style'  => array(),
			'id'	 => array(),
		),
		'h4'   => array(
			'class'  => array(),
			'style'  => array(),
			'id'	 => array(),
		),
		'h5'   => array(
			'class'  => array(),
			'style'  => array(),
			'id'	 => array(),
		),
		'h6'   => array(
			'class'  => array(),
			'style'  => array(),
			'id'	 => array(),
		),
		'article'	=> array(
			'class'			=> array(),
			'id'			=> array(),
			'style'			=> array(),
		),
		'input'   => array(
			'type'  		=> array(),
			'name'  		=> array(),
			'value' 		=> array(),
			'class' 		=> array(),
			'placeholder'	=> array(),
			'id'			=> array(),
			'style'			=> array(),
			'checked'		=> array(),
		),
		'blockquote'	=> array(
			'class'			=> array(),
			'id'			=> array(),
			'style'			=> array(),
		),
		'a'	    => array(
			'class'		=> array(),
			'href'		=> array(),
			'style'		=> array(),
			'title'		=> array(),
			'target'	=> array(),
			'rel'		=> array(),
			'data-rel'	=> array(),
			'data-filter'	=> array(),
			'data-sortby' => array(),
			'data-clear'	=> array(),
		),
		'nav' => array(
			'class'	  => array(),
			'id'	  => array(),
		),
		'i'			  => array(
			'class'	  => array(),
			'style'	  => array(),
		),
		'br'     => array(),
		'em'     => array(),
		'strong' => array(),
		'ul'		=> array(
			'class'		=> array(),
		),
		'ol'		=> array(
			'class'		=> array(),
		),
		'li'     => array(
			'class'  => array(),
			'data-content'	=> array(),
		),
		'p'    => array(
			'class' => array(),
		),
		'img' => array(
			'class'  => array(),
			'src'    => array(),
			'alt'    => array(),
			'title'  => array(),
			'width'  => array(),
			'height' => array(),
			'srcset'	=> array(),
			'sizes'		=> array(),
			'data-id'	=> array(),
			'data-srcset' => array(),
			'data-src'	=> array(),
		),
		'sup'    => array(
			'class' => array(),
		),
		'sub'    => array(
			'class' => array(),
		),
		'noscript'	=> array(),
		'iframe' => array(
			'src'         => array(),
			'width'       => array(),
			'height'      => array(),
			'scrolling'   => array(),
			'frameborder'	=> array(),
			'allow'		=> array(),
			'allowfullscreen'	=> array(),
		    'class'		=> array(),
			'id'		=> array(),
			'style'		=> array(),
		),
		'time'    => array(
			'class'		=> array(),
			'id'		=> array(),
			'style'		=> array(),
			'datetime'	=> array(),
		),
		'header'	=> array(
			'class'		=> array(),
			'id'		=> array(),
			'style'		=> array(),
		),
		'form' => array(
			'class'			=> array(),
			'id'			=> array(),
			'type'			=> array(),
			'method'		=> array(),
			'name'			=> array(),
			'action'		=> array(),
			'style'			=> array(),
			'data-id'		=> array(),
			'data-name'		=> array(),
		),
		'textarea'	=> array(
			'name'			=> array(),
			'value'			=> array(),
			'placeholder'	=> array(),
			'class'			=> array(),
			'id'			=> array(),
			'style'			=> array(),
		),
		'aside'	=> array(
			'name'			=> array(),
			'class'			=> array(),
			'id'			=> array(),
			'style'			=> array(),
		),
		'button'	=> array(
			'class'		=> array(),
			'type'		=> array(),
			'href'		=> array(),
			'title'		=> array(),
		),
		'label'	=> array(
			'for'			=> array(),
			'name'			=> array(),
			'class'			=> array(),
			'id'			=> array(),
			'style'			=> array(),
		),
		'small'	=> array(
			'name'			=> array(),
			'class'			=> array(),
			'id'			=> array(),
			'style'			=> array(),
		),
	);
?>