-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbootstrap.php
More file actions
146 lines (126 loc) · 3.36 KB
/
bootstrap.php
File metadata and controls
146 lines (126 loc) · 3.36 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
use NewfoldLabs\WP\Module\Data\Data;
use NewfoldLabs\WP\Module\Data\EventQueue\Queues\BatchQueue;
use NewfoldLabs\WP\Module\Data\Helpers\Encryption;
use NewfoldLabs\WP\Module\Data\Helpers\Transient;
use NewfoldLabs\WP\Module\Data\SiteCapabilities;
use NewfoldLabs\WP\ModuleLoader\Container;
use WP_Forge\UpgradeHandler\UpgradeHandler;
use function NewfoldLabs\WP\ModuleLoader\container;
use function NewfoldLabs\WP\ModuleLoader\register as registerModule;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
return;
}
// Do not allow multiple copies of the module to be active
if ( defined( 'NFD_DATA_MODULE_VERSION' ) ) {
return;
}
define( 'NFD_DATA_MODULE_VERSION', '2.9.3' );
if ( ! function_exists( 'nfd_create_event_queue_table' ) ) {
/**
* Create the event queue table
*/
function nfd_create_event_queue_table() {
BatchQueue::create_table();
}
}
if ( ! function_exists( 'nfd_drop_event_queue_table' ) ) {
/**
* Drop the event queue table
*/
function nfd_drop_event_queue_table() {
global $wpdb;
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}nfd_data_event_queue" );
}
}
if ( function_exists( 'is_admin' ) && is_admin() ) {
$upgrade_handler = new UpgradeHandler(
__DIR__ . '/upgrades',
get_option( 'nfd_data_module_version' ),
NFD_DATA_MODULE_VERSION
);
if ( $upgrade_handler->maybe_upgrade() ) {
// If an upgrade occurred, update the new version in the database to prevent running the routine(s) again.
update_option( 'nfd_data_module_version', NFD_DATA_MODULE_VERSION, true );
}
}
/**
* Register the data module
*/
if ( function_exists( 'add_action' ) && function_exists( 'add_filter' ) ) {
add_action(
'plugins_loaded',
function () {
registerModule(
array(
'name' => 'data',
'label' => __( 'Data', 'newfold-data-module' ),
'callback' => function ( Container $container ) {
$module = new Data( $container->plugin() );
$module->start();
},
'isActive' => true,
'isHidden' => true,
)
);
}
);
// Auto-encrypt token on save.
add_filter(
'pre_update_option_nfd_data_token',
function ( $value ) {
return ( new Encryption() )->encrypt( $value );
}
);
// Auto-decrypt token when fetched
add_filter(
'option_nfd_data_token',
function ( $value ) {
return ( new Encryption() )->decrypt( $value );
}
);
// Temporary filter, as the migrate capability isn't working as expected.
add_filter(
'pre_set_transient_nfd_site_capabilities',
function ( $transient ) {
if ( empty( $transient ) && 'bluehost' === container()->plugin()->brand ) {
return array(
'canMigrateSite' => true,
'hasAISiteGen' => true,
);
}
return $transient;
},
10,
2
);
// Register activation/deactivation hooks
add_action(
'newfold_container_set',
function ( Container $container ) {
register_activation_hook(
$container->plugin()->file,
function () use ( $container ) {
nfd_create_event_queue_table();
Transient::set( 'nfd_plugin_activated', $container->plugin()->basename );
}
);
register_deactivation_hook(
$container->plugin()->file,
function () use ( $container ) {
delete_option( 'nfd_data_module_version' );
nfd_drop_event_queue_table();
}
);
$container->set(
'capabilities',
$container->service(
function () {
return new SiteCapabilities();
}
)
);
}
);
}