-
Notifications
You must be signed in to change notification settings - Fork 1
/
sentry-integration.php
143 lines (120 loc) · 3.7 KB
/
sentry-integration.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
<?php
/**
* Plugin Name: Sentry Integration
* Plugin URI: https://github.com/itgalaxy/sentry-integration
* Description: A (unofficial) WordPress plugin to report PHP, JavaScript and security headers errors to Sentry.
* Version: 2.2.9
* Author: Alexander Krasnoyarov
* Author URI: https://github.com/evilebottnawi
* License: MIT
*/
// Exit if accessed directly.
if (!defined('ABSPATH')) {
exit();
}
use Itgalaxy\SentryIntegration\ExpectCTTracker;
use Itgalaxy\SentryIntegration\JavaScriptTracker;
use Itgalaxy\SentryIntegration\PHPTracker;
use Itgalaxy\SentryIntegration\XXSSProtectionTracker;
// If the plugin was already loaded as a mu-plugin do not load again.
if (defined('SENTRY_INTEGRATION_MU_LOADED')) {
return;
}
// Resolve the sentry plugin file.
if (!defined('SENTRY_INTEGRATION_PLUGIN_FILE')) {
define(
'SENTRY_INTEGRATION_PLUGIN_FILE',
call_user_func(function () {
global $wp_plugin_paths;
$plugin_file = __FILE__;
if (!empty($wp_plugin_paths)) {
$wp_plugin_real_paths = array_flip($wp_plugin_paths);
$plugin_path = wp_normalize_path(dirname($plugin_file));
if (isset($wp_plugin_real_paths[$plugin_path])) {
$plugin_file = str_replace(
$plugin_path,
$wp_plugin_real_paths[$plugin_path],
$plugin_file
);
}
}
return $plugin_file;
})
);
}
$autoloaderPath = __DIR__ . '/vendor/autoload.php';
if (!file_exists($autoloaderPath)) {
wp_die(
wp_kses_post(
__(
'You must run <code>composer install</code> from the Sentry Integration directory.',
'sentry-integration'
)
),
esc_html(__('Autoloader not found', 'sentry-integration'))
);
}
require_once $autoloaderPath;
register_deactivation_hook(__FILE__, 'flush_rewrite_rules');
register_activation_hook(__FILE__, 'flush_rewrite_rules');
// Define the sentry version.
if (!defined('SENTRY_INTEGRATION_RELEASE')) {
define('SENTRY_INTEGRATION_RELEASE', wp_get_theme()->get('Version'));
}
// Load the Expect-CT tracker if we have a private DSN
if (
defined('SENTRY_INTEGRATION_EXPECT_CT_DSN') &&
SENTRY_INTEGRATION_EXPECT_CT_DSN
) {
add_filter(
'sentry_integration_expect_ct_dsn',
function () {
return SENTRY_INTEGRATION_EXPECT_CT_DSN;
},
1,
0
);
ExpectCTTracker::get_instance();
}
if (!defined('SENTRY_INTEGRATION_PUBLIC_DSN_ENQUEUE_MODE')) {
define('SENTRY_INTEGRATION_PUBLIC_DSN_ENQUEUE_MODE', 'inline');
}
// Load the Javascript tracker if we have a public DSN
if (defined('SENTRY_INTEGRATION_PUBLIC_DSN') && SENTRY_INTEGRATION_PUBLIC_DSN) {
add_filter(
'sentry_integration_public_dsn',
function () {
return SENTRY_INTEGRATION_PUBLIC_DSN;
},
1,
0
);
JavaScriptTracker::get_instance();
}
// Load the PHP tracker if we have a private DSN
if (defined('SENTRY_INTEGRATION_DSN') && SENTRY_INTEGRATION_DSN) {
add_filter(
'sentry_integration_dsn',
function () {
return SENTRY_INTEGRATION_DSN;
},
1,
0
);
PHPTracker::get_instance();
}
// Load the X-XSS-Protection tracker if we have a private DSN
if (
defined('SENTRY_INTEGRATION_X_XSS_PROTECTION_DSN') &&
SENTRY_INTEGRATION_X_XSS_PROTECTION_DSN
) {
add_filter(
'sentry_integration_x_xss_protection_dsn',
function () {
return SENTRY_INTEGRATION_X_XSS_PROTECTION_DSN;
},
1,
0
);
XXSSProtectionTracker::get_instance();
}