From 537f436aadfe20060c36dee3f17f226708a9a57a Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Tue, 20 Jun 2017 15:53:21 -0400 Subject: [PATCH] Add check to ensure site is using WordPress 4.8 (#1319) --- gutenberg.php | 17 ++++++++++------- lib/init-checks.php | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 lib/init-checks.php diff --git a/gutenberg.php b/gutenberg.php index 4ae56ca168e0fd..ad332a82d7afb1 100644 --- a/gutenberg.php +++ b/gutenberg.php @@ -13,11 +13,14 @@ define( 'GUTENBERG_DEVELOPMENT_MODE', true ); ### END AUTO-GENERATED DEFINES -// Load API functions. -require_once dirname( __FILE__ ) . '/lib/blocks.php'; -require_once dirname( __FILE__ ) . '/lib/client-assets.php'; -require_once dirname( __FILE__ ) . '/lib/i18n.php'; -require_once dirname( __FILE__ ) . '/lib/register.php'; +require_once dirname( __FILE__ ) . '/lib/init-checks.php'; +if ( gutenberg_can_init() ) { + // Load API functions, register scripts and actions, etc. + require_once dirname( __FILE__ ) . '/lib/blocks.php'; + require_once dirname( __FILE__ ) . '/lib/client-assets.php'; + require_once dirname( __FILE__ ) . '/lib/i18n.php'; + require_once dirname( __FILE__ ) . '/lib/register.php'; -// Register server-side code for individual blocks. -require_once dirname( __FILE__ ) . '/lib/blocks/latest-posts.php'; + // Register server-side code for individual blocks. + require_once dirname( __FILE__ ) . '/lib/blocks/latest-posts.php'; +} diff --git a/lib/init-checks.php b/lib/init-checks.php new file mode 100644 index 00000000000000..4346fd599a5659 --- /dev/null +++ b/lib/init-checks.php @@ -0,0 +1,40 @@ +

'; + echo __( 'Gutenberg requires WordPress 4.8 or later to function properly. Please upgrade WordPress before activating Gutenberg.', 'gutenberg' ); + echo '

'; + + deactivate_plugins( array( 'gutenberg/gutenberg.php' ) ); +} + +/** + * Verify that we can initialize the Gutenberg editor plugin. + * + * @since 0.1.0 + * @return bool Whether we can initialize the plugin. + */ +function gutenberg_can_init() { + global $wp_version; + + if ( version_compare( $wp_version, '4.8', '<' ) ) { + add_action( 'admin_notices', 'gutenberg_wordpress_version_notice' ); + return false; + } + + return true; +}