Skip to content

Commit

Permalink
Compat Checker – Adds perma-dismissible warning notices (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibndawood authored Oct 11, 2023
2 parents 4486cc1 + 1b5307f commit bb3d2f2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/php/compat-checker/src/Checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public function get_plugin_data( $plugin_file, $file_version ) {
$plugin_data = get_transient( $transient_key );

if ( false === $plugin_data ) {
$plugin_data = get_file_data( $plugin_file, $default_headers, 'plugin' );
$plugin_data = get_file_data( $plugin_file, $default_headers, 'plugin' );
$plugin_data['File'] = $plugin_file;
set_transient( $transient_key, $plugin_data, MONTH_IN_SECONDS );
}

Expand Down
21 changes: 16 additions & 5 deletions packages/php/compat-checker/src/Checks/CompatCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Automattic\WooCommerce\Grow\Tools\CompatChecker\v0_0_1\Checks;

use WC_Admin_Notices;

defined( 'ABSPATH' ) || exit;

/**
Expand Down Expand Up @@ -67,6 +69,7 @@ protected function add_admin_notice( $slug, $class, $message ) {
$screen = get_current_screen();
$hidden = array( 'update', 'update-network', 'update-core', 'update-core-network', 'upgrade', 'upgrade-network', 'network' );
$show = isset( $screen->id ) && ! in_array( $screen->id, $hidden, true );
$slug = isset( $this->plugin_data['File'] ) ? plugin_basename( $this->plugin_data['File'] ) . '-' . $slug : $slug;

/**
* The Compat Check filter to show an admin notice.
Expand All @@ -80,10 +83,18 @@ protected function add_admin_notice( $slug, $class, $message ) {
return;
}

$this->notices[ $slug ] = array(
'class' => $class,
'message' => $message,
);
// If the notice is a warning and WooCommerce admin notice system is available. Then use it.
if ( str_contains( $class, 'warning' ) && class_exists( WC_Admin_Notices::class ) ) {
// Do not display the notice if it was dismissed.
if ( ! get_user_meta( get_current_user_id(), 'dismissed_' . $slug . '_notice', true ) ) {
WC_Admin_Notices::add_custom_notice( $slug, $message );
}
} else {
$this->notices[ $slug ] = array(
'class' => $class,
'message' => $message,
);
}
}

/**
Expand Down Expand Up @@ -121,7 +132,7 @@ public function display_admin_notices() {
foreach ( $this->notices as $key => $notice ) {
$class = $notice['class'];
$message = $notice['message'];
echo sprintf(
printf(
'<div class="notice notice-%1$s"><p>%2$s</p></div>',
esc_attr( $class ),
wp_kses( $message, $allowed_tags )
Expand Down
2 changes: 1 addition & 1 deletion packages/php/compat-checker/src/Checks/WCCompatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private function get_supported_wc_version() {
// Store the previous minor while we loop patch versions, which we ignore.
$previous_minor = $older_minor;

$supported_minor--;
--$supported_minor;
}

return $supported_wc_version;
Expand Down

0 comments on commit bb3d2f2

Please sign in to comment.