Skip to content

Commit 0fb011c

Browse files
authored
Merge pull request #972 from WordPress/error-type-plugin-headers
Change error type for fields in plugin headers
2 parents ad50686 + 842b9cf commit 0fb011c

2 files changed

Lines changed: 19 additions & 18 deletions

File tree

includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function run( Check_Result $result ) {
8383

8484
if ( ! empty( $plugin_header['Name'] ) ) {
8585
if ( in_array( $plugin_header['Name'], array( 'Plugin Name', 'My Basics Plugin' ), true ) ) {
86-
$this->add_result_warning_for_file(
86+
$this->add_result_error_for_file(
8787
$result,
8888
sprintf(
8989
/* translators: %s: plugin header field */
@@ -95,7 +95,7 @@ public function run( Check_Result $result ) {
9595
0,
9696
0,
9797
'',
98-
6
98+
7
9999
);
100100
} else {
101101
$valid_chars_count = preg_match_all( '/[a-z0-9]/i', $plugin_header['Name'] );
@@ -121,7 +121,7 @@ public function run( Check_Result $result ) {
121121

122122
if ( ! empty( $plugin_header['PluginURI'] ) ) {
123123
if ( true !== $this->is_valid_url( $plugin_header['PluginURI'] ) ) {
124-
$this->add_result_warning_for_file(
124+
$this->add_result_error_for_file(
125125
$result,
126126
sprintf(
127127
/* translators: %s: plugin header field */
@@ -132,11 +132,11 @@ public function run( Check_Result $result ) {
132132
$plugin_main_file,
133133
0,
134134
0,
135-
'',
136-
6
135+
'https://developer.wordpress.org/plugins/plugin-basics/header-requirements/#header-fields',
136+
7
137137
);
138138
} elseif ( preg_match( '/\/\/(example\.com|example\.net|example\.org)\//', $plugin_header['PluginURI'], $matches ) ) {
139-
$this->add_result_warning_for_file(
139+
$this->add_result_error_for_file(
140140
$result,
141141
sprintf(
142142
/* translators: 1: plugin header field, 2: domain */
@@ -149,7 +149,7 @@ public function run( Check_Result $result ) {
149149
0,
150150
0,
151151
'https://developer.wordpress.org/plugins/plugin-basics/header-requirements/#header-fields',
152-
6
152+
7
153153
);
154154
}
155155
}
@@ -175,7 +175,7 @@ public function run( Check_Result $result ) {
175175
|| str_contains( $plugin_header['Description'], 'Here is a short description of the plugin' )
176176
|| str_contains( $plugin_header['Description'], 'Handle the basics with this plugin' )
177177
) {
178-
$this->add_result_warning_for_file(
178+
$this->add_result_error_for_file(
179179
$result,
180180
sprintf(
181181
/* translators: %s: plugin header field */
@@ -186,8 +186,8 @@ public function run( Check_Result $result ) {
186186
$plugin_main_file,
187187
0,
188188
0,
189-
'',
190-
6
189+
'https://developer.wordpress.org/plugins/plugin-basics/header-requirements/#header-fields',
190+
7
191191
);
192192
}
193193
}
@@ -239,15 +239,15 @@ public function run( Check_Result $result ) {
239239
$plugin_main_file,
240240
0,
241241
0,
242-
'',
242+
'https://developer.wordpress.org/plugins/plugin-basics/header-requirements/#header-fields',
243243
7
244244
);
245245
}
246246
}
247247

248248
if ( ! empty( $plugin_header['Network'] ) ) {
249249
if ( 'true' !== strtolower( $plugin_header['Network'] ) ) {
250-
$this->add_result_warning_for_file(
250+
$this->add_result_error_for_file(
251251
$result,
252252
sprintf(
253253
/* translators: %s: plugin header field */
@@ -259,7 +259,7 @@ public function run( Check_Result $result ) {
259259
0,
260260
0,
261261
'https://developer.wordpress.org/plugins/plugin-basics/header-requirements/#header-fields',
262-
6
262+
7
263263
);
264264
}
265265
}

tests/phpunit/tests/Checker/Checks/Plugin_Header_Fields_Check_Tests.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public function test_run_with_errors() {
3030
$this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_no_license' ) ) );
3131
$this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_missing_plugin_version' ) ) );
3232
$this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_invalid_author_uri' ) ) );
33-
$this->assertCount( 1, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'plugin_header_invalid_plugin_uri_domain' ) ) );
34-
$this->assertCount( 1, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'plugin_header_invalid_plugin_description' ) ) );
33+
$this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_invalid_plugin_uri_domain' ) ) );
34+
$this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_invalid_plugin_description' ) ) );
35+
$this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_invalid_network' ) ) );
3536
$this->assertCount( 1, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'textdomain_mismatch' ) ) );
3637
$this->assertCount( 1, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'plugin_header_nonexistent_domain_path' ) ) );
37-
$this->assertCount( 1, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'plugin_header_invalid_network' ) ) );
3838

3939
if ( is_wp_version_compatible( '6.5' ) ) {
4040
$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() {
179179
$errors = $check_result->get_errors();
180180

181181
$filtered_items = wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_invalid_author_uri' ) );
182+
$filtered_items = array_values( $filtered_items );
182183

183184
$this->assertCount( 1, $filtered_items );
184-
$this->assertStringContainsString( 'Author URI', $filtered_items[1]['message'] );
185-
$this->assertStringContainsString( 'is not valid', $filtered_items[1]['message'] );
185+
$this->assertStringContainsString( 'Author URI', $filtered_items[0]['message'] );
186+
$this->assertStringContainsString( 'is not valid', $filtered_items[0]['message'] );
186187
}
187188
}

0 commit comments

Comments
 (0)