Skip to content

Commit 02d8ecb

Browse files
authored
Merge pull request #393 from wpengine/chore-add-php-compatibility-notice
chore: Added admin notice for older version of PHP for the WPGraphQL Logging Plugin
2 parents 340a62f + 95451dd commit 02d8ecb

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

plugins/wpgraphql-logging/wpgraphql-logging.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
function wpgraphql_logging_init(): void {
6565
wpgraphql_logging_constants();
6666
wpgraphql_logging_plugin_init();
67-
wpgraphql_logging_plugin_admin_notice();
67+
wpgraphql_logging_plugin_admin_notice_correct_build();
68+
wpgraphql_logging_plugin_admin_notice_min_php_version();
6869
}
6970
}
7071

@@ -110,11 +111,11 @@ function wpgraphql_logging_plugin_init(): ?Plugin {
110111
}
111112

112113

113-
if ( ! function_exists( 'wpgraphql_logging_plugin_admin_notice' ) ) {
114+
if ( ! function_exists( 'wpgraphql_logging_plugin_admin_notice_correct_build' ) ) {
114115
/**
115116
* Display an admin notice if the plugin is not properly initialized.
116117
*/
117-
function wpgraphql_logging_plugin_admin_notice(): void {
118+
function wpgraphql_logging_plugin_admin_notice_correct_build(): void {
118119
if ( defined( 'WPGRAPHQL_LOGGING_PLUGIN_DIR' ) ) {
119120
return;
120121
}
@@ -138,6 +139,35 @@ static function (): void {
138139
}
139140
}
140141

142+
if ( ! function_exists( 'wpgraphql_logging_plugin_admin_notice_min_php_version' ) ) {
143+
/**
144+
* Display an admin notice if the PHP version is not met.
145+
*/
146+
function wpgraphql_logging_plugin_admin_notice_min_php_version(): void {
147+
if ( version_compare( PHP_VERSION, '8.1', '>=' ) ) {
148+
return;
149+
}
150+
151+
add_action(
152+
'admin_notices',
153+
static function (): void {
154+
?>
155+
<div class="error notice">
156+
<p>
157+
<?php
158+
echo 'PHP ' . PHP_VERSION . ' is not supported. Please upgrade to PHP 8.1 or higher in order to use WPGraphQL Logging Plugin.';
159+
?>
160+
</p>
161+
</div>
162+
<?php
163+
},
164+
10,
165+
0
166+
);
167+
}
168+
}
169+
170+
141171
/**
142172
* Load plugin text domain.
143173
*/

0 commit comments

Comments
 (0)