<?php
/**
 * The plugin bootstrap file.
 *
 * This file is read by WordPress to generate the plugin information in the plugin
 * admin area. This file also includes all dependencies used by the plugin,
 * registers activation and deactivation hooks, and starts the plugin.
 *
 * @link              https://registrationformbuilder.com
 * @since             1.0.0
 * @package           Vedrixa_Forms
 *
 * @wordpress-plugin
 * Plugin Name:       Vedrixa Forms - Contact & Registration Form Builder
 * Plugin URI:        https://registrationformbuilder.com
 * Description:       Drag-and-drop WordPress form builder to create contact forms, registration forms, and custom forms with email notifications and submission management.
 * Version:           1.2.0
 * Author:            Vedrixa
 * Author URI:        https://vedrixa.com
 * License:           GPL-2.0-or-later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       vedrixa-forms-registration-builder
 * Domain Path:       /languages
 * Requires at least: 5.8
 * Requires PHP:      7.4
 */

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
	die;
}

define( 'WPEFB_PLUGIN_FILE', __FILE__ );
define( 'WPEFB_PLUGIN_VERSION', '1.2.0' );
define( 'WPEFB_DB_VERSION', 1.0 );
/**
 * The code that runs during plugin activation.
 * This action is documented in includes/class-registration-form-builder-activator.php
 */
function wpefb_activate_plugin( $network_wide = false ) {

	require_once plugin_dir_path( __FILE__ ) . 'includes/class-registration-form-builder-activator.php';
	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wpefb-sanitizer.php';
	add_option( 'wpefb_db_version', WPEFB_DB_VERSION );
	$wefb_activator = new Registration_Form_Builder_Activator();
	$wefb_activator->activate( is_multisite() && (bool) $network_wide );
}
/**
 * The code that runs during plugin deactivation.
 * This action is documented in includes/class-registration-form-builder-deactivator.php
 */
function wpefb_deactivate_plugin() {
	require_once plugin_dir_path( __FILE__ ) . 'includes/class-registration-form-builder-deactivator.php';

	$wefb_deactivator = new Registration_Form_Builder_Deactivator();
	$wefb_deactivator->deactivate();
}

register_activation_hook( __FILE__, 'wpefb_activate_plugin' );
register_deactivation_hook( __FILE__, 'wpefb_deactivate_plugin' );

/**
 * Create plugin tables for newly created multisite blogs when plugin is network active.
 *
 * @param int $blog_id New blog ID.
 */
function wpefb_create_tables_for_new_blog( $blog_id ) {
	if ( ! is_multisite() ) {
		return;
	}

	$active_network_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
	$plugin_basename        = plugin_basename( WPEFB_PLUGIN_FILE );
	if ( ! isset( $active_network_plugins[ $plugin_basename ] ) ) {
		return;
	}

	require_once plugin_dir_path( __FILE__ ) . 'includes/class-registration-form-builder-activator.php';
	switch_to_blog( (int) $blog_id );
	$wefb_activator = new Registration_Form_Builder_Activator();
	$wefb_activator->create_table();
	restore_current_blog();
}
add_action( 'wpmu_new_blog', 'wpefb_create_tables_for_new_blog', 10, 1 );

/**
 * The core plugin class that is used to define internationalization,
 * admin-specific hooks, and public-facing site hooks.
 */
require plugin_dir_path( __FILE__ ) . 'includes/class-registration-form-builder.php';

/**
 * Begins execution of the plugin.
 *
 * Since everything within the plugin is registered via hooks,
 * then kicking off the plugin from this point in the file does
 * not affect the page life cycle.
 *
 * @since    1.0.0
 */
function wpefb_run_plugin() {

	$plugin = new Registration_Form_Builder();
	$plugin->run();

}
wpefb_run_plugin();
