Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Show a warning to notify the user if the WC Blocks version is behind …
Browse files Browse the repository at this point in the history
…the one bundled in WC Core (#6459)

Co-authored-by: Albert Juhé Lluveras <[email protected]>
  • Loading branch information
dinhtungdu and Aljullu authored May 31, 2022
1 parent d7d8895 commit 83a3e64
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions woocommerce-gutenberg-products-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,40 @@ function woocommerce_blocks_get_php_translation_from_core( $translation, $text,
}

add_filter( 'gettext', 'woocommerce_blocks_get_php_translation_from_core', 10, 3 );

/**
* Add notice to the admin dashboard if the plugin is outdated.
*
* @see https://github.com/woocommerce/woocommerce-blocks/issues/5587
*/
function woocommerce_blocks_plugin_outdated_notice() {
$is_active =
is_plugin_active( 'woo-gutenberg-products-block/woocommerce-gutenberg-products-block.php' ) ||
is_plugin_active( 'woocommerce-gutenberg-products-block/woocommerce-gutenberg-products-block.php' ) ||
is_plugin_active( 'woocommerce-blocks/woocommerce-gutenberg-products-block.php' );

if ( ! $is_active ) {
return;
}

$woocommerce_blocks_path = \Automattic\WooCommerce\Blocks\Package::get_path();

/**
* Check the current WC Blocks path. If the WC Blocks plugin is active but
* the current path is from the WC Core, we can consider the plugin is
* outdated because Jetpack Autoloader always loads the newer package.
*/
if ( ! strpos( $woocommerce_blocks_path, 'packages/woocommerce-blocks' ) ) {
return;
}

if ( should_display_compatibility_notices() ) {
?>
<div class="notice notice-warning">
<p><?php esc_html_e( 'You have WooCommerce Blocks installed, but the WooCommerce bundled version is running because it is more up-to-date. This may cause unexpected compatibility issues. Please update the WooCommerce Blocks plugin.', 'woo-gutenberg-products-block' ); ?></p>
</div>
<?php
}
}

add_action( 'admin_notices', 'woocommerce_blocks_plugin_outdated_notice' );

0 comments on commit 83a3e64

Please sign in to comment.