From 58839553023f30dd4edddd44d503bc0807629960 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Mon, 23 Jun 2025 11:03:48 +0545 Subject: [PATCH 1/2] Change error type for plugin header fields --- .../Plugin_Header_Fields_Check.php | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 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 39cafdd70..f5d8a2472 100644 --- a/includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php @@ -83,7 +83,7 @@ public function run( Check_Result $result ) { if ( ! empty( $plugin_header['Name'] ) ) { if ( in_array( $plugin_header['Name'], array( 'Plugin Name', 'My Basics Plugin' ), true ) ) { - $this->add_result_warning_for_file( + $this->add_result_error_for_file( $result, sprintf( /* translators: %s: plugin header field */ @@ -95,7 +95,7 @@ public function run( Check_Result $result ) { 0, 0, '', - 6 + 7 ); } else { $valid_chars_count = preg_match_all( '/[a-z0-9]/i', $plugin_header['Name'] ); @@ -121,7 +121,7 @@ public function run( Check_Result $result ) { if ( ! empty( $plugin_header['PluginURI'] ) ) { if ( true !== $this->is_valid_url( $plugin_header['PluginURI'] ) ) { - $this->add_result_warning_for_file( + $this->add_result_error_for_file( $result, sprintf( /* translators: %s: plugin header field */ @@ -132,11 +132,11 @@ public function run( Check_Result $result ) { $plugin_main_file, 0, 0, - '', - 6 + 'https://developer.wordpress.org/plugins/plugin-basics/header-requirements/#header-fields', + 7 ); } elseif ( preg_match( '/\/\/(example\.com|example\.net|example\.org)\//', $plugin_header['PluginURI'], $matches ) ) { - $this->add_result_warning_for_file( + $this->add_result_error_for_file( $result, sprintf( /* translators: 1: plugin header field, 2: domain */ @@ -149,7 +149,7 @@ public function run( Check_Result $result ) { 0, 0, 'https://developer.wordpress.org/plugins/plugin-basics/header-requirements/#header-fields', - 6 + 7 ); } } @@ -175,7 +175,7 @@ public function run( Check_Result $result ) { || str_contains( $plugin_header['Description'], 'Here is a short description of the plugin' ) || str_contains( $plugin_header['Description'], 'Handle the basics with this plugin' ) ) { - $this->add_result_warning_for_file( + $this->add_result_error_for_file( $result, sprintf( /* translators: %s: plugin header field */ @@ -186,8 +186,8 @@ public function run( Check_Result $result ) { $plugin_main_file, 0, 0, - '', - 6 + 'https://developer.wordpress.org/plugins/plugin-basics/header-requirements/#header-fields', + 7 ); } } @@ -239,7 +239,7 @@ public function run( Check_Result $result ) { $plugin_main_file, 0, 0, - '', + 'https://developer.wordpress.org/plugins/plugin-basics/header-requirements/#header-fields', 7 ); } @@ -247,7 +247,7 @@ public function run( Check_Result $result ) { if ( ! empty( $plugin_header['Network'] ) ) { if ( 'true' !== strtolower( $plugin_header['Network'] ) ) { - $this->add_result_warning_for_file( + $this->add_result_error_for_file( $result, sprintf( /* translators: %s: plugin header field */ @@ -259,7 +259,7 @@ public function run( Check_Result $result ) { 0, 0, 'https://developer.wordpress.org/plugins/plugin-basics/header-requirements/#header-fields', - 6 + 7 ); } } From 5bb4bbba9ca54e2ee3fbe40297e9dce0ad946fab Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Mon, 23 Jun 2025 11:11:22 +0545 Subject: [PATCH 2/2] Add test for updated error type --- .../Checks/Plugin_Header_Fields_Check_Tests.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/tests/Checker/Checks/Plugin_Header_Fields_Check_Tests.php b/tests/phpunit/tests/Checker/Checks/Plugin_Header_Fields_Check_Tests.php index 0f052e6d8..4d1847151 100644 --- a/tests/phpunit/tests/Checker/Checks/Plugin_Header_Fields_Check_Tests.php +++ b/tests/phpunit/tests/Checker/Checks/Plugin_Header_Fields_Check_Tests.php @@ -30,11 +30,11 @@ public function test_run_with_errors() { $this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_no_license' ) ) ); $this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_missing_plugin_version' ) ) ); $this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_invalid_author_uri' ) ) ); - $this->assertCount( 1, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'plugin_header_invalid_plugin_uri_domain' ) ) ); - $this->assertCount( 1, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'plugin_header_invalid_plugin_description' ) ) ); + $this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_invalid_plugin_uri_domain' ) ) ); + $this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_invalid_plugin_description' ) ) ); + $this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_invalid_network' ) ) ); $this->assertCount( 1, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'textdomain_mismatch' ) ) ); $this->assertCount( 1, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'plugin_header_nonexistent_domain_path' ) ) ); - $this->assertCount( 1, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'plugin_header_invalid_network' ) ) ); if ( is_wp_version_compatible( '6.5' ) ) { $this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_invalid_requires_plugins' ) ) ); @@ -179,9 +179,10 @@ public function test_run_with_errors_duplicated_protocol_is_valid_url() { $errors = $check_result->get_errors(); $filtered_items = wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_invalid_author_uri' ) ); + $filtered_items = array_values( $filtered_items ); $this->assertCount( 1, $filtered_items ); - $this->assertStringContainsString( 'Author URI', $filtered_items[1]['message'] ); - $this->assertStringContainsString( 'is not valid', $filtered_items[1]['message'] ); + $this->assertStringContainsString( 'Author URI', $filtered_items[0]['message'] ); + $this->assertStringContainsString( 'is not valid', $filtered_items[0]['message'] ); } }