<?php
/**
 * Plugin Name:       Subscription & Recurring Billing – Memberships, Invoices & Automated Payments
 * Plugin URI:        https://wpbillify.lucrativeit.com/
 * Description:       Enterprise subscription management for WordPress. Manage customers, branches, plans, subscriptions, and billing with Stripe, Manual, SSLCommerz, Razorpay, and PayPal. Staff and roles are available in the Pro add-on.
 * Version:           1.0.3
 * Requires at least: 6.2
 * Requires PHP:      7.4
 * Author:            Lucrativeit
 * Author URI:        https://lucrativeit.com
 * License:           GPL-2.0-or-later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       lucrativeit-subscription-recurring-billing
 * Domain Path:       /languages
 *
 * @package Lucrativeit_Subscription_Recurring_Billing
 */

// Abort if this file is called directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Plugin constants.
 */
define( 'LUCRSURE_VERSION', '1.0.3' );
define( 'LUCRSURE_PLUGIN_FILE', __FILE__ );
define( 'LUCRSURE_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
define( 'LUCRSURE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'LUCRSURE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'LUCRSURE_PLUGIN_SLUG', 'lucrativeit-subscription-recurring-billing' );

/**
 * Database table prefix helper used across the plugin.
 *
 * @return string The fully-qualified table base (e.g. wp_lucrsure_).
 */
function lucrsure_table_prefix() {
	global $wpdb;
	return $wpdb->prefix . 'lucrsure_';
}

/**
 * Fully-qualified plugin table name.
 *
 * @param string $table Table suffix (e.g. "customers").
 * @return string
 */
function lucrsure_table( $table ) {
	return lucrsure_table_prefix() . $table;
}

/**
 * Prepare a SQL query (supports %i identifiers on WordPress 6.2+).
 *
 * @param string $query SQL with placeholders.
 * @param mixed  ...$args Values for placeholders.
 * @return string|null
 */
function lucrsure_prepare_sql( $query, ...$args ) {
	global $wpdb;

	// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Placeholders are validated; table names use %i.
	return $wpdb->prepare( $query, ...$args );
}

/**
 * The code that runs during plugin activation.
 */
function lucrsure_activate_plugin() {
	require_once LUCRSURE_PLUGIN_DIR . 'includes/class-lucrsure-activator.php';
	LUCRSURE_Activator::activate();
}
register_activation_hook( __FILE__, 'lucrsure_activate_plugin' );

/**
 * The code that runs during plugin deactivation.
 */
function lucrsure_deactivate_plugin() {
	require_once LUCRSURE_PLUGIN_DIR . 'includes/class-lucrsure-deactivator.php';
	LUCRSURE_Deactivator::deactivate();
}
register_deactivation_hook( __FILE__, 'lucrsure_deactivate_plugin' );

/**
 * Bootstrap the plugin.
 */
require_once LUCRSURE_PLUGIN_DIR . 'includes/class-lucrsure-dependencies.php';
require_once LUCRSURE_PLUGIN_DIR . 'includes/class-lucrsure-plugin.php';

/**
 * Begin execution of the plugin.
 *
 * @return LUCRSURE_Plugin
 */
function lucrsure() {
	return LUCRSURE_Plugin::instance();
}

lucrsure();
