Skip to content

Commit 149223a

Browse files
committed
Add PHP compatibility check: minimum PHP version with admin notice and safe deactivation
1 parent b8972ed commit 149223a

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

gutenberg.php

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,40 @@
1616
defined( 'GUTENBERG_DEVELOPMENT_MODE' ) or define( 'GUTENBERG_DEVELOPMENT_MODE', true );
1717
### END AUTO-GENERATED DEFINES
1818
defined( 'GUTENBERG_MINIMUM_WP_VERSION' ) or define( 'GUTENBERG_MINIMUM_WP_VERSION', '6.7' );
19-
19+
defined( 'GUTENBERG_MINIMUM_PHP_VERSION' ) or define( 'GUTENBERG_MINIMUM_PHP_VERSION', '7.2' );
2020

2121
gutenberg_pre_init();
2222

2323
/**
24-
* Display a version notice and deactivate the Gutenberg plugin.
24+
* Display a WordPress version notice and deactivate the Gutenberg plugin.
2525
*
2626
* @since 0.1.0
2727
*/
2828
function gutenberg_wordpress_version_notice() {
2929
echo '<div class="error"><p>';
3030
/* translators: %s: Minimum required version */
31-
printf( __( 'Gutenberg requires WordPress %s or later to function properly. Please upgrade WordPress before activating Gutenberg.', 'gutenberg' ), GUTENBERG_MINIMUM_WP_VERSION );
31+
printf(
32+
__( 'Gutenberg requires WordPress %s or later to function properly. Please upgrade WordPress before activating Gutenberg.', 'gutenberg' ),
33+
GUTENBERG_MINIMUM_WP_VERSION
34+
);
35+
echo '</p></div>';
36+
37+
deactivate_plugins( array( 'gutenberg/gutenberg.php' ) );
38+
}
39+
40+
/**
41+
* Display a PHP version notice and deactivate the Gutenberg plugin.
42+
*
43+
* @since 0.1.0
44+
*/
45+
function gutenberg_php_version_notice() {
46+
echo '<div class="error"><p>';
47+
/* translators: %1$s: Minimum required PHP version, %2$s: current PHP version */
48+
printf(
49+
__( 'Gutenberg requires PHP %1$s or later to function. Your site is running PHP %2$s. Please update PHP or contact your host to enable PHP %1$s+.', 'gutenberg' ),
50+
GUTENBERG_MINIMUM_PHP_VERSION,
51+
PHP_VERSION
52+
);
3253
echo '</p></div>';
3354

3455
deactivate_plugins( array( 'gutenberg/gutenberg.php' ) );
@@ -41,19 +62,27 @@ function gutenberg_wordpress_version_notice() {
4162
*/
4263
function gutenberg_build_files_notice() {
4364
echo '<div class="error"><p>';
44-
_e( 'Gutenberg development mode requires files to be built. Run <code>npm install</code> to install dependencies, <code>npm run build</code> to build the files or <code>npm run dev</code> to build the files and watch for changes. Read the <a href="https://github.com/WordPress/gutenberg/blob/HEAD/docs/contributors/code/getting-started-with-code-contribution.md">contributing</a> file for more information.', 'gutenberg' );
65+
_e(
66+
'Gutenberg development mode requires files to be built. Run <code>npm install</code> to install dependencies, <code>npm run build</code> to build the files or <code>npm run dev</code> to build the files and watch for changes. Read the <a href="https://github.com/WordPress/gutenberg/blob/HEAD/docs/contributors/code/getting-started-with-code-contribution.md">contributing</a> file for more information.',
67+
'gutenberg'
68+
);
4569
echo '</p></div>';
4670
}
4771

4872
/**
49-
* Verify that we can initialize the Gutenberg editor , then load it.
73+
* Verify that we can initialize the Gutenberg editor, then load it.
5074
*
5175
* @since 1.5.0
5276
*
53-
* @global string $wp_version The WordPress version string.
54-
*
77+
* @global string $wp_version The WordPress version string.
5578
*/
5679
function gutenberg_pre_init() {
80+
// Check PHP version early.
81+
if ( defined( 'GUTENBERG_MINIMUM_PHP_VERSION' ) && version_compare( PHP_VERSION, GUTENBERG_MINIMUM_PHP_VERSION, '<' ) ) {
82+
add_action( 'admin_notices', 'gutenberg_php_version_notice' );
83+
return;
84+
}
85+
5786
global $wp_version;
5887
if ( defined( 'GUTENBERG_DEVELOPMENT_MODE' ) && GUTENBERG_DEVELOPMENT_MODE && ! file_exists( __DIR__ . '/build/blocks' ) ) {
5988
add_action( 'admin_notices', 'gutenberg_build_files_notice' );

0 commit comments

Comments
 (0)