Skip to content

Commit 68d48c1

Browse files
authored
Merge branch 'main' into copilot/add-format-argument-core-install
2 parents 569ffc8 + 07c72a3 commit 68d48c1

8 files changed

Lines changed: 139 additions & 8 deletions

File tree

.github/workflows/copilot-setup-steps.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ jobs:
1717

1818
steps:
1919
- name: Checkout code
20-
uses: actions/checkout@v6
20+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
2121

2222
- name: Check existence of composer.json file
2323
id: check_composer_file
24-
uses: andstor/file-existence-action@v3
24+
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3
2525
with:
2626
files: "composer.json"
2727

2828
- name: Set up PHP environment
2929
if: steps.check_composer_file.outputs.files_exists == 'true'
30-
uses: shivammathur/setup-php@v2
30+
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2
3131
with:
3232
php-version: 'latest'
3333
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
@@ -38,7 +38,7 @@ jobs:
3838

3939
- name: Install Composer dependencies & cache dependencies
4040
if: steps.check_composer_file.outputs.files_exists == 'true'
41-
uses: ramsey/composer-install@v3
41+
uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # v3
4242
env:
4343
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
4444
with:

.github/workflows/issue-triage.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: Issue and PR Triage
44
'on':
55
issues:
66
types: [opened]
7-
pull_request:
7+
pull_request_target:
88
types: [opened]
99
workflow_dispatch:
1010
inputs:
@@ -13,14 +13,21 @@ name: Issue and PR Triage
1313
required: false
1414
type: string
1515

16+
permissions:
17+
issues: write
18+
pull-requests: write
19+
actions: write
20+
contents: read
21+
models: read
22+
1623
jobs:
1724
issue-triage:
1825
uses: wp-cli/.github/.github/workflows/reusable-issue-triage.yml@main
1926
with:
2027
issue_number: >-
2128
${{
2229
(github.event_name == 'workflow_dispatch' && inputs.issue_number) ||
23-
(github.event_name == 'pull_request' && github.event.pull_request.number) ||
30+
(github.event_name == 'pull_request_target' && github.event.pull_request.number) ||
2431
(github.event_name == 'issues' && github.event.issue.number) ||
2532
''
2633
}}

.github/workflows/regenerate-readme.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ on:
1010
- "features/**"
1111
- "README.md"
1212

13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
1317
jobs:
1418
regenerate-readme:
1519
uses: wp-cli/.github/.github/workflows/reusable-regenerate-readme.yml@main
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Welcome New Contributors
2+
3+
on:
4+
pull_request_target:
5+
types: [opened]
6+
branches:
7+
- main
8+
- master
9+
10+
permissions:
11+
pull-requests: write
12+
13+
jobs:
14+
welcome:
15+
uses: wp-cli/.github/.github/workflows/reusable-welcome-new-contributors.yml@main

.typos.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[default]
2+
extend-ignore-re = [
3+
"(?Rm)^.*(#|//)\\s*spellchecker:disable-line$",
4+
"(?s)(#|//)\\s*spellchecker:off.*?\\n\\s*(#|//)\\s*spellchecker:on",
5+
"(#|//)\\s*spellchecker:ignore-next-line\\n.*"
6+
]

