From e239e48acc2916ce37c178bb51e83cba07da56aa Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Tue, 10 Dec 2024 12:35:29 +0545 Subject: [PATCH 1/4] Add check for unsupported plugin name --- .../Plugin_Header_Fields_Check.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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..53b47b570 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 { + $potential_slug = sanitize_title_with_dashes( str_replace( '_', '-', preg_replace( '/[^a-z0-9 _.-]/i', '', remove_accents( $plugin_header['Name'] ) ) ) ); + + if ( empty( $potential_slug ) ) { + $this->add_result_error_for_file( + $result, + sprintf( + /* translators: %s: plugin header field */ + __( 'The "%s" header in the plugin file is not valid. It may only contain latin letters (A-z), numbers, spaces, and hyphens.', '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 + ); + } } } From d7de0f62e27e6b50444971db42a50df473525a3e Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Tue, 7 Jan 2025 17:44:06 +0545 Subject: [PATCH 2/4] Update feature test --- tests/behat/features/plugin-check.feature | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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: + """ + Date: Wed, 8 Jan 2025 15:32:54 +0545 Subject: [PATCH 3/4] Update the conditional --- .../Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 53b47b570..f4538a994 100644 --- a/includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php @@ -98,9 +98,9 @@ public function run( Check_Result $result ) { 6 ); } else { - $potential_slug = sanitize_title_with_dashes( str_replace( '_', '-', preg_replace( '/[^a-z0-9 _.-]/i', '', remove_accents( $plugin_header['Name'] ) ) ) ); + $valid_chars_count = preg_match_all( '/[a-z0-9-]/i', $plugin_header['Name'] ); - if ( empty( $potential_slug ) ) { + if ( intval( $valid_chars_count ) < 5 ) { $this->add_result_error_for_file( $result, sprintf( From 094d83347259cc48cf27e211099db80c3fdaa35e Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Wed, 8 Jan 2025 16:33:06 +0545 Subject: [PATCH 4/4] Update error message --- .../Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 f4538a994..1f4792672 100644 --- a/includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php @@ -98,14 +98,14 @@ public function run( Check_Result $result ) { 6 ); } else { - $valid_chars_count = preg_match_all( '/[a-z0-9-]/i', $plugin_header['Name'] ); + $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 may only contain latin letters (A-z), numbers, spaces, and hyphens.', 'plugin-check' ), + __( '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',