Skip to content

Update /theme-check/checks/class-title-check.php. Validate two text-d…#463

Open
productivemindsdotcom wants to merge 1 commit intoWordPress:masterfrom
productivemindsdotcom:class-textdomain-check
Open

Update /theme-check/checks/class-title-check.php. Validate two text-d…#463
productivemindsdotcom wants to merge 1 commit intoWordPress:masterfrom
productivemindsdotcom:class-textdomain-check

Conversation

@productivemindsdotcom
Copy link
Contributor

Validate two text-domains for child themes

File: /theme-check/checks/class-textdomain-check.php

Error:
The file correctly collects all unique text domains used in both parent and child themes. However, it incorrectly expects that only one text domain has been used across both parent and child themes. As a result, it displays an error message when the two correct domains (one for the parent theme and one for the child theme) are found.

Fix:
When, and only when, valid text domains for both child and parent themes are found, an appropriate "INFO" message is displayed instead of an error.

Reasoning behind the fix:
The parent theme must be activated to use a child theme. Consequently, the parent theme should be translated into any language that the child theme is being translated into. Therefore, when validating a child theme, it makes sense to check for both the parent and child theme text domains.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts Theme Check’s text-domain validation to avoid flagging valid child themes (which legitimately include both child + parent theme domains) as incompatible with WordPress.org language packs.

Changes:

  • Adds theme “Template” context to the TextDomain_Check.
  • Introduces logic to detect a valid child+parent theme text-domain pair and emit an INFO message instead of a WARNING when exactly those two domains are present.
  • Keeps existing behavior for multiple unrelated text domains.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +211 to +226

$this_name = sanitize_title_with_dashes( $this->name );
$this_template = sanitize_title_with_dashes( $this->template );

$get_stylesheet = get_stylesheet();
$get_stylesheet = sanitize_title_with_dashes( $get_stylesheet );

$get_template = get_template();
$get_template = sanitize_title_with_dashes( $get_template );

$wp_get_theme = wp_get_theme();
$wp_get_theme_template = sanitize_title_with_dashes( $wp_get_theme['Template'] );

$is_theme_confirmed = $this_name == $get_stylesheet;
$is_template_confirmed = ($this_template == $get_template) && ($this_template == $wp_get_theme_template);

Comment on lines +212 to +242
$this_name = sanitize_title_with_dashes( $this->name );
$this_template = sanitize_title_with_dashes( $this->template );

$get_stylesheet = get_stylesheet();
$get_stylesheet = sanitize_title_with_dashes( $get_stylesheet );

$get_template = get_template();
$get_template = sanitize_title_with_dashes( $get_template );

$wp_get_theme = wp_get_theme();
$wp_get_theme_template = sanitize_title_with_dashes( $wp_get_theme['Template'] );

$is_theme_confirmed = $this_name == $get_stylesheet;
$is_template_confirmed = ($this_template == $get_template) && ($this_template == $wp_get_theme_template);

$is_child_and_parent_theme_count = 0;
$is_valid_child_and_parent_theme = false;
if( ( !empty($this_name) && !empty($this_template) ) &&
( $this_name != $this_template ) &&
( 2 == $domainscount ) &&
( $is_theme_confirmed && $is_template_confirmed ) )
{
// If we get here, this is likely a child theme, along with corresponding parent theme
foreach ( $domains as $domain ) {
$domain_sanitized = sanitize_title_with_dashes( $domain );
if( $this_name == $domain_sanitized ) {
$is_child_and_parent_theme_count += 1;
}
if( $this_template == $domain_sanitized ) {
$is_child_and_parent_theme_count += 1;
}
Comment on lines +211 to 249

$this_name = sanitize_title_with_dashes( $this->name );
$this_template = sanitize_title_with_dashes( $this->template );

$get_stylesheet = get_stylesheet();
$get_stylesheet = sanitize_title_with_dashes( $get_stylesheet );

$get_template = get_template();
$get_template = sanitize_title_with_dashes( $get_template );

$wp_get_theme = wp_get_theme();
$wp_get_theme_template = sanitize_title_with_dashes( $wp_get_theme['Template'] );

$is_theme_confirmed = $this_name == $get_stylesheet;
$is_template_confirmed = ($this_template == $get_template) && ($this_template == $wp_get_theme_template);

$is_child_and_parent_theme_count = 0;
$is_valid_child_and_parent_theme = false;
if( ( !empty($this_name) && !empty($this_template) ) &&
( $this_name != $this_template ) &&
( 2 == $domainscount ) &&
( $is_theme_confirmed && $is_template_confirmed ) )
{
// If we get here, this is likely a child theme, along with corresponding parent theme
foreach ( $domains as $domain ) {
$domain_sanitized = sanitize_title_with_dashes( $domain );
if( $this_name == $domain_sanitized ) {
$is_child_and_parent_theme_count += 1;
}
if( $this_template == $domain_sanitized ) {
$is_child_and_parent_theme_count += 1;
}
}
if( 2 == $is_child_and_parent_theme_count ) {
// If we get here, this is definitely a child theme, along with corresponding parent theme
$is_valid_child_and_parent_theme = true;
}
}

'<strong>' . $domainlist . '</strong>'
)
);
} else if ( $domainscount > 1 ) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants