Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add valid checks slug array and warning for non-existent checks #470

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions includes/Checker/Abstract_Check_Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@
*/
final public function get_checks_to_run() {
$check_slugs = $this->get_check_slugs();
$check_slugs = $this->return_valid_check_slugs( $check_slugs );
$check_flags = Check_Repository::TYPE_STATIC;

// Check if conditions are met in order to perform Runtime Checks.
Expand Down Expand Up @@ -489,6 +490,30 @@
return $collection->to_map();
}

/**
* Returns an array of valid check slugs.
*
* @since 1.0.1
*
* @param array $check_slugs An array of check slugs to be run.
*
* @return array An array of valid check slugs.
*/
protected function return_valid_check_slugs( array $check_slugs ) {

$available_checks_slugs = array_keys( $this->check_repository->get_checks( Check_Repository::TYPE_ALL )->to_map() );

foreach ( $check_slugs as $slug ) {
if ( ! in_array( $slug, $available_checks_slugs, true ) ) {
echo 'Warning: Check with the slug "' . $slug . '" does not exist.' . PHP_EOL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make translatable the sentence and escape the slug.

$key = array_search( $slug, $check_slugs, true );
unset( $check_slugs[ $key ] );

Check warning on line 510 in includes/Checker/Abstract_Check_Runner.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Abstract_Check_Runner.php#L508-L510

Added lines #L508 - L510 were not covered by tests
}
}

return $check_slugs;
}

/**
* Checks whether the current environment allows for runtime checks to be used.
*
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ In any case, passing the checks in this tool likely helps to achieve a smooth pl

= 1.0.2 =

* Enhancement - Show a warning if a non-existent check if passed to the WP CLI --checks argument. (issue 348)
* Feature - New `Enqueued_Scripts_Scope_Check` (`enqueued_scripts_scope`), `Enqueued_Styles_Size_Check` (`enqueued_styles_size`) and `Enqueued_Resources_Check` (`enqueued_resources`) performance checks.
* Enhancement - Improved readme check and added a new `wp_plugin_check_ignored_readme_warnings` filter.
* Enhancement - New `wp_plugin_check_default_categories` filter to change the categories which are selected by default.
Expand Down
Loading