generated from Pierre-Lannoy/wp-plugin-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdecalog.php
184 lines (175 loc) · 4.92 KB
/
decalog.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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
/**
* Main plugin file.
*
* @package Bootstrap
* @author Pierre Lannoy <https://pierre.lannoy.fr/>.
* @since 1.0.0
*
* @wordpress-plugin
* Plugin Name: DecaLog
* Plugin URI: https://perfops.one/decalog
* Description: Capture and log events, metrics and traces on your site. Make WordPress observable – finally!
* Version: 4.3.1
* Requires at least: 6.2
* Requires PHP: 8.1
* Author: Pierre Lannoy / PerfOps One
* Author URI: https://perfops.one
* License: GPLv3
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: decalog
* Network: true
* Domain Path: /languages
*/
if ( ! defined( 'WPINC' ) ) {
die;
}
require_once __DIR__ . '/init.php';
require_once __DIR__ . '/functions.php';
require_once __DIR__ . '/includes/system/class-option.php';
require_once __DIR__ . '/includes/system/class-environment.php';
require_once __DIR__ . '/autoload.php';
require_once __DIR__ . '/includes/libraries/class-libraries.php';
require_once __DIR__ . '/includes/libraries/autoload.php';
require_once __DIR__ . '/includes/libraries/guzzlehttp/functions_include.php';
/**
* Copy the file responsible to early initialization in mu-plugins and drop-ins dir.
*
* @since 2.4.0
*/
function decalog_check_earlyloading() {
if ( (bool) get_site_option( 'decalog_earlyloading', true ) ) {
if ( defined( 'DECALOG_EARLY_INIT' ) && defined( 'DECALOG_BOOTSTRAPPED' ) && DECALOG_BOOTSTRAPPED && DECALOG_EARLY_INIT ) {
return;
}
if ( ! defined( 'DECALOG_EARLY_INIT' ) ) {
$target = WPMU_PLUGIN_DIR . '/_decalog_loader.php';
$source = __DIR__ . '/assets/_decalog_loader.php';
if ( ! file_exists( $target ) ) {
if ( ! file_exists( WPMU_PLUGIN_DIR ) ) {
// phpcs:ignore
@mkdir( WPMU_PLUGIN_DIR );
}
if ( ! file_exists( WPMU_PLUGIN_DIR ) ) {
define( 'DECALOG_EARLY_INIT_WPMUDIR_ERROR', true );
}
if ( file_exists( $source ) ) {
// phpcs:ignore
@copy( $source, $target );
// phpcs:ignore
@chmod( $target, 0644 );
}
if ( ! file_exists( $target ) ) {
define( 'DECALOG_EARLY_INIT_COPY_ERROR', true );
}
} else {
define( 'DECALOG_EARLY_INIT_ERROR', true );
}
}
if ( ! defined( 'DECALOG_BOOTSTRAPPED' ) ) {
$target = WP_CONTENT_DIR . '/fatal-error-handler.php';
$source = __DIR__ . '/assets/fatal-error-handler.php';
if ( ! file_exists( $target ) ) {
if ( file_exists( $source ) ) {
// phpcs:ignore
@copy( $source, $target );
// phpcs:ignore
@chmod( $target, 0644 );
}
if ( ! file_exists( $target ) ) {
define( 'DECALOG_BOOTSTRAP_COPY_ERROR', true );
}
} else {
define( 'DECALOG_BOOTSTRAP_ALREADY_EXISTS_ERROR', true );
}
}
} else {
$file = WPMU_PLUGIN_DIR . '/_decalog_loader.php';
if ( file_exists( $file ) ) {
// phpcs:ignore
@unlink( $file );
}
if ( defined( 'DECALOG_BOOTSTRAPPED' ) ) {
$file = WP_CONTENT_DIR . '/fatal-error-handler.php';
if ( file_exists( $file ) ) {
// phpcs:ignore
@unlink( $file );
}
}
}
}
/**
* Removes the file responsible to early initialization in mu-plugins and drop-ins dir.
*
* @since 3.0.0
*/
function decalog_reset_earlyloading() {
$target = WPMU_PLUGIN_DIR . '/_decalog_loader.php';
if ( file_exists( $target ) ) {
// phpcs:ignore
@unlink( $target );
}
if ( defined( 'DECALOG_BOOTSTRAPPED' ) ) {
$target = WP_CONTENT_DIR . '/fatal-error-handler.php';
if ( file_exists( $target ) ) {
// phpcs:ignore
@unlink( $target );
}
}
}
/**
* Disable early loading if we update from version lower than 4.0.0.
*
* @since 4.0.0
*/
function decalog_update_earlyloading_if_needed() {
if ( ! str_starts_with( (string) get_site_option( 'decalog_version', '0.0.0' ), '4.' ) ) {
update_site_option( 'decalog_earlyloading', false );
}
}
/**
* The code that runs during plugin activation.
*
* @since 1.0.0
*/
function decalog_activate() {
decalog_reset_earlyloading();
Decalog\Plugin\Activator::activate();
}
/**
* The code that runs during plugin deactivation.
*
* @since 1.0.0
*/
function decalog_deactivate() {
decalog_reset_earlyloading();
Decalog\Plugin\Deactivator::deactivate();
}
/**
* The code that runs during plugin uninstallation.
*
* @since 1.0.0
*/
function decalog_uninstall() {
decalog_reset_earlyloading();
Decalog\Plugin\Uninstaller::uninstall();
}
/**
* Begins execution of the plugin.
*
* @since 1.0.0
*/
function decalog_run() {
//decalog_update_earlyloading_if_needed();
require_once __DIR__ . '/includes/features/class-wpcli.php';
decalog_check_earlyloading();
$plugin = new Decalog\Plugin\Core();
$plugin->run();
}
if ( ! defined( 'DECALOG_MAX_SHUTDOWN_PRIORITY' ) ) {
define( 'DECALOG_MAX_SHUTDOWN_PRIORITY', PHP_INT_MAX - 1000 );
}
register_activation_hook( __FILE__, 'decalog_activate' );
register_deactivation_hook( __FILE__, 'decalog_deactivate' );
register_uninstall_hook( __FILE__, 'decalog_uninstall' );
decalog_run();