From 9e88d8666d097eeaa307009c726ab35cfc940d5a Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Sat, 14 Sep 2024 00:30:30 +1000 Subject: [PATCH] Update minimum required version in PHP. (#65301) * Update minimum required version in PHP. * Use a constant. * Test plugin meta data and constant match. * Set constant incorrectly to demonstrate failing tests. * Use regex to extract the constant. * Match the version in the constant and plugin meta. Co-authored-by: peterwilsoncc Co-authored-by: Mamaduka --- gutenberg.php | 6 +++-- .../class-test-plugin-version-meta-test.php | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 phpunit/class-test-plugin-version-meta-test.php diff --git a/gutenberg.php b/gutenberg.php index c9c6e09a8092b..342c61fb56cd1 100644 --- a/gutenberg.php +++ b/gutenberg.php @@ -15,6 +15,8 @@ ### BEGIN AUTO-GENERATED DEFINES defined( 'GUTENBERG_DEVELOPMENT_MODE' ) or define( 'GUTENBERG_DEVELOPMENT_MODE', true ); ### END AUTO-GENERATED DEFINES +defined( 'GUTENBERG_MINIMUM_WP_VERSION' ) or define( 'GUTENBERG_MINIMUM_WP_VERSION', '6.5' ); + gutenberg_pre_init(); @@ -26,7 +28,7 @@ function gutenberg_wordpress_version_notice() { echo '

'; /* translators: %s: Minimum required version */ - printf( __( 'Gutenberg requires WordPress %s or later to function properly. Please upgrade WordPress before activating Gutenberg.', 'gutenberg' ), '5.9' ); + printf( __( 'Gutenberg requires WordPress %s or later to function properly. Please upgrade WordPress before activating Gutenberg.', 'gutenberg' ), GUTENBERG_MINIMUM_WP_VERSION ); echo '

'; deactivate_plugins( array( 'gutenberg/gutenberg.php' ) ); @@ -67,7 +69,7 @@ function gutenberg_pre_init() { // Compare against major release versions (X.Y) rather than minor (X.Y.Z) // unless a minor release is the actual minimum requirement. WordPress reports // X.Y for its major releases. - if ( version_compare( $version, '5.9', '<' ) ) { + if ( version_compare( $version, GUTENBERG_MINIMUM_WP_VERSION, '<' ) ) { add_action( 'admin_notices', 'gutenberg_wordpress_version_notice' ); return; } diff --git a/phpunit/class-test-plugin-version-meta-test.php b/phpunit/class-test-plugin-version-meta-test.php new file mode 100644 index 0000000000000..f0dadf873166f --- /dev/null +++ b/phpunit/class-test-plugin-version-meta-test.php @@ -0,0 +1,26 @@ + 'Requires at least' ) ); + /* + * Gutenberg.php isn't loaded in the test environment. + * + * Read the file directly and use regex to extract the constant. + */ + preg_match( '/GUTENBERG_MINIMUM_WP_VERSION\', \'(.*?)\'/', file_get_contents( __DIR__ . '/../gutenberg.php' ), $matches ); + $version_in_file = $matches[1]; + + $this->assertSame( $file_meta['RequiresWP'], $version_in_file, 'The minimum required WordPress version does not match the plugin header.' ); + } +}