-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwoo-nota-fiscal-for-assas.php
93 lines (80 loc) · 3.1 KB
/
woo-nota-fiscal-for-assas.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* Plugin Name: Nota Fiscal for Asaas
* Description: Integração do WooCommerce com o Asaas para emissão automática de Nota Fiscal.
* Version: 1.0.2
* Requires at least: 6.5
* Requires PHP: 7.4
* Author: DynoWP
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: nota-fiscal-for-asaas
* Requires Plugins: woocommerce
* Tested up to: WordPress 6.6.2
* WooCommerce tested up to: 9.3.1
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Define the absolute path to the plugin directory
define( 'NF_ASAAS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
// Autoload classes using the PSR-4 standard
spl_autoload_register( function ( $class ) {
$prefix = 'NotaFiscalForAsaas\\';
$base_dirs = [
__DIR__ . '/src/',
__DIR__ . '/app/'
];
$len = strlen( $prefix );
if ( strncmp( $prefix, $class, $len ) !== 0 ) {
return;
}
$relative_class = substr( $class, $len );
foreach ( $base_dirs as $base_dir ) {
$file = $base_dir . str_replace( '\\', '/', $relative_class ) . '.php';
if ( file_exists( $file ) ) {
require $file;
return;
}
}
} );
// Initialize the plugin components
function nf_asaas_init() {
// Load plugin options
$options = get_option( 'nf_asaas_options', array() );
$enable_logging = isset( $options['enable_logging'] ) && $options['enable_logging'] === '1';
$access_token = isset( $options['api_key'] ) ? $options['api_key'] : '';
// Check if the access token is configured
if ( empty( $access_token ) ) {
// Optional: Add an error message or notify the admin
add_action( 'admin_notices', 'nfa_missing_access_token_notice' );
return;
}
// Initialize plugin settings
if ( class_exists( 'NotaFiscalForAsaas\Admin\SettingsPage' ) ) {
$settings = new NotaFiscalForAsaas\Admin\SettingsPage();
$settings->init();
}
// Initialize the order invoice menu
if ( class_exists( 'NotaFiscalForAsaas\Admin\OrderInvoiceMenu' ) ) {
$order_invoice_menu = new NotaFiscalForAsaas\Admin\OrderInvoiceMenu();
$order_invoice_menu->init();
}
// Initialize WooCommerce hooks for customer updates
if ( class_exists( 'NotaFiscalForAsaas\Hooks\UpdateCustomerHooks' ) ) {
$update_customer_hooks = new NotaFiscalForAsaas\Hooks\UpdateCustomerHooks( $access_token, $enable_logging );
$update_customer_hooks->init();
}
// Initialize WooCommerce hooks for invoice emission
if ( class_exists( 'NotaFiscalForAsaas\Hooks\EmitInvoiceHooks' ) ) {
$emit_invoice_hooks = new NotaFiscalForAsaas\Hooks\EmitInvoiceHooks( $access_token, $enable_logging );
$emit_invoice_hooks->init();
}
}
add_action( 'init', 'nf_asaas_init' );
// Add an error notification if the access token is not configured
function nfa_missing_access_token_notice() {
echo '<div class="error"><p>';
echo 'O plugin Nota Fiscal for Asaas está ativo, mas a chave de API (access token) não está configurada. Por favor, configure-a nas configurações do plugin.';
echo '</p></div>';
}