Skip to content

Commit

Permalink
Add check to ensure site is using WordPress 4.8 (#1319)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronjorbin authored and nylen committed Jun 20, 2017
1 parent 5eceb50 commit 537f436
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
17 changes: 10 additions & 7 deletions gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
40 changes: 40 additions & 0 deletions lib/init-checks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* Verify that we can initialize the Gutenberg editor plugin.
*
* @package gutenberg
*/

if ( ! defined( 'ABSPATH' ) ) {
die( 'Silence is golden.' );
}

/**
* Display a notice and deactivate the Gutenberg plugin.
*
* @since 0.1.0
*/
function gutenberg_wordpress_version_notice() {
echo '<div class="error"><p>';
echo __( 'Gutenberg requires WordPress 4.8 or later to function properly. Please upgrade WordPress before activating Gutenberg.', 'gutenberg' );
echo '</p></div>';

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;
}

0 comments on commit 537f436

Please sign in to comment.