Skip to content

Commit

Permalink
Merge pull request #825 from WordPress/805-plugin-name-non-unicode
Browse files Browse the repository at this point in the history
Add check for unsupported plugin name in plugin header field
  • Loading branch information
ernilambar authored Jan 8, 2025
2 parents 0675a5a + 094d833 commit e927b04
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
19 changes: 19 additions & 0 deletions includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,25 @@ public function run( Check_Result $result ) {
'',
6
);
} else {
$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 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',
$plugin_main_file,
0,
0,
'https://developer.wordpress.org/plugins/plugin-basics/header-requirements/#header-fields',
7
);
}
}
}

Expand Down
24 changes: 24 additions & 0 deletions tests/behat/features/plugin-check.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
<?php
/**
* Plugin Name: अद्भुत प्लगिन
* Plugin URI: https://foo-sample.com
* Description: Custom plugin.
* Version: 0.1.0
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/performance/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
"""

When I run the WP-CLI command `plugin check foo-sample`
Then STDOUT should contain:
"""
plugin_header_unsupported_plugin_name
"""

0 comments on commit e927b04

Please sign in to comment.