Skip to content

Commit

Permalink
Merge branch 'release/1.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmikita committed Nov 14, 2021
2 parents 855b21b + 3e919e1 commit 61ce4fa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog
All notable changes to this project will be documented in this file.

## 1.1.1

### Changed
- Notice has been moved to a separate template file.
- Notice content is now escaped.

## 1.1.0

### Added
Expand Down
29 changes: 1 addition & 28 deletions src/Requirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class Requirements {
* Default: true.
*/
public function __construct( $plugin_name, $requirements = [], $autoload_checkers = true ) {

$this->plugin_name = $plugin_name;

// Add requirements.
Expand All @@ -82,7 +81,6 @@ public function __construct( $plugin_name, $requirements = [], $autoload_checker
// Load translation.
$i18n = new Internationalization( 'micropackage-requirements', dirname( __DIR__ ) . '/languages' );
$i18n->load_translation();

}

/**
Expand Down Expand Up @@ -116,15 +114,13 @@ public function load_default_checkers() {
* @return $this
*/
public function add( $requirement_slug, $checked_value ) {

if ( isset( $this->requirements[ $requirement_slug ] ) ) {
throw new \Exception( sprintf( 'Requirement %s already exists', $requirement_slug ) );
}

$this->requirements[ $requirement_slug ] = $checked_value;

return $this;

}

/**
Expand All @@ -148,7 +144,6 @@ public function get() {
* @return $this
*/
public function register_checker( $checker ) {

$implements = class_implements( $checker );
$interface = Checkable::class;

Expand All @@ -167,7 +162,6 @@ public function register_checker( $checker ) {
$this->checkers[ $checker->get_name() ] = $checker;

return $this;

}

/**
Expand All @@ -189,13 +183,11 @@ public function has_checker( $name ) {
* @return false|Checkable
*/
public function get_checker( $name ) {

if ( ! $this->has_checker( $name ) ) {
return false;
}

return $this->checkers[ $name ];

}

/**
Expand All @@ -205,7 +197,6 @@ public function get_checker( $name ) {
* @return void
*/
public function check() {

// Reset state.
$this->errors = [];

Expand All @@ -217,7 +208,6 @@ public function check() {
}

$this->did_check = true;

}

/**
Expand All @@ -227,13 +217,11 @@ public function check() {
* @return bool
*/
public function satisfied() {

if ( ! $this->did_check ) {
$this->check();
}

return empty( $this->errors );

}

/**
Expand All @@ -243,28 +231,13 @@ public function satisfied() {
* @return void
*/
public function print_notice() {

if ( $this->satisfied() ) {
return;
}

add_action( 'admin_notices', function() {
// phpcs:disable
echo '<div class="error">';

// Translators - plugin name.
echo '<p>' . sprintf( __( 'The plugin: <strong>%s</strong> cannot be activated.', Requirements::$textdomain ), esc_html( $this->plugin_name ) ) . '</p>';

echo '<ul style="list-style: disc; padding-left: 20px;">';
foreach ( $this->errors as $error ) {
echo '<li>' . $error . '</li>';
}
echo '</ul>';

echo '</div>';
// phpcs:enable
include __DIR__ . '/notice.php';
} );

}

}
29 changes: 29 additions & 0 deletions src/notice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* Notice template
*
* @package micropackage/requirements
*/

use BracketSpace\Notification\Dependencies\Micropackage\Requirements\Requirements;

?>
<div class="error">
<p>
<?php
echo wp_kses_post(
sprintf(
// Translators: Plugin name.
__( 'The plugin: <strong>%s</strong> cannot be activated.', Requirements::$textdomain ),
esc_html( $this->plugin_name )
)
);
?>
</p>

<ul style="list-style: disc; padding-left: 20px;">
<?php foreach ( $this->errors as $error ) : ?>
<li><?php echo esc_html( $error ); ?></li>
<?php endforeach; ?>
</ul>
</div>

0 comments on commit 61ce4fa

Please sign in to comment.