Skip to content

Commit

Permalink
Add more checks for Plugin Header fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Nov 12, 2024
1 parent 74abb6a commit 7493c60
Showing 1 changed file with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,22 @@ public function run( Check_Result $result ) {
}
}

if ( ! empty( $plugin_header['Description'] ) ) {
if ( empty( $plugin_header['Description'] ) ) {
$this->add_result_error_for_file(
$result,
sprintf(
/* translators: %s: plugin header field */
__( 'The "%s" header is missing in the plugin file.', 'plugin-check' ),
esc_html( $labels['Description'] )
),
'plugin_header_missing_plugin_description',
$plugin_main_file,
0,
0,
__( 'https://developer.wordpress.org/plugins/plugin-basics/header-requirements/', 'plugin-check' ),
7
);
} else {
if (
str_contains( $plugin_header['Description'], 'This is a short description of what the plugin does' )
|| str_contains( $plugin_header['Description'], 'Here is a short description of the plugin' )
Expand All @@ -155,6 +170,40 @@ public function run( Check_Result $result ) {
}
}

if ( empty( $plugin_header['Version'] ) ) {
$this->add_result_error_for_file(
$result,
sprintf(
/* translators: %s: plugin header field */
__( 'The "%s" header is missing in the plugin file.', 'plugin-check' ),
esc_html( $labels['Version'] )
),
'plugin_header_missing_plugin_version',
$plugin_main_file,
0,
0,
__( 'https://developer.wordpress.org/plugins/plugin-basics/header-requirements/', 'plugin-check' ),
7
);
} else {
if ( preg_match( '|[^\d\.]|', $plugin_header['Version'] ) ) {
$this->add_result_error_for_file(
$result,
sprintf(

Check warning on line 192 in includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php#L190-L192

Added lines #L190 - L192 were not covered by tests
/* translators: %s: plugin header field */
__( 'The "%s" header in the plugin file should only contain numeric and period characters.', 'plugin-check' ),
esc_html( $labels['Version'] )
),
'plugin_header_invalid_plugin_version',
$plugin_main_file,
0,
0,
__( 'https://developer.wordpress.org/plugins/plugin-basics/header-requirements/', 'plugin-check' ),
7
);

Check warning on line 203 in includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php#L194-L203

Added lines #L194 - L203 were not covered by tests
}
}

if ( ! empty( $plugin_header['AuthorURI'] ) ) {
if ( true !== $this->is_valid_url( $plugin_header['AuthorURI'] ) ) {
$this->add_result_warning_for_file(
Expand All @@ -174,6 +223,29 @@ public function run( Check_Result $result ) {
}
}

if ( ! empty( $plugin_header['PluginURI'] ) && ! empty( $plugin_header['AuthorURI'] ) ) {
$plugin_uri = rtrim( strtolower( $plugin_header['PluginURI'] ), '/' );
$author_uri = rtrim( strtolower( $plugin_header['AuthorURI'] ), '/' );

if ( $plugin_uri === $author_uri ) {
$this->add_result_error_for_file(
$result,
sprintf(

Check warning on line 233 in includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php#L231-L233

Added lines #L231 - L233 were not covered by tests
/* translators: 1: plugin uri header field, 2: author uri header field */
__( 'The "%1$s" and "%2$s" header in the plugin file must be different. It is not required to provide both, so pick the one that best applies to your situation.', 'plugin-check' ),
esc_html( $labels['PluginURI'] ),
esc_html( $labels['AuthorURI'] )
),
'plugin_header_same_plugin_author_uri',
$plugin_main_file,
0,
0,
__( 'https://developer.wordpress.org/plugins/plugin-basics/header-requirements/', 'plugin-check' ),
7
);

Check warning on line 245 in includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php#L235-L245

Added lines #L235 - L245 were not covered by tests
}
}

if ( ! empty( $plugin_header['Network'] ) ) {
if ( 'true' !== strtolower( $plugin_header['Network'] ) ) {
$this->add_result_warning_for_file(
Expand Down

0 comments on commit 7493c60

Please sign in to comment.