<?php
/**
 * ExcelTable for Elementor plugin main file.
 *
 * @package ExcelTableForElementor
 * Plugin Name: ExcelTable for Elementor
 * Plugin URI:        https://sightfactory.com/product/exceltable-for-elementor/
 * Description: An Elementor widget to display an Excel spreadsheet file.
 * Version: 1.0.8
 * Author: Sightfactory
 * Author URI:        https://profiles.wordpress.org/sightfactory/
 * License:           GPL-2.0+
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
 * Text Domain:       excel-to-elementor
 * Requires at least: 6.4
 * Requires PHP: 8.1
 * Requires Plugins: elementor
 * Elementor tested up to: 3.35.7
 * Elementor Pro tested up to: 3.35.1
 * Third Party:       PhpOffice/PhpSpreadsheet
 * Third Party URI:   https://phpspreadsheet.readthedocs.io/en/latest/
 * Third Party License: MIT
 * Third Party License URI: https://github.com/PHPOffice/PhpSpreadsheet/blob/master/LICENSE
 */

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

define( 'VWPETE_PLUGIN_DIR', trailingslashit( plugin_dir_path( __FILE__ ) ) );
define( 'VWPETE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'VWPETE_VERSION', '1.0.8' );
define( 'VWPETE_CACHE_PERIOD', 3600 ); // for future use to cache table 86400.
define( 'VWPETE_EXCEL_CACHE_PREFIX', 'vwpete_excel_table_' );

/**
 * Load PHPSpreadsheet library using Composer autoload.
 */
require VWPETE_PLUGIN_DIR . '/vendor/autoload.php';

/**
 * Register the Excel Table Elementor widget.
 *
 * @param \Elementor\Widgets_Manager $widgets_manager Elementor widgets manager instance.
 */
function vwpete_register_excel_widget( $widgets_manager ) {
	include_once VWPETE_PLUGIN_DIR . '/widgets/class-vwpete-exceltable-to-elementor-widget.php';
	$widgets_manager->register( new \VWPETE_ExcelTable_To_Elementor_Widget() );
}
add_action( 'elementor/widgets/register', 'vwpete_register_excel_widget' );


/**
 * Add custom query variable for Excel export functionality.
 *
 * @param array $vars Existing query variables.
 * @return array Modified query variables.
 */
function vwpete_register_query_vars( $vars ) {
	$vars[] = 'vwpete_excel_table_export_pdf';
	return $vars;
}
add_filter( 'query_vars', 'vwpete_register_query_vars' );

/**
 * Register and enqueue CSS dependencies for the widget.
 */
function vwpete_widgets_dependencies() {
	wp_register_style( 'vwpete-wp-widget-style', plugins_url( 'widget.css', __FILE__ ), array(), VWPETE_VERSION );
	wp_enqueue_style( 'vwpete-widget-style' );
}

add_action( 'admin_enqueue_scripts', 'vwpete_widgets_dependencies' );
