diff --git a/includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php b/includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php index 0d85f41cd..1f4792672 100644 --- a/includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php @@ -97,6 +97,25 @@ public function run( Check_Result $result ) { '', 6 ); + } else { + $valid_chars_count = preg_match_all( '/[a-z0-9]/i', $plugin_header['Name'] ); + + if ( intval( $valid_chars_count ) < 5 ) { + $this->add_result_error_for_file( + $result, + sprintf( + /* translators: %s: plugin header field */ + __( 'The "%s" header in the plugin file is not valid. It needs to contain at least 5 latin letters (a-Z) and/or numbers. This is necessary because the initial plugin slug is generated from the name.', 'plugin-check' ), + esc_html( $labels['Name'] ) + ), + 'plugin_header_unsupported_plugin_name', + $plugin_main_file, + 0, + 0, + 'https://developer.wordpress.org/plugins/plugin-basics/header-requirements/#header-fields', + 7 + ); + } } } diff --git a/tests/behat/features/plugin-check.feature b/tests/behat/features/plugin-check.feature index a90fec119..80c951350 100644 --- a/tests/behat/features/plugin-check.feature +++ b/tests/behat/features/plugin-check.feature @@ -800,3 +800,27 @@ Feature: Test that the WP-CLI command works. """ 18,ERROR,WordPress.WP.I18n.TooManyFunctionArgs,7 """ + + Scenario: Check unsupported plugin name in plugin header field + Given a WP install with the Plugin Check plugin + And a wp-content/plugins/foo-sample/foo-sample.php file: + """ +