| 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.1.2 |
| 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: 6.8 |
| 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 |
// Define plugin constants. |
| 27 |
define( 'EASY_INVOICE_VERSION', '2.1.2' ); |
| 28 |
define( 'EASY_INVOICE_PLUGIN_FILE', __FILE__ ); |
| 29 |
define( 'EASY_INVOICE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
| 30 |
define( 'EASY_INVOICE_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); |
| 31 |
|
| 32 |
// Load composer autoloader if it exists. |
| 33 |
if ( file_exists( EASY_INVOICE_PLUGIN_DIR . 'vendor/autoload.php' ) ) { |
| 34 |
require_once EASY_INVOICE_PLUGIN_DIR . 'vendor/autoload.php'; |
| 35 |
} |
| 36 |
|
| 37 |
// Include standalone function files (not autoloaded by Composer) |
| 38 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Helpers/NotificationHelper.php'; |
| 39 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Admin/Helpers/Utility.php'; |
| 40 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Helpers/GeneralHelper.php'; |
| 41 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Helpers/ToastHelper.php'; |
| 42 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Helpers/TaxHelper.php'; |
| 43 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Helpers/FormattingHelper.php'; |
| 44 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Helpers/EmailHelper.php'; |
| 45 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Helpers/EnqueueHelper.php'; |
| 46 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Helpers/PdfHelper.php'; |
| 47 |
require_once EASY_INVOICE_PLUGIN_DIR . 'includes/Helpers/QuoteInvoiceHelper.php'; |
| 48 |
|
| 49 |
/** |
| 50 |
* Initialize the plugin. |
| 51 |
* |
| 52 |
* @since 1.0.0 |
| 53 |
* @return void |
| 54 |
*/ |
| 55 |
function easy_invoice_init() { |
| 56 |
// Initialize the main plugin class. |
| 57 |
$plugin = \EasyInvoice\EasyInvoice::getInstance(); |
| 58 |
$plugin->init(); |
| 59 |
|
| 60 |
// Initialize service providers. |
| 61 |
$invoice_service_provider = new \EasyInvoice\Providers\InvoiceServiceProvider(); |
| 62 |
$invoice_service_provider->register(); |
| 63 |
|
| 64 |
$invoice_item_service_provider = new \EasyInvoice\Providers\InvoiceItemServiceProvider(); |
| 65 |
$invoice_item_service_provider->register(); |
| 66 |
|
| 67 |
$client_service_provider = new \EasyInvoice\Providers\ClientServiceProvider(); |
| 68 |
$client_service_provider->register(); |
| 69 |
|
| 70 |
$invoice_number_service_provider = new \EasyInvoice\Providers\InvoiceNumberServiceProvider(); |
| 71 |
$invoice_number_service_provider->register(); |
| 72 |
|
| 73 |
$quote_number_service_provider = new \EasyInvoice\Providers\QuoteNumberServiceProvider(); |
| 74 |
$quote_number_service_provider->register(); |
| 75 |
|
| 76 |
$quote_service_provider = new \EasyInvoice\Providers\QuoteServiceProvider(); |
| 77 |
$quote_service_provider->register(); |
| 78 |
|
| 79 |
// Initialize EmailManager |
| 80 |
$email_manager = \EasyInvoice\Services\EmailManager::getInstance(); |
| 81 |
|
| 82 |
// Initialize form manager |
| 83 |
//$form_manager = \EasyInvoice\Forms\FormManager::getInstance(); |
| 84 |
// $form_manager->setInvoiceNumberServiceProvider($invoice_number_service_provider); |
| 85 |
|
| 86 |
// Initialize controllers. |
| 87 |
$payment_controller = new \EasyInvoice\Controllers\PaymentController(); |
| 88 |
$payment_controller->init(); |
| 89 |
|
| 90 |
$settings_controller = new \EasyInvoice\Controllers\SettingsController(); |
| 91 |
$settings_controller->init(); |
| 92 |
|
| 93 |
$quote_controller = new \EasyInvoice\Controllers\QuoteController(); |
| 94 |
$quote_controller->init(); |
| 95 |
|
| 96 |
// Initialize shortcode manager |
| 97 |
$shortcode_manager = new \EasyInvoice\Shortcodes\ShortcodeManager(); |
| 98 |
|
| 99 |
} |
| 100 |
add_action( 'init', 'easy_invoice_init' ); |
| 101 |
|
| 102 |
/** |
| 103 |
* Handle payment gateway logging |
| 104 |
*/ |
| 105 |
function easy_invoice_payment_gateway_log_handler($message, $level, $gateway_name) { |
| 106 |
$log_message = sprintf('[%s] Easy Invoice %s Gateway: %s', |
| 107 |
date('Y-m-d H:i:s'), |
| 108 |
ucfirst($gateway_name), |
| 109 |
$message |
| 110 |
); |
| 111 |
|
| 112 |
if (defined('WP_DEBUG') && WP_DEBUG) { |
| 113 |
error_log($log_message); |
| 114 |
} |
| 115 |
} |
| 116 |
add_action('easy_invoice_payment_gateway_log', 'easy_invoice_payment_gateway_log_handler', 10, 3); |
| 117 |
|
| 118 |
// Initialize migration system |
| 119 |
if ( class_exists( 'EasyInvoice\Migration\MigrationInit' ) ) { |
| 120 |
|
| 121 |
EasyInvoice\Migration\MigrationInit::init(); |
| 122 |
} |
| 123 |
/** |
| 124 |
* Register post types early to ensure they're available |
| 125 |
*/ |
| 126 |
function easy_invoice_register_post_types() { |
| 127 |
// Initialize the main plugin class and register post types |
| 128 |
$plugin = \EasyInvoice\EasyInvoice::getInstance(); |
| 129 |
$plugin->registerPostTypes(); |
| 130 |
$plugin->registerCustomStatuses(); |
| 131 |
} |
| 132 |
add_action( 'init', 'easy_invoice_register_post_types', 0 ); // Priority 0 to run early |
| 133 |
|
| 134 |
/** |
| 135 |
* Load textdomain early to avoid translation loading warnings. |
| 136 |
* |
| 137 |
* @since 1.0.0 |
| 138 |
* @return void |
| 139 |
*/ |
| 140 |
function easy_invoice_load_textdomain() { |
| 141 |
load_plugin_textdomain('easy-invoice', false, dirname(plugin_basename(__FILE__)) . '/languages'); |
| 142 |
} |
| 143 |
add_action( 'init', 'easy_invoice_load_textdomain', 1 ); |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
/** |
| 150 |
* Plugin activation hook. |
| 151 |
* |
| 152 |
* @since 1.0.0 |
| 153 |
* @return void |
| 154 |
*/ |
| 155 |
register_activation_hook( __FILE__, 'easy_invoice_activate' ); |
| 156 |
function easy_invoice_activate() { |
| 157 |
// Initialization of post types so rewrite rules can be flushed properly. |
| 158 |
\EasyInvoice\EasyInvoice::getInstance()->registerPostTypes(); |
| 159 |
|
| 160 |
// Initialize default settings |
| 161 |
$settings_controller = new \EasyInvoice\Controllers\SettingsController(); |
| 162 |
$settings_controller->initializeSettings(); |
| 163 |
|
| 164 |
// Record first install timestamp (do not overwrite if it already exists) |
| 165 |
if (!get_option('easy_invoice_installed')) { |
| 166 |
update_option('easy_invoice_installed', current_time('mysql')); |
| 167 |
} |
| 168 |
|
| 169 |
// Check if this is a fresh installation or an upgrade |
| 170 |
$stored_version = get_option('easy_invoice_version', ''); |
| 171 |
|
| 172 |
// If no version is stored, this is a fresh installation |
| 173 |
if (empty($stored_version)) { |
| 174 |
update_option('easy_invoice_version', EASY_INVOICE_VERSION); |
| 175 |
update_option('easy_invoice_migration_completed', true); |
| 176 |
} else { |
| 177 |
// This is an upgrade. Do NOT bump version here; migration will set it when completed. |
| 178 |
} |
| 179 |
|
| 180 |
// Flush rewrite rules. |
| 181 |
flush_rewrite_rules(); |
| 182 |
} |
| 183 |
|
| 184 |
/** |
| 185 |
* Plugin deactivation hook. |
| 186 |
* |
| 187 |
* @since 1.0.0 |
| 188 |
* @return void |
| 189 |
*/ |
| 190 |
register_deactivation_hook( __FILE__, 'easy_invoice_deactivate' ); |
| 191 |
function easy_invoice_deactivate() { |
| 192 |
// Flush rewrite rules. |
| 193 |
flush_rewrite_rules(); |
| 194 |
|
| 195 |
// Clear scheduled events |
| 196 |
\EasyInvoice\Services\QuoteExpirationService::clear_schedule(); |
| 197 |
} |
| 198 |
|
| 199 |
/** |
| 200 |
* Toast notification helper functions |
| 201 |
*/ |
| 202 |
|
| 203 |
|