features/language-plugin.feature

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,3 +444,41 @@ Feature: Manage plugin translation files for a WordPress install
444444
| akismet | en_US | active |
445445
| akismet | nl_NL | installed |
446446
And STDERR should be empty
447+
448+
@require-wp-4.0
449+
Scenario: Handle plugins with text domain different from slug
450+
Given a WP install
451+
And an empty cache
452+
453+
# Create a test plugin with a different text domain
454+
And a wp-content/plugins/test-plugin/test-plugin.php file:
455+
"""
456+
<?php
457+
/**
458+
* Plugin Name: Test Plugin
459+
* Text Domain: different-text-domain
460+
* Domain Path: /languages
461+
*/
462+
"""
463+
464+
# Manually create a translation file using the text domain (not the plugin slug)
465+
And a wp-content/languages/plugins/different-text-domain-de_DE.l10n.php file:
466+
"""
467+
"""
468+
And a wp-content/languages/plugins/different-text-domain-de_DE.mo file:
469+
"""
470+
"""
471+
And a wp-content/languages/plugins/different-text-domain-de_DE.po file:
472+
"""
473+
"""
474+
475+
When I run `wp language plugin list test-plugin --fields=language,status --format=csv`
476+
Then STDOUT should contain:
477+
"""
478+
en_US,active
479+
"""
480+
And STDERR should be empty
481+
482+
# If the fix is working, installed languages should be detected via text domain
483+
When I run `wp language plugin is-installed test-plugin de_DE`
484+
Then the return code should be 0

features/language-theme.feature

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,39 @@ Feature: Manage theme translation files for a WordPress install
328328
| en_US | active |
329329
| nl_NL | installed |
330330
And STDERR should be empty
331+
332+
@require-wp-4.0
333+
Scenario: Handle themes with text domain different from slug
334+
Given a WP install
335+
And an empty cache
336+
337+
# Create a test theme with a different text domain
338+
And a wp-content/themes/test-theme/style.css file:
339+
"""
340+
/*
341+
Theme Name: Test Theme
342+
Text Domain: different-text-domain
343+
*/
344+
"""
345+
346+
# Manually create a translation file using the text domain (not the theme slug)
347+
And a wp-content/languages/themes/different-text-domain-de_DE.l10n.php file:
348+
"""
349+
"""
350+
And a wp-content/languages/themes/different-text-domain-de_DE.mo file:
351+
"""
352+
"""
353+
And a wp-content/languages/themes/different-text-domain-de_DE.po file:
354+
"""
355+
"""
356+
357+
When I run `wp language theme list test-theme --fields=language,status --format=csv`
358+
Then STDOUT should contain:
359+
"""
360+
en_US,active
361+
"""
362+
And STDERR should be empty
363+
364+
# If the fix is working, installed languages should be detected via text domain
365+
When I run `wp language theme is-installed test-theme de_DE`
366+
Then the return code should be 0

src/WP_CLI/CommandWithTranslation.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,33 @@ protected function get_installed_languages( $slug = 'default' ) {
283283
/**
284284
* @var array<string, array<string, array<string, mixed>>> $available
285285
*/
286-
$available = wp_get_installed_translations( $this->obj_type );
287-
$available = ! empty( $available[ $slug ] ) ? array_keys( $available[ $slug ] ) : array();
286+
$available = wp_get_installed_translations( $this->obj_type );
287+
288+
// For plugins and themes, check if the text domain differs from the slug.
289+
$text_domain = $slug;
290+
if ( 'default' !== $slug ) {
291+
if ( 'plugins' === $this->obj_type ) {
292+
$plugins = get_plugins( '/' . $slug );
293+
if ( ! empty( $plugins ) ) {
294+
$plugin_data = array_shift( $plugins );
295+
// Use the TextDomain header if available, otherwise fall back to slug.
296+
if ( ! empty( $plugin_data['TextDomain'] ) ) {
297+
$text_domain = $plugin_data['TextDomain'];
298+
}
299+
}
300+
} elseif ( 'themes' === $this->obj_type ) {
301+
$theme_data = wp_get_theme( $slug );
302+
if ( $theme_data->exists() ) {
303+
// Use the TextDomain property if available, otherwise fall back to slug.
304+
$theme_text_domain = $theme_data->get( 'TextDomain' );
305+
if ( ! empty( $theme_text_domain ) ) {
306+
$text_domain = $theme_text_domain;
307+
}
308+
}
309+
}
310+
}
311+
312+
$available = ! empty( $available[ $text_domain ] ) ? array_keys( $available[ $text_domain ] ) : array();
288313
$available[] = 'en_US';
289314

290315
return $available;

0 commit comments

Comments
 (0)