Show notices when WP or PHP versions are not met (https://github.com/woocommerce/woocommerce-blocks/pull/1160)

* Show notices when PHP or WP versions are not met

* Update version-changes.sh so it updates versions in woocommerce-gutenberg-products-block.php

* Convert constants to normal variables

* Remove error_log calls

* Remove button with PHP update link

* Show notices only in plugins and WooCommerce pages
This commit is contained in:
Albert Juhé Lluveras 2019-11-15 13:33:43 +01:00 committed by GitHub
parent 5f7dfe0ac8
commit 2fde5d6890
2 changed files with 63 additions and 2 deletions

View File

@ -4,7 +4,7 @@ IS_PRE_RELEASE=${IS_PRE_RELEASE:=false}
# replace all instances of $VID:$ with the release version but only when not pre-release. # replace all instances of $VID:$ with the release version but only when not pre-release.
if [ $IS_PRE_RELEASE = false ]; then if [ $IS_PRE_RELEASE = false ]; then
find ./src -name "*.php" -print0 | xargs -0 perl -i -pe 's/\$VID:\$/'${VERSION}'/g' find ./src woocommerce-gutenberg-products-block.php -name "*.php" -print0 | xargs -0 perl -i -pe 's/\$VID:\$/'${VERSION}'/g'
fi fi
# Update version number in readme.txt # Update version number in readme.txt

View File

@ -18,7 +18,68 @@
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
if ( version_compare( PHP_VERSION, '5.6.0', '<' ) ) { $minimum_wp_version = '5.0';
$minimum_php_version = '5.6';
/**
* Whether notices must be displayed in the current page (plugins and WooCommerce pages).
*
* @since $VID:$
*/
function should_display_compatibility_notices() {
$current_screen = get_current_screen();
if ( ! isset( $current_screen ) ) {
return false;
}
$is_plugins_page =
property_exists( $current_screen, 'id' ) &&
'plugins' === $current_screen->id;
$is_woocommerce_page =
property_exists( $current_screen, 'parent_base' ) &&
'woocommerce' === $current_screen->parent_base;
return $is_plugins_page || $is_woocommerce_page;
}
if ( version_compare( $GLOBALS['wp_version'], $minimum_wp_version, '<' ) ) {
/**
* Outputs for an admin notice about running WooCommerce Blocks on outdated WordPress.
*
* @since $VID:$
*/
function woocommerce_blocks_admin_unsupported_wp_notice() {
if ( should_display_compatibility_notices() ) {
?>
<div class="notice notice-error is-dismissible">
<p><?php esc_html_e( 'WooCommerce Blocks requires a more recent version of WordPress and has been paused. Please update WordPress to continue enjoying WooCommerce Blocks.', 'woo-gutenberg-products-block' ); ?></p>
</div>
<?php
}
}
add_action( 'admin_notices', 'woocommerce_blocks_admin_unsupported_wp_notice' );
return;
}
if ( version_compare( PHP_VERSION, $minimum_php_version, '<' ) ) {
/**
* Outputs an admin notice for folks running an outdated version of PHP.
*
* @todo: Remove once WP 5.2 is the minimum version.
*
* @since $VID:$
*/
function woocommerce_blocks_admin_unsupported_php_notice() {
if ( should_display_compatibility_notices() ) {
?>
<div class="notice notice-error is-dismissible">
<p><?php esc_html_e( 'WooCommerce Blocks requires a more recent version of PHP and has been paused. Please update PHP to continue enjoying WooCommerce Blocks.', 'woo-gutenberg-products-block' ); ?></p>
</div>
<?php
}
}
add_action( 'admin_notices', 'woocommerce_blocks_admin_unsupported_php_notice' );
return; return;
} }