<?php
/*
 *  Plugin Name:    WhatsApp Chat Support
 *  Plugin URI:     https://wpchatplugins.com/plugins/click-to-whatsapp/
 *  Description:    Can easily create Bubble & buttons for reciving whatsapp message from useres in any WordPress site. Gutenberg, Elementor and shortcodes supported. 
 *  Author:         ThemeAtelier
 *  Author URI:     http://themeatelier.net/
 *  Requirements:   PHP 5.2.4 or above, WordPress 3.3 or above.
 *  Version:       1.3.2
 * Text Domain:  ta-whatshelp
 * Domain Path:  /languages
 */

// Block Direct access
if (!defined('ABSPATH')) {
	die('You should not access this file directly!.');
}

// Define Constants for direct access alert message.
if (!defined('WHATSHELP_ALERT_MSG'))
	define('WHATSHELP_ALERT_MSG', esc_html__('You should not access this file directly.!', 'ta-whatshelp'));

// Define constants for plugin directory path.
if (!defined('WHATSHELP_DIR_PATH'))
	define('WHATSHELP_DIR_PATH', plugin_dir_path(__FILE__));


// Define constants for view directory path.
if (!defined('WHATSHELP_VIEW_DIR_PATH'))
	define('WHATSHELP_VIEW_DIR_PATH', WHATSHELP_DIR_PATH . 'view/');

// Define constants for elementor widget directory path.
if (!defined('WHATSHELP_EW_DIR_PATH'))
	define('WHATSHELP_EW_DIR_PATH', WHATSHELP_VIEW_DIR_PATH . 'elementor-widgets/');


// Define constants for plugin directory path.
if (!defined('WHATSHELP_DIR_URL'))
	define('WHATSHELP_DIR_URL', plugin_dir_url(__FILE__));

// load text domain from plugin folder
function whatshelp_load_textdomain()
{
	load_plugin_textdomain('', false, dirname(__FILE__) . "/languages");
}
add_action("plugins_loaded", 'whatshelp_load_textdomain');

// Plugin settings in plugin list
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'whatshelp_settings_link');
function whatshelp_settings_link(array $links)
{
	$url = get_admin_url() . "admin.php?page=whatshelp";
	$settings_link = '<a href="' . esc_url($url) . '">' . esc_html__('Settings', 'ta-whatshelp') . '</a>';
	$links[] = $settings_link;
	return $links;
}


// Pro version link
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'whatshelp_pro_link');
function whatshelp_pro_link(array $links)
{
    $url = "https://1.envato.market/x9Ba1y";
    $settings_link = '<a style="color: #118C7E; font-weight: 700;" href="' . esc_url($url) . '">' . esc_html__('Go Pro!', 'ta-vchat') . '</a>';
    $links[] = $settings_link;
    return $links;
}

// Register block
function create_block_whatsapp_block_init()
{
	register_block_type_from_metadata(WHATSHELP_VIEW_DIR_PATH . 'blocks/');
}
add_action('init', 'create_block_whatsapp_block_init');


// Register block category 

function whatsapp_chat_plugin_block_categories( $categories ) {
    return array_merge(
        $categories,
        [
            [
                'slug'  => 'whatsapp-block',
                'title' => __( 'Whatsapp block', 'ta-whatshelp' ),
            ],
        ]
    );
}
add_action( 'block_categories', 'whatsapp_chat_plugin_block_categories', 10, 2 );



// Script enqueue class include
require_once WHATSHELP_DIR_PATH . 'inc/class-enqueue.php';

// View Shortcodes
require_once WHATSHELP_DIR_PATH . '/view/elementor-widgets/elementor-widget.php';
require_once WHATSHELP_DIR_PATH . 'view/shortcodes/custom-shortcode.php';

// buttons functions
require_once WHATSHELP_DIR_PATH . 'inc/functions.php';
// Button template class
require_once WHATSHELP_DIR_PATH . 'inc/class-custom-buttons-templates.php';

// single chat bubble template
require_once WHATSHELP_DIR_PATH . '/view/chat-bubbles/chat-bubbles.php';

// include framework for admin panel
require_once WHATSHELP_DIR_PATH . 'admin/codestar-framework.php';
require_once WHATSHELP_DIR_PATH . 'inc/whatshelp-plugin-options.php';



/**
 * Initialize the plugin tracker
 *
 * @return void
 */
function WhatsHelp_chat_appsero_init()
{

    if (!class_exists('WhatsHelpAppSero\Insights')) {
        require_once WHATSHELP_DIR_PATH . 'admin/appsero/Client.php';
    }

	$client = new WhatsHelpAppSero\Client( 'faa96fc0-6c04-4d9e-95fa-3612fea71662', 'WhatsApp Chat Support', __FILE__ );
    // Active insights
    $client->insights()->init();
}

WhatsHelp_chat_appsero_init();
