Skip to content

Disallow unsupported characters for Text Domain plugin header #955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -411,25 +411,43 @@ public function run( Check_Result $result ) {

if ( ! $result->plugin()->is_single_file_plugin() ) {
if ( ! empty( $plugin_header['TextDomain'] ) ) {
$plugin_slug = $result->plugin()->slug();

if ( $plugin_slug !== $plugin_header['TextDomain'] ) {
$this->add_result_warning_for_file(
if ( ! preg_match( '/^[a-z0-9]+(?:-[a-z0-9]+)*$/', $plugin_header['TextDomain'] ) ) {
$this->add_result_error_for_file(
$result,
sprintf(
/* translators: 1: plugin header field, 2: plugin header text domain, 3: plugin slug */
__( 'The "%1$s" header in the plugin file does not match the slug. Found "%2$s", expected "%3$s".', 'plugin-check' ),
/* translators: 1: plugin header field, 2: text domain */
__( 'The "%1$s" header in the plugin file should only contain lowercase letters, numbers, and hyphens. Found "%2$s".', 'plugin-check' ),
esc_html( $labels['TextDomain'] ),
esc_html( $plugin_header['TextDomain'] ),
esc_html( $plugin_slug )
esc_html( $plugin_header['TextDomain'] )
),
'textdomain_mismatch',
'textdomain_invalid_format',
$plugin_main_file,
0,
0,
'https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/',
6
'https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#text-domains',
7
);
} else {
$plugin_slug = $result->plugin()->slug();

if ( $plugin_slug !== $plugin_header['TextDomain'] ) {
$this->add_result_warning_for_file(
$result,
sprintf(
/* translators: 1: plugin header field, 2: plugin header text domain, 3: plugin slug */
__( 'The "%1$s" header in the plugin file does not match the slug. Found "%2$s", expected "%3$s".', 'plugin-check' ),
esc_html( $labels['TextDomain'] ),
esc_html( $plugin_header['TextDomain'] ),
esc_html( $plugin_slug )
),
'textdomain_mismatch',
$plugin_main_file,
0,
0,
'https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/',
6
);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Author URI: https://make.wordpress.org/performance/
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* Text Domain: test-plugin-check-errors
* Text Domain: Test-plugin-check_errors
* Domain Path: /languages
*
* @package test-plugin-check-errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public function test_run_with_invalid_header_fields() {

$this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_missing_plugin_description' ) ) );
$this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_invalid_plugin_version' ) ) );
$this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'textdomain_invalid_format' ) ) );
}

public function test_run_with_errors_requires_at_least_latest_plus_two_version() {
Expand Down
Loading