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 19, 2024
1 parent 91694ca commit 8e0bbbe
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(
/* 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
);
}
}

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(
/* 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
);
}
}

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

0 comments on commit 8e0bbbe

Please sign in to comment.