From c121799ef7d4d630567ae7f75ecb24083af7f2db Mon Sep 17 00:00:00 2001 From: Luiz Bills Date: Mon, 5 Sep 2022 09:16:38 -0300 Subject: [PATCH] 1.5 --- CHANGELOG.md | 10 ++++++++-- core/Dependencies.php | 40 ++++++++++++++++++++++------------------ core/VERSION | 2 +- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2e669e..ed846ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,18 +4,24 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 1.5.0 - 2022-09-01 + +[Source code changes](https://github.com/luizbills/wp-plugin-base/compare/1.4.1...1.5.0) + +- Fix and improve the missing dependencies notice. + ## 1.4.1 - 2022-09-01 [Source code changes](https://github.com/luizbills/wp-plugin-base/compare/1.4.0...1.4.1) -- Fix: incorrect `h::log` output. +- Fix: incorrect `h::log` output. ## 1.4.0 - 2022-09-01 [Source code changes](https://github.com/luizbills/wp-plugin-base/compare/1.3.1...1.4.0) - Feat: allow class instances in `loader.php`. -- Fix: remove *falsy* values from `loader.php`. +- Fix: remove *falsy* values from `loader.php`. ## 1.3.1 - 2022-08-19 diff --git a/core/Dependencies.php b/core/Dependencies.php index fb00aa7..864a20b 100644 --- a/core/Dependencies.php +++ b/core/Dependencies.php @@ -107,35 +107,39 @@ protected static function handle_shortcut ( $shortcut ) { protected static function display_notice_missing_deps ( $messages ) { if ( ! \is_admin() ) return; if ( ! \current_user_can( 'install_plugins' ) ) return; - if ( 0 === ( $messages ) ) return; + if ( 0 === count( $messages ) ) return; - \add_action( 'admin_notices', function () use ( $messages ) { - $allowed_html = [ - 'a' => [ 'href' => [], 'title' => [] ], - 'span' => [ 'class' => [], 'style' => [] ], - 'br' => [], - 'em' => [], - 'strong' => [], - ]; + \usort( $messages, function ( $a, $b ) { + return $b['is_error'] <=> $a['is_error']; + } ); + \add_action( 'admin_notices', function () use ( $messages ) { echo "

"; echo sprintf( /* translators: %s is replaced with plugin name */ - __( 'Missing dependencies for %s:', 'wc-variations-table' ), + __( 'The %s plugin needs the following dependencies to work:', 'your-text-domain' ), "" . Config::get( 'NAME' ) . "", ); + $indent = \str_repeat( ' ', 4 ); + $missing = esc_html__( 'Missing', 'your-text-domain' ); + $allowed_html = [ + 'a' => [ 'href' => [], 'target' => [] ], + 'span' => [ 'class' => [], 'style' => [] ], + 'em' => [], + 'strong' => [], + 'code' => [], + ]; foreach ( $messages as $message ) { - $icon = $message['is_error'] ? 'no-alt' : 'yes'; - $color = $message['is_error'] ? '#e03131' : '#2b8a3e'; $line = \sprintf( - '
%s %s', - \str_repeat( ' ', 4 ), - $color, - $icon, - $message['text'] + ' %s%s', + $message['is_error'] ? '#e03131' : '#2b8a3e', + $message['is_error'] ? 'minus' : 'yes', + $message['is_error'] ? "$missing: " : '', + \wp_kses( $message['text'], $allowed_html ) ); - echo \wp_kses( $line, $allowed_html ); + $line = $message['is_error'] ? $line : "$line"; + echo "
{$indent} {$line}"; } echo '

'; diff --git a/core/VERSION b/core/VERSION index 347f583..bc80560 100644 --- a/core/VERSION +++ b/core/VERSION @@ -1 +1 @@ -1.4.1 +1.5.0