diff --git a/includes/Checker/Abstract_Check_Runner.php b/includes/Checker/Abstract_Check_Runner.php index 368418da3..4429de87a 100644 --- a/includes/Checker/Abstract_Check_Runner.php +++ b/includes/Checker/Abstract_Check_Runner.php @@ -461,6 +461,7 @@ private function get_shared_preparations( array $checks ) { */ 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. @@ -489,6 +490,30 @@ final public function get_checks_to_run() { 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; + $key = array_search( $slug, $check_slugs, true ); + unset( $check_slugs[ $key ] ); + } + } + + return $check_slugs; + } + /** * Checks whether the current environment allows for runtime checks to be used. * diff --git a/readme.txt b/readme.txt index c9c242a8e..0783ac1dc 100644 --- a/readme.txt +++ b/readme.txt @@ -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.