-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwpgraphql-debug-extensions.php
More file actions
156 lines (135 loc) · 4.57 KB
/
wpgraphql-debug-extensions.php
File metadata and controls
156 lines (135 loc) · 4.57 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
<?php
/**
* Plugin Name: WPGraphQL Debug Extensions
* Plugin URI: https://github.com/wpengine/hwptoolkit
* GitHub Plugin URI: https://github.com/wpengine/hwptoolkit
* Description: Debug extensions for WPGraphQL.
* Author: WPEngine OSS Team
* Author URI: https://github.com/wpengine
* Update URI: https://github.com/wpengine/hwptoolkit
* Version: 0.0.3
* Text Domain: wpgraphql-debug-extensions
* Domain Path: /languages
* Requires at least: 6.0
* Tested up to: 6.9
* Requires PHP: 7.4+
* Requires Plugins: wp-graphql
* WPGraphQL requires at least: 1.8.0
* License: BSD-0-Clause
* License URI: https://opensource.org/licenses/BSD-3-Clause
*
* @package WPGraphQL\Debug
*/
declare(strict_types=1);
namespace WPGraphQL\Debug;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Define text domain constant to use instead of string literals
if ( ! defined( 'WPGRAPHQL_DEBUG_EXTENSIONS_TEXT_DOMAIN' ) ) {
define( 'WPGRAPHQL_DEBUG_EXTENSIONS_TEXT_DOMAIN', 'wpgraphql-debug-extensions' );
}
// Load the autoloader.
require_once __DIR__ . '/src/Autoloader.php';
if ( ! \WPGraphQL\Debug\Autoloader::autoload() ) {
return;
}
// Run this function when the plugin is activated.
if ( file_exists( __DIR__ . '/activation.php' ) ) {
require_once __DIR__ . '/activation.php';
register_activation_hook( __FILE__, 'graphql_debug_activation_callback' );
}
// Run this function when the plugin is deactivated.
if ( file_exists( __DIR__ . '/deactivation.php' ) ) {
require_once __DIR__ . '/deactivation.php';
register_deactivation_hook( __FILE__, 'graphql_debug_deactivation_callback' );
}
/**
* Define plugin constants.
*/
function wpgraphql_debug_extensions_constants(): void {
// Plugin version.
if ( ! defined( 'WPGRAPHQL_DEBUG_EXTENSIONS_VERSION' ) ) {
define( 'WPGRAPHQL_DEBUG_EXTENSIONS_VERSION', '0.0.3' );
}
// Plugin Folder Path.
if ( ! defined( 'WPGRAPHQL_DEBUG_EXTENSIONS_PLUGIN_DIR' ) ) {
define( 'WPGRAPHQL_DEBUG_EXTENSIONS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
// Plugin Folder URL.
if ( ! defined( 'WPGRAPHQL_DEBUG_EXTENSIONS_PLUGIN_URL' ) ) {
define( 'WPGRAPHQL_DEBUG_EXTENSIONS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
// Plugin Root File.
if ( ! defined( 'WPGRAPHQL_DEBUG_EXTENSIONS_PLUGIN_FILE' ) ) {
define( 'WPGRAPHQL_DEBUG_EXTENSIONS_PLUGIN_FILE', __FILE__ );
}
// Whether to autoload the files or not.
if ( ! defined( 'WPGRAPHQL_DEBUG_EXTENSIONS_AUTOLOAD' ) ) {
define( 'WPGRAPHQL_DEBUG_EXTENSIONS_AUTOLOAD', true );
}
}
/**
* Checks if all the the required plugins are installed and activated.
*
* @return array<string>
*/
function wpgraphql_debug_extensions_dependencies_not_ready(): array {
$deps = [];
if ( ! class_exists( '\WPGraphQL' ) ) {
$deps[] = 'WPGraphQL';
}
return $deps;
}
/**
* Initializes plugin.
*/
function wpgraphql_debug_extensions_init(): void {
wpgraphql_debug_extensions_constants();
$not_ready = wpgraphql_debug_extensions_dependencies_not_ready();
if ( $not_ready === [] && defined( 'WPGRAPHQL_DEBUG_EXTENSIONS_PLUGIN_DIR' ) ) {
// Load text domain at the init hook
add_action( 'init', 'WPGraphQL\Debug\wpgraphql_debug_extensions_load_textdomain' );
$plugin = new \WPGraphQL\Debug\Plugin();
$plugin::instance();
return;
}
foreach ( $not_ready as $dep ) {
add_action(
'admin_notices',
static function () use ($dep) {
?>
<div class="error notice">
<p>
<?php
// Using plain string to avoid early text domain loading
printf(
/* translators: dependency not ready error message */
'%1$s must be active for WPGraphQL Debug Extensions to work.',
esc_html( $dep )
);
?>
</p>
</div>
<?php
},
10,
0
);
}
}
/**
* Load plugin text domain.
*/
function wpgraphql_debug_extensions_load_textdomain(): void {
load_plugin_textdomain(
'wpgraphql-debug-extensions',
false,
dirname( plugin_basename( __FILE__ ) ) . '/languages'
);
}
// Load the text domain during init, not earlier
add_action( 'init', 'WPGraphQL\Debug\wpgraphql_debug_extensions_load_textdomain', 1 );
/** @psalm-suppress HookNotFound */
add_action( 'plugins_loaded', 'WPGraphQL\Debug\wpgraphql_debug_extensions_init' );