fix(submissions): derive source language dynamically, target the other 5#228
Conversation
cdcf_enqueue_translations_for_submission() hardcoded the source as
English: target_langs = ['it','es','fr','pt','de'] (no en), and
$translations['en'] = $source_id. A non-English public submission
got siblings for IT/FR/PT/DE only — EN was missing from the target
list, the source language was silently skipped as "already linked",
and the source post was mis-keyed as the EN translation, so
pll_save_post_translations was handed an invalid {en: source, ...}
map and rejected it → empty Polylang group on every post.
Now reads pll_get_post_language() for the source and pll_languages_list()
for the configured set, computes target_langs = all - source_lang,
and keys the map under the actual source language. Same atomic
shape, same deferred-to-shutdown call site from #227.
Production trigger 2026-06-16: community_project 1534 ("Enciclopedia
Católica") submitted in Spanish; group came out empty, siblings
1552/1553/1554/1555 (it/fr/pt/de) created but no EN.
Parameter renamed $en_post_id → $source_post_id and the docblock
+ error_log lines updated to match the new semantics.
Added regression test covering the ES-source case end-to-end:
asserts pll_save_post_translations gets {es: source, en:..., it:...,
fr:..., pt:..., de:...} and cdcf_enqueue_translation is called for
each non-source language (including en). The wp-cron-fallback test
also gains pll_get_post_language + pll_languages_list stubs.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthrough
ChangesDynamic Polylang Source Language Fan-Out
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 10 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
wordpress/themes/cdcf-headless/tests/SubmissionLifecycleTest.php (1)
381-440: 💤 Low valueSolid regression test for the Spanish-source scenario.
The assertions correctly verify that:
pll_save_post_translationsreceives the map keyed by the actual source language (es)- All five non-source languages (including
en) are enqueued for translation- The source language is not re-enqueued against itself
Regarding the static analysis hint about the unused
$source_idparameter on line 420: this is intentional since the closure must match thecdcf_enqueue_translationsignature. If you want to silence the PHPMD warning, you could prefix it with an underscore ($_source_id), but it's minor and entirely optional.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@wordpress/themes/cdcf-headless/tests/SubmissionLifecycleTest.php` around lines 381 - 440, To silence the PHPMD static analysis warning about the unused parameter, rename the `$source_id` parameter in the closure within the `Functions\when('cdcf_enqueue_translation')->alias()` call to `$_source_id`. This convention indicates that the parameter is intentionally unused but must be present to match the expected function signature.Source: Linters/SAST tools
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@wordpress/themes/cdcf-headless/tests/SubmissionLifecycleTest.php`:
- Around line 381-440: To silence the PHPMD static analysis warning about the
unused parameter, rename the `$source_id` parameter in the closure within the
`Functions\when('cdcf_enqueue_translation')->alias()` call to `$_source_id`.
This convention indicates that the parameter is intentionally unused but must be
present to match the expected function signature.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: dcb8ee41-fbdf-45c2-a5af-4851838c6eba
📒 Files selected for processing (2)
wordpress/themes/cdcf-headless/includes/admin/submission-lifecycle.phpwordpress/themes/cdcf-headless/tests/SubmissionLifecycleTest.php
Summary
['it','es','fr','pt','de']target list and$translations['en'] = $source_idmapping incdcf_enqueue_translations_for_submission()with a dynamic resolution: source language comes frompll_get_post_language()on the source post, the target set ispll_languages_list() - source_lang, and the Polylang group is keyed under the actual source language.{es: source, en: ..., it: ..., fr: ..., pt: ..., de: ...}and that every non-source language (including EN) is enqueued.\$en_post_id→\$source_post_idand updates the docblock + error_log lines to match the new semantics. Same atomic shape, same deferred-to-shutdown call site as fix(submissions): defer translation enqueue to shutdown action #227.Production trigger
community_project1534 ("Enciclopedia Católica") was submitted in Spanish. The hook created siblings for IT/FR/PT/DE only — EN was missing from the hardcoded target list, ES was skipped as "already linked" because the source already carried that language, and the source post was mis-keyed as the EN translation in the atomic save. Polylang rejected the malformed{en: 1534, ...}map → empty group on every post. Recovery on production after this PR merges + deploys: link the existing 5 siblings + create EN sibling via/cdcf/v1/translate.Test plan
composer test --working-dir=wordpress/themes/cdcf-headless— 579/579 pass, including the new ES-source testen=>42instead ofes=>42)gh workflow run deploy.yml -f environment=production, then publish a fresh non-English public submission and verify (a) translations are created for all 5 OTHER languages including EN AND (b) the Polylang group is linked across all 6 siblings🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests