| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Easy Invoice |
| 4 |
* Plugin URI: https://matrixaddons.com/plugins/easy-invoice |
| 5 |
* Description: A beautiful, full-featured invoicing solution for WordPress. Create professional invoices, quotes, and manage payments with ease. |
| 6 |
* Version: 2.3.3 |
| 7 |
* Author: MatrixAddons |
| 8 |
* Author URI: https://matrixaddons.com |
| 9 |
* License: GPL v2 or later |
| 10 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 11 |
* Text Domain: easy-invoice |
| 12 |
* Domain Path: /languages |
| 13 |
* Requires at least: 5.6 |
| 14 |
* Tested up to: 7.0 |
| 15 |
* Requires PHP: 7.4 |
| 16 |
* Network: false |
| 17 |
* |
| 18 |
* @package EasyInvoice |
| 19 |
*/ |
| 20 |
|
| 21 |
// Exit if accessed directly. |
| 22 |
if ( ! defined( 'ABSPATH' ) ) { |
| 23 |
exit; |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
// Define plugin constants. |
| 28 |
define( 'EASY_INVOICE_VERSION', '2.3.3' ); |
| 29 |
define( 'EASY_INVOICE_PLUGIN_FILE', __FILE__ ); |
| 30 |
define( 'EASY_INVOICE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
| 31 |
define( 'EASY_INVOICE_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); |
| 32 |
|
| 33 |
// Load composer autoloader if it exists. |
| 34 |
if ( file_exists( EASY_INVOICE_PLUGIN_DIR . 'vendor/autoload.php' ) ) { |
| 35 |
require_once EASY_INVOICE_PLUGIN_DIR . 'vendor/autoload.php'; |
| 36 |
} |
| 37 |
|
| 38 |
// Include standalone function files (not autoloaded by Composer) |
| 39 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Helpers/NotificationHelper.php'; |
| 40 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Admin/Helpers/Utility.php'; |
| 41 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Helpers/GeneralHelper.php'; |
| 42 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Helpers/ToastHelper.php'; |
| 43 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Helpers/CapabilityHelper.php'; |
| 44 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Helpers/AuditHelper.php'; |
| 45 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Helpers/AutoloadOptimizer.php'; |
| 46 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Helpers/BrandHelper.php'; |
| 47 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Helpers/TaxHelper.php'; |
| 48 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Helpers/FormattingHelper.php'; |
| 49 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Helpers/EmailHelper.php'; |
| 50 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Helpers/EnqueueHelper.php'; |
| 51 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Helpers/PdfHelper.php'; |
| 52 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Helpers/QuoteInvoiceHelper.php'; |
| 53 |
|
| 54 |
// Addons system — Free plugin owns the listing UI + license gate; |
| 55 |
// Pro plugin owns the executable addon code. |
| 56 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Addons/LicensePlanResolver.php'; |
| 57 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Addons/AddonRegistry.php'; |
| 58 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Addons/AddonManager.php'; |
| 59 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Addons/ProAddonMigration.php'; |
| 60 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Controllers/AddonsController.php'; |
| 61 |
|
| 62 |
// Register the Pro→addon migration. Only fires inside admin (admin_init |
| 63 |
// hook), only when Pro is active, only once per MIGRATION_VERSION bump. |
| 64 |
\EasyInvoice\Addons\ProAddonMigration::register(); |
| 65 |
|
| 66 |
/** |
| 67 |
* Initialize the plugin. |
| 68 |
* |
| 69 |
* @since 1.0.0 |
| 70 |
* @return void |
| 71 |
*/ |
| 72 |
function easy_invoice_init() { |
| 73 |
// Initialize the main plugin class. |
| 74 |
$plugin = \EasyInvoice\EasyInvoice::getInstance(); |
| 75 |
$plugin->init(); |
| 76 |
|
| 77 |
// Initialize service providers. |
| 78 |
$invoice_service_provider = new \EasyInvoice\Providers\InvoiceServiceProvider(); |
| 79 |
$invoice_service_provider->register(); |
| 80 |
|
| 81 |
$invoice_item_service_provider = new \EasyInvoice\Providers\InvoiceItemServiceProvider(); |
| 82 |
$invoice_item_service_provider->register(); |
| 83 |
|
| 84 |
$client_service_provider = new \EasyInvoice\Providers\ClientServiceProvider(); |
| 85 |
$client_service_provider->register(); |
| 86 |
|
| 87 |
$invoice_number_service_provider = new \EasyInvoice\Providers\InvoiceNumberServiceProvider(); |
| 88 |
$invoice_number_service_provider->register(); |
| 89 |
|
| 90 |
$quote_number_service_provider = new \EasyInvoice\Providers\QuoteNumberServiceProvider(); |
| 91 |
$quote_number_service_provider->register(); |
| 92 |
|
| 93 |
$quote_service_provider = new \EasyInvoice\Providers\QuoteServiceProvider(); |
| 94 |
$quote_service_provider->register(); |
| 95 |
|
| 96 |
// Initialize EmailManager |
| 97 |
$email_manager = \EasyInvoice\Services\EmailManager::getInstance(); |
| 98 |
|
| 99 |
// Initialize controllers. |
| 100 |
$payment_controller = new \EasyInvoice\Controllers\PaymentController(); |
| 101 |
$payment_controller->init(); |
| 102 |
|
| 103 |
$settings_controller = new \EasyInvoice\Controllers\SettingsController(); |
| 104 |
$settings_controller->init(); |
| 105 |
|
| 106 |
$quote_controller = new \EasyInvoice\Controllers\QuoteController(); |
| 107 |
$quote_controller->init(); |
| 108 |
|
| 109 |
// Initialize shortcode manager |
| 110 |
$shortcode_manager = new \EasyInvoice\Shortcodes\ShortcodeManager(); |
| 111 |
|
| 112 |
// Initialize review notice service |
| 113 |
\EasyInvoice\Services\ReviewNoticeService::init(); |
| 114 |
|
| 115 |
// Initialize promotion service |
| 116 |
\EasyInvoice\Services\PromotionService::init(); |
| 117 |
|
| 118 |
// Initialize Addons controller (admin page + AJAX toggle) |
| 119 |
(new \EasyInvoice\Controllers\AddonsController())->init(); |
| 120 |
|
| 121 |
do_action('easy_invoice_loaded'); |
| 122 |
|
| 123 |
} |
| 124 |
add_action( 'init', 'easy_invoice_init' ); |
| 125 |
|
| 126 |
/** |
| 127 |
* Handle payment gateway logging |
| 128 |
*/ |
| 129 |
function easy_invoice_payment_gateway_log_handler($message, $level, $gateway_name) { |
| 130 |
$log_message = sprintf('[%s] Easy Invoice %s Gateway: %s', |
| 131 |
date('Y-m-d H:i:s'), |
| 132 |
ucfirst($gateway_name), |
| 133 |
$message |
| 134 |
); |
| 135 |
|
| 136 |
if (defined('WP_DEBUG') && WP_DEBUG) { |
| 137 |
error_log($log_message); |
| 138 |
} |
| 139 |
} |
| 140 |
add_action('easy_invoice_payment_gateway_log', 'easy_invoice_payment_gateway_log_handler', 10, 3); |
| 141 |
|
| 142 |
// Initialize migration system |
| 143 |
if ( class_exists( 'EasyInvoice\Migration\MigrationInit' ) ) { |
| 144 |
|
| 145 |
EasyInvoice\Migration\MigrationInit::init(); |
| 146 |
} |
| 147 |
/** |
| 148 |
* Register post types early to ensure they're available |
| 149 |
*/ |
| 150 |
function easy_invoice_register_post_types() { |
| 151 |
// Initialize the main plugin class and register post types |
| 152 |
$plugin = \EasyInvoice\EasyInvoice::getInstance(); |
| 153 |
$plugin->registerPostTypes(); |
| 154 |
$plugin->registerCustomStatuses(); |
| 155 |
} |
| 156 |
add_action( 'init', 'easy_invoice_register_post_types', 0 ); // Priority 0 to run early |
| 157 |
|
| 158 |
/** |
| 159 |
* Load textdomain early to avoid translation loading warnings. |
| 160 |
* |
| 161 |
* @since 1.0.0 |
| 162 |
* @return void |
| 163 |
*/ |
| 164 |
function easy_invoice_load_textdomain() { |
| 165 |
load_plugin_textdomain('easy-invoice', false, dirname(plugin_basename(__FILE__)) . '/languages'); |
| 166 |
} |
| 167 |
add_action( 'init', 'easy_invoice_load_textdomain', 1 ); |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
/** |
| 174 |
* Plugin activation hook. |
| 175 |
* |
| 176 |
* @since 1.0.0 |
| 177 |
* @return void |
| 178 |
*/ |
| 179 |
register_activation_hook( __FILE__, 'easy_invoice_activate' ); |
| 180 |
function easy_invoice_activate() { |
| 181 |
// Initialization of post types so rewrite rules can be flushed properly. |
| 182 |
\EasyInvoice\EasyInvoice::getInstance()->registerPostTypes(); |
| 183 |
|
| 184 |
// Initialize default settings |
| 185 |
$settings_controller = new \EasyInvoice\Controllers\SettingsController(); |
| 186 |
$settings_controller->initializeSettings(); |
| 187 |
|
| 188 |
// Record first install timestamp (do not overwrite if it already exists) |
| 189 |
if (!get_option('easy_invoice_installed')) { |
| 190 |
update_option('easy_invoice_installed', current_time('mysql')); |
| 191 |
} |
| 192 |
|
| 193 |
// Check if this is a fresh installation or an upgrade |
| 194 |
$stored_version = get_option('easy_invoice_version', ''); |
| 195 |
|
| 196 |
// If no version is stored, this is a fresh installation |
| 197 |
if (empty($stored_version)) { |
| 198 |
update_option('easy_invoice_version', EASY_INVOICE_VERSION); |
| 199 |
update_option('easy_invoice_migration_completed', true); |
| 200 |
} else { |
| 201 |
// This is an upgrade. Do NOT bump version here; migration will set it when completed. |
| 202 |
} |
| 203 |
|
| 204 |
// Flush rewrite rules. |
| 205 |
flush_rewrite_rules(); |
| 206 |
} |
| 207 |
|
| 208 |
/** |
| 209 |
* Plugin deactivation hook. |
| 210 |
* |
| 211 |
* @since 1.0.0 |
| 212 |
* @return void |
| 213 |
*/ |
| 214 |
register_deactivation_hook( __FILE__, 'easy_invoice_deactivate' ); |
| 215 |
function easy_invoice_deactivate() { |
| 216 |
// Flush rewrite rules. |
| 217 |
flush_rewrite_rules(); |
| 218 |
|
| 219 |
// Clear scheduled events |
| 220 |
\EasyInvoice\Services\QuoteExpirationService::clear_schedule(); |
| 221 |
} |
| 222 |
|
| 223 |
/** |
| 224 |
* Toast notification helper functions |
| 225 |
*/ |
| 226 |
|
| 227 |
|