<?php
/**
*
* Plugin Name: BuildABand
* Plugin URI: https://belgiumwebnet.com/
* Description: BuildABand: A powerful wedding band builder with custom styles, profiles, widths, and finishes.
* Version: 1.0.0    
* Author: Task Source Plugins
* Author URI: https://tasksource.net/
* Requires at least: 6.7
* Tested up to:      6.8
* Requires PHP:      7.4
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: buildaband
*/

if (!defined('ABSPATH')) exit;

define( 'buildaband_PLUGIN_FILE', __FILE__ );
define( 'buildaband_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'buildaband_PLUGIN_URL', plugin_dir_url( __FILE__ ) );

if(!class_exists('buildaband_BAND_A_BUILDER') ) {		
	class buildaband_BAND_A_BUILDER {	

		public function __construct() {
	        register_activation_hook( __FILE__, array( $this , 'activate_BBPWPDIR' ) );	   
	        add_shortcode('BuildABand', 'buildaband_shortcode');
   		}

   		public function activate_BBPWPDIR() {

		     // Check if Woo is active
		        if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
		                // Woo is active.
		        } else {
		                deactivate_plugins( plugin_basename( __FILE__ ) );
		                wp_die(
						    esc_html__( 'Please Activate WooCommerce Plugin First.', 'buildaband' ),
						    esc_html__( 'Plugin Dependency Check', 'buildaband' ),
						    array( 'back_link' => true )
						);
		        }   	

			// Create post object
			function BBPWPDIRCheckPageAlreadyexist( $title ) {
				$query = new WP_Query( [
					'post_type'   => 'page',
					'post_status' => 'publish',
					'title'       => $title,
					'posts_per_page' => 1
				] );
				return $query->have_posts() ? $query->posts[0] : null;
			}
			
			$page_BBPWPDIR = BBPWPDIRCheckPageAlreadyexist( 'BuildABand' );
			if (!$page_BBPWPDIR) {
				$my_post_BBPWPDIR = array(
				  'post_title'    => wp_strip_all_tags('BuildABand'),
				  'post_content'  => '[BuildABand]',
				  'post_status'   => 'publish',
				  'post_author'   => 1,
				  'post_type'     => 'page',
				);

				// Insert the post into the database
				wp_insert_post( $my_post_BBPWPDIR );
			}		

		} 

	}

	new buildaband_BAND_A_BUILDER();

}



// Enqueue scripts and styles
add_action('wp_enqueue_scripts', 'band_a_builder_wp_callback_for_scripts');
function band_a_builder_wp_callback_for_scripts() {
    wp_enqueue_style('bootstrap_css_BBWP', buildaband_PLUGIN_URL.'assets/css/plugins/bootstrap.min.css',[],'1.0');
    wp_enqueue_style( 'bootstrap_css_BBWP' );
    wp_register_style( 'montserrat_BBWP',  buildaband_PLUGIN_URL.'assets/fonts/montserrat/montserrat.css',[],'1.2' );
    wp_enqueue_style( 'montserrat_BBWP' );   
    wp_register_style( 'theme_BBWP',  buildaband_PLUGIN_URL.'assets/css/theme.css' ,array(),'1.10'); 
    wp_enqueue_style( 'theme_BBWP' );     
    wp_register_style( 'band_builders_BBWP',  buildaband_PLUGIN_URL.'assets/css/band-builder.css',array(),'1.0' );  
    wp_enqueue_style( 'band_builders_BBWP' );    
    wp_register_style( 'responsive_BBWP',  buildaband_PLUGIN_URL.'assets/css/responsive.css' ,array(),'10' );
    wp_enqueue_style( 'responsive_BBWP' );  

	
}  

function band_a_builder_wp_enqueue_external_js_footer() {
    wp_enqueue_script( 'bootstrap_BBWP',  buildaband_PLUGIN_URL.'assets/js/plugins/bootstrap.bundle.min.js', array( 'jquery' ),false );
    wp_enqueue_script('theme_buildaband', buildaband_PLUGIN_URL . 'assets/js/theme.js', array('jquery'), '1.9', true);
	wp_localize_script('theme_buildaband', 'buildaband_ajax', array(
        'ajax_url' => admin_url('admin-ajax.php'),
        'nonce'    => wp_create_nonce('buildaband_filter_program'),
    ));
	wp_localize_script('theme_buildaband', 'buildaband_add_to_cart_ajax', array(
        'ajax_url' => admin_url('admin-ajax.php'),
        'nonce'    => wp_create_nonce('buildaband_addTocartOrder'),
    ));
}
add_action('wp_footer', 'band_a_builder_wp_enqueue_external_js_footer');

require_once plugin_dir_path(__FILE__) . 'templates/band-builder-woo-variant.php';
