-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwpgraphql-logging.php
More file actions
192 lines (167 loc) · 4.99 KB
/
wpgraphql-logging.php
File metadata and controls
192 lines (167 loc) · 4.99 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
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
185
186
187
188
189
190
191
192
<?php
/**
* Plugin Name: WPGraphQL Logging
* Plugin URI: https://github.com/wpengine/hwptoolkit
* GitHub Plugin URI: https://github.com/wpengine/hwptoolkit
* Description: A WPGraphQL logging plugin that provides visibility into the request lifecycle, giving developers the observability needed to quickly identify and resolve bottlenecks in their headless WordPress application.
* Author: WPEngine Headless OSS Team
* Author URI: https://github.com/wpengine
* Update URI: https://github.com/wpengine/hwptoolkit
* Version: 1.0.1
* Text Domain: wpgraphql-logging
* Domain Path: /languages
* Requires at least: 6.5
* Tested up to: 6.9
* Requires PHP: 8.1.2+
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Requires Plugins: wp-graphql
* WPGraphQL requires at least: 2.3.0
* WPGraphQL tested up to: 2.5.1
*
* @package WPGraphQL\Logging
*
* @author WPEngine Headless OSS Team
*
* @since 0.0.1
*
* @license GPL-2
*/
declare(strict_types=1);
use WPGraphQL\Logging\Autoloader;
use WPGraphQL\Logging\Plugin;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Composer autoloader.
require_once __DIR__ . '/src/Autoloader.php';
if ( ! Autoloader::autoload() ) {
return;
}
if ( ! function_exists( 'wpgraphql_logging_constants' ) ) {
/**
* Define plugin constants.
*/
function wpgraphql_logging_constants(): void {
if ( ! defined( 'WPGRAPHQL_LOGGING_VERSION' ) ) {
define( 'WPGRAPHQL_LOGGING_VERSION', '1.0.1' );
}
if ( ! defined( 'WPGRAPHQL_LOGGING_PLUGIN_DIR' ) ) {
define( 'WPGRAPHQL_LOGGING_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'WPGRAPHQL_LOGGING_PLUGIN_URL' ) ) {
define( 'WPGRAPHQL_LOGGING_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
if ( ! defined( 'WPGRAPHQL_LOGGING_SETTINGS_KEY' ) ) {
define( 'WPGRAPHQL_LOGGING_SETTINGS_KEY', 'wpgraphql_logging_settings' );
}
if ( ! defined( 'WPGRAPHQL_LOGGING_SETTINGS_GROUP' ) ) {
define( 'WPGRAPHQL_LOGGING_SETTINGS_GROUP', 'wpgraphql_logging_settings_group' );
}
}
}
// Define constants early - needed for activation/deactivation hooks.
wpgraphql_logging_constants();
if ( file_exists( __DIR__ . '/activation.php' ) ) {
require_once __DIR__ . '/activation.php';
// @phpstan-ignore-next-line
register_activation_hook( __FILE__, 'wpgraphql_logging_activation_callback' );
}
if ( file_exists( __DIR__ . '/deactivation.php' ) ) {
require_once __DIR__ . '/deactivation.php';
// @phpstan-ignore-next-line
register_deactivation_hook( __FILE__, 'wpgraphql_logging_deactivation_callback' );
}
// phpcs:enable Generic.Metrics.CyclomaticComplexity.TooHigh
// phpcs:enable SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
if ( ! function_exists( 'wpgraphql_logging_init' ) ) {
/**
* Initializes plugin.
*/
function wpgraphql_logging_init(): void {
wpgraphql_logging_plugin_init();
wpgraphql_logging_plugin_admin_notice_correct_build();
wpgraphql_logging_plugin_admin_notice_min_php_version();
}
}
if ( ! function_exists( 'wpgraphql_logging_plugin_init' ) ) {
/**
* Initialize the WPGraphQL Logging plugin.
*/
function wpgraphql_logging_plugin_init(): ?Plugin {
if ( ! defined( 'WPGRAPHQL_LOGGING_PLUGIN_DIR' ) ) {
return null;
}
require_once WPGRAPHQL_LOGGING_PLUGIN_DIR . 'src/Plugin.php';
return Plugin::init();
}
}
if ( ! function_exists( 'wpgraphql_logging_plugin_admin_notice_correct_build' ) ) {
/**
* Display an admin notice if the plugin is not properly initialized.
*/
function wpgraphql_logging_plugin_admin_notice_correct_build(): void {
if ( defined( 'WPGRAPHQL_LOGGING_PLUGIN_DIR' ) ) {
return;
}
add_action(
'admin_notices',
static function (): void {
?>
<div class="error notice">
<p>
<?php
echo esc_html__( 'Composer vendor directory must be present for WPGraphQL Logging to work.', 'wpgraphql-logging' );
?>
</p>
</div>
<?php
},
10,
0
);
}
}
if ( ! function_exists( 'wpgraphql_logging_plugin_admin_notice_min_php_version' ) ) {
/**
* Display an admin notice if the PHP version is not met.
*/
function wpgraphql_logging_plugin_admin_notice_min_php_version(): void {
if ( version_compare( PHP_VERSION, '8.1.2', '>=' ) ) {
return;
}
add_action(
'admin_notices',
static function (): void {
?>
<div class="error notice">
<p>
<?php
echo esc_html(
sprintf(
/* translators: %s: PHP version */
__( 'PHP %s is not supported. Please upgrade to PHP 8.1.2 or higher in order to use WPGraphQL Logging Plugin.', 'wpgraphql-logging' ),
PHP_VERSION
)
);
?>
</p>
</div>
<?php
},
10,
0
);
}
}
/**
* Load plugin text domain.
*/
function wpgraphql_logging_load_textdomain(): void {
load_plugin_textdomain( 'wpgraphql-logging', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
add_action( 'init', 'wpgraphql_logging_load_textdomain', 1, 0 );
/** @psalm-suppress HookNotFound */
add_action( 'plugins_loaded', static function (): void {
wpgraphql_logging_init();
}, 100, 0 );