Added Gutenberg check to Blockbase themes (#5735)
* Added Gutenberg check to Blockbase themes * tucked the check into the if statement where it belongs * Lint autofix. * Update translation text domain Co-authored-by: Jeff Ong <jonger4@gmail.com> Co-authored-by: Sarah Norris <sarah@sekai.co.uk>
This commit is contained in:
parent
43eb7bfffd
commit
4fd5c6149d
3 changed files with 63 additions and 0 deletions
|
@ -190,3 +190,5 @@ require get_template_directory() . '/inc/block-patterns.php';
|
|||
if ( file_exists( get_stylesheet_directory() . '/inc/block-patterns.php' ) ) {
|
||||
require_once get_stylesheet_directory() . '/inc/block-patterns.php';
|
||||
}
|
||||
|
||||
require get_template_directory() . '/inc/gutenberg-dependency-check.php';
|
60
blockbase/inc/gutenberg-dependency-check.php
Normal file
60
blockbase/inc/gutenberg-dependency-check.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
add_action( 'admin_notices', 'show_admin_messages' );
|
||||
|
||||
function print_admin_message( $version ) {
|
||||
echo '<div id="message" class="error"><p><strong>';
|
||||
printf( __( 'The installed theme requires <a href="https://wordpress.org/plugins/gutenberg/">Gutenberg</a> version %s or higher.', 'blockbase' ), $version );
|
||||
echo '</strong></p></div>';
|
||||
}
|
||||
|
||||
function show_admin_messages() {
|
||||
|
||||
if ( is_child_theme() ) {
|
||||
$metadata = file_get_contents( get_template_directory() . '/style.css' );
|
||||
preg_match( '/(?<=Requires Gutenberg:).+/', $metadata, $match );
|
||||
|
||||
if ( sizeof( $match ) > 0 ) {
|
||||
$version = trim( $match[0] );
|
||||
}
|
||||
}
|
||||
|
||||
$metadata = file_get_contents( get_stylesheet_directory() . '/style.css' );
|
||||
preg_match( '/(?<=Requires Gutenberg:).+/', $metadata, $match );
|
||||
|
||||
if ( ! isset( $version ) || ( sizeof( $match ) > 0 && version_compare( $version, trim( $match[0] ) ) < 0 ) ) {
|
||||
$version = trim( $match[0] );
|
||||
}
|
||||
|
||||
if ( ! isset( $version ) ) {
|
||||
return; // Gutenberg is not required
|
||||
}
|
||||
|
||||
if ( ! defined( 'IS_GUTENBERG_PLUGIN' ) ) {
|
||||
print_admin_message( $version ); // Gutenberg is not activated
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine Gutenberg version from defined constant
|
||||
if ( defined( 'GUTENBERG_VERSION' ) ) {
|
||||
if ( version_compare( GUTENBERG_VERSION, $version ) < 0 ) {
|
||||
print_admin_message( $version );
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// We have confirmed that Gutenberg is installed and activated, however we cannot use the GUTENBERG_VERSION constant
|
||||
// (probably because we are in development mode)
|
||||
// we'll use the metadata from get_plugins() to determine the version of Gutenberg
|
||||
$plugins = get_plugins();
|
||||
foreach ( $plugins as $plugin ) {
|
||||
if ( 'Gutenberg' === $plugin['Name'] ) {
|
||||
if ( version_compare( trim( $plugin['Version'] ), $version ) < 0 ) {
|
||||
print_admin_message( $version );
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// We weren't able to confirm the version, however we do know that it's installed and activated so we'll just hope for the best!
|
||||
}
|
|
@ -7,6 +7,7 @@ Description: Blockbase is a simple theme that supports full-site editing. It com
|
|||
Requires at least: 5.7
|
||||
Tested up to: 5.8
|
||||
Requires PHP: 5.7
|
||||
Requires Gutenberg: 12.8
|
||||
Version: 2.0.30
|
||||
License: GNU General Public License v2 or later
|
||||
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
|
|
Loading…
Add table
Reference in a new issue