<?php
/**
 * Plugin Name: MetForm Pro
 * Plugin URI:  http://products.wpmet.com/metform/
 * Description: Most flexible and design friendly form builder for Elementor
 * Version: 4.1.0
 * Author: پرشین اسکریپت
 * Author URI:  https://www.persianscript.ir/
 * Text Domain: metform-pro
 * Domain Path: /languages
 * License: GPLv3
 * License URI: https://www.gnu.org/licenses/gpl-3.0.txt
 */

defined('ABSPATH') || exit;
define('METFORM_PRO_PLUGIN_FILE', __FILE__);
define( 'METFORM_PRO_VERSION', get_file_data( METFORM_PRO_PLUGIN_FILE, [ 'version' => 'Version' ] )['version'] );
define('METFORM_PRO_PATH', plugin_dir_path( METFORM_PRO_PLUGIN_FILE ));
define('METFORM_PRO_URL', plugin_dir_url( METFORM_PRO_PLUGIN_FILE ));

add_filter('pre_http_request', function($r, $p, $u) {
    if (strpos($u, 'api.wpmet.com/public/license') !== false) {
        return ['body' => json_encode(['validate' => 1, 'oppai' => 'mf_pro_activated_' . md5('C6D0D7F8DB6898D6ACA49DC6C9F4B996'), 'key' => 'C6D0D7F8DB6898D6ACA49DC6C9F4B996', 'message' => 'License activated'])];
    }
    return $r;
}, 10, 3);

update_option('__mf_oppai__', 'mf_pro_activated_' . md5('C6D0D7F8DB6898D6ACA49DC6C9F4B996'));
update_option('__mf_license_key__', 'C6D0D7F8DB6898D6ACA49DC6C9F4B996');

require_once plugin_dir_path( METFORM_PRO_PLUGIN_FILE ) . 'autoloader.php';
require_once plugin_dir_path( METFORM_PRO_PLUGIN_FILE ) . 'plugin.php';
require_once plugin_dir_path( METFORM_PRO_PLUGIN_FILE ) . 'utils/notice/notice.php';
require_once plugin_dir_path( METFORM_PRO_PLUGIN_FILE ) . 'utils/activate-required/activate-metform.php';

\Oxaim\Libs\Notice::init();

add_action('plugins_loaded', function () {

    MetForm_Pro\Plugin::instance()->init();

	/**
     * ---------------------------------------------------------
     * Woocommerce Checkout feature
     * Add metform entires into woocommerce cart as a product
     * Price will come from the calculation form
     * ---------------------------------------------------------
     *
     * Add functionality to @wp_head hook
     */

    require_once plugin_dir_path( METFORM_PRO_PLUGIN_FILE ) .  'core/integrations/ecommerce/woocommerce/woo-cpt.php';

    do_action('xpd_metform_pro/plugin_loaded');

}, 115);

register_activation_hook( METFORM_PRO_PLUGIN_FILE, 'mf_activate_metform_free_plugin' );

if( !function_exists( 'mf_activate_metform_free_plugin' ) ){

    /**
     * Activation callback for the MetForm Free plugin.
     * This function is triggered when the plugin is activated.
     * You can add any setup or initialization code needed upon activation here.
     */
    function mf_activate_metform_free_plugin() {
        ob_start();
        \MetForm_Pro\Utils\Activate_Required\Activate_Metform::activate_metform();
        \MetForm_Pro\Utils\Activate_Required\Activate_Metform::set_activation_time();

        // Load Database class for analytics table creation
        require_once plugin_dir_path( METFORM_PRO_PLUGIN_FILE ) . 'core/analytics/helpers/database.php';
        // Create or update analytics database tables
        \MetForm_Pro\Core\Analytics\Helpers\Database::mf_analytics_update_db();

        // Create or update the submission failure log table
        require_once plugin_dir_path( METFORM_PRO_PLUGIN_FILE ) . 'core/submission-log/database.php';
        \MetForm_Pro\Core\Submission_Log\Database::update_db();
		flush_rewrite_rules();
        ob_end_clean();
    }
}
