<?php
/**
 * Plugin Name: Button Voodoo v2
 * Plugin URI : https://EzLinkTools.Com
 * Description: Button Voodoo v2 is an awesome tool created by EzLinkTools.Com.
 * Version: 2.1.1
 * Author: EzLinkTools
 * Author URI: https://EzLinkTools.Com
 *
 *
 *
 * Filename: button-voodoo-v2.php
 * Created : EzLinkTools.Com <marcus@blogprofitnetwork.com> (https://EzLinkTools.Com)
 * Copyright 2020 - EzLinkTools.Com <marcus@blogprofitnetwork.com> (https://EzLinkTools.Com)
 */
define ('_IN_MAIN_MODULE', 1);

include_once ('config.local.php');
include_once ('lib/_database.php');
include_once ('lib/_pages.php');
include_once ('lib/_metaboxes.php');
include_once ('lib/_shortcodes.php');
include_once ('lib/_widgets.php');
include_once ('lib/_helpers.php');
include_once ('lib/_init.admin.php');
include_once ('lib/_init.frontend.php');

//* init variables
$buttonVoodooDatabase	= new buttonVoodooDatabase();
$buttonVoodooHelpers  	= new buttonVoodooHelpers();
$buttonVoodooWidgets	= new buttonVoodooWidgets();

//* hooks for table installation / uninstallation
register_activation_hook(__FILE__, array($buttonVoodooDatabase, 'install'));
register_deactivation_hook(__FILE__, array($buttonVoodooDatabase, 'uninstall'));

//* register widgets
add_action('widgets_init', array($buttonVoodooWidgets, 'init'));

//* ajax requests
add_action('wp_ajax_'. BUTTONVOODOO_CODE .'-update-settings', array($buttonVoodooDatabase, 'updateSettings'));
add_action('wp_ajax_'. BUTTONVOODOO_CODE .'-add-group', array($buttonVoodooDatabase, 'addGroup'));
add_action('wp_ajax_'. BUTTONVOODOO_CODE .'-update-group-status', array($buttonVoodooDatabase, 'updateGroupStatus'));
add_action('wp_ajax_'. BUTTONVOODOO_CODE .'-reset-group-stat', array($buttonVoodooDatabase, 'resetGroupStat'));
add_action('wp_ajax_'. BUTTONVOODOO_CODE .'-delete-group', array($buttonVoodooDatabase, 'deleteGroup'));
add_action('wp_ajax_'. BUTTONVOODOO_CODE .'-update-group', array($buttonVoodooDatabase, 'updateGroup'));
add_action('wp_ajax_'. BUTTONVOODOO_CODE .'-add-button', array($buttonVoodooDatabase, 'addButton'));
add_action('wp_ajax_'. BUTTONVOODOO_CODE .'-delete-button', array($buttonVoodooDatabase, 'deleteButton'));
add_action('wp_ajax_'. BUTTONVOODOO_CODE .'-update-button-status', array($buttonVoodooDatabase, 'updateButtonStatus'));
add_action('wp_ajax_'. BUTTONVOODOO_CODE .'-reset-button-stat', array($buttonVoodooDatabase, 'resetButtonStat'));
add_action('wp_ajax_'. BUTTONVOODOO_CODE .'-update-button', array($buttonVoodooDatabase, 'updateButton'));
add_action('wp_ajax_'. BUTTONVOODOO_CODE .'-update-button-sort', array($buttonVoodooDatabase, 'updateButtonSort'));


add_action('wp', 'parseButtonUrlRequest');
function parseButtonUrlRequest() {
	global $buttonVoodooDatabase;

	$buttonid 	= intval($_GET[BUTTONVOODOO_CODE]);
	if ($buttonid > 0) {
		$button = $buttonVoodooDatabase->getButtonById($buttonid);
		if (0 != count($button)) {
			$buttonVoodooDatabase->addButtonClick($buttonid);

			wp_redirect($button['url']);
			exit();
		}
	}
}