Skip to content

fix(submissions): walk the polylang group when checking submitter meta#230

Merged
JohnRDOrazio merged 1 commit into
mainfrom
fix/public-submission-walks-polylang-group
Jun 16, 2026
Merged

fix(submissions): walk the polylang group when checking submitter meta#230
JohnRDOrazio merged 1 commit into
mainfrom
fix/public-submission-walks-polylang-group

Conversation

@JohnRDOrazio

@JohnRDOrazio JohnRDOrazio commented Jun 16, 2026

Copy link
Copy Markdown
Member

Summary

  • Rewrite cdcf_is_public_submission() to walk pll_get_post_translations() and return true if ANY sibling carries _submission_submitter_email or _referral_submitter_email. The old shape resolved to "the EN sibling" via cdcf_get_source_post_id() and only read meta there — which fails for non-English public submissions, where the meta lives on the originally-submitted post (the language the human used) and the auto-translated EN sibling has none.
  • Falls back to a single-post check when Polylang isn't active or the post is in no group.
  • Replaces the existing test_is_public_submission_resolves_translation_to_source_via_polylang with test_is_public_submission_true_when_any_sibling_in_the_polylang_group_carries_submitter_meta covering the production scenario (ES carries meta, called with the EN sibling, with another non-source sibling, and with the source itself). Three legacy single-post tests gain a pll_get_post_translations stub that returns [] so they exercise the new fallback path.

Production trigger

community_project 1534 ("Enciclopedia Católica") was submitted in Spanish; the ES post carried the referral meta and the cdcf_link_referral_on_publish hook correctly appended 1534 to /es/proyectos. But when the worker auto-translated and promoted siblings 1552–1556 (it/fr/pt/de/en) to publish, the hook re-fired for each — and cdcf_is_public_submission walked to the EN sibling (1556), found no meta there, and bailed. Result: the encyclopedia was invisible on /projects, /it/progetti, /fr/projets, /pt/projetos, /de/projekte. Manual recovery via update-relationship on pages 6/86/88/89/90 unblocked production; this PR closes the gap so the next non-English referral surfaces automatically.

Test plan

  • composer test --working-dir=wordpress/themes/cdcf-headless — 579/579 pass
  • Verified RED first: the new test fails against pre-fix code at "Calling with the EN sibling (200) must still recognize the submission as public"
  • After merge: deploy with gh workflow run deploy.yml -f environment=production, then verify by re-running the worker (or by adding a fresh test referral in a non-English language) that the matching-language projects page picks up the post automatically

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved multilingual submission handling to correctly identify public submissions across all language versions, ensuring submitter metadata is properly recognized regardless of which language version is accessed.

cdcf_is_public_submission() resolved its post to "the EN sibling" via
cdcf_get_source_post_id() and read submitter meta from there. For a
non-English public submission the meta lives on the originally-submitted
post (the language the human used), and the auto-translated EN sibling
has no meta — so the gate returned false for every sibling whose own
post lacked the meta. cdcf_link_referral_on_publish then bailed and the
sibling was never appended to its language's projects page
community_projects relationship field.

Now walks pll_get_post_translations() for the entire group and returns
true if ANY sibling carries _submission_submitter_email or
_referral_submitter_email. Falls back to a single-post check when
Polylang is missing or the post is in no group.

Production trigger 2026-06-16: community_project 1534 ("Enciclopedia
Católica") submitted in Spanish. ES sibling 1534 carried the referral
meta and was appended to /es/proyectos. EN sibling 1556 (and IT/FR/PT/DE)
got auto-translated and worker-promoted to publish, but the publish hook
saw no meta on the EN-resolved post and bailed — so the encyclopedia
never appeared on /projects, /it/progetti, /fr/projets, /pt/projetos,
/de/projekte.

Replaces the old test_is_public_submission_resolves_translation_to_source_via_polylang
with test_is_public_submission_true_when_any_sibling_in_the_polylang_group_carries_submitter_meta
covering the production scenario (ES carries meta, called with the EN
sibling, also with another non-source sibling, also with the source
itself). The three legacy single-post tests gain a pll_get_post_translations
stub that returns an empty group, exercising the new fallback path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e4b61ec9-ae10-4f13-a2b3-1efe8bd49ad7

📥 Commits

Reviewing files that changed from the base of the PR and between 5589dad and 0806e81.

📒 Files selected for processing (2)
  • wordpress/themes/cdcf-headless/includes/admin/submission-lifecycle.php
  • wordpress/themes/cdcf-headless/tests/SubmissionLifecycleTest.php

📝 Walkthrough

Walkthrough

cdcf_is_public_submission() is refactored to call pll_get_post_translations() and iterate all Polylang translation-group post IDs when checking for _submission_submitter_email or _referral_submitter_email meta, replacing the prior single-source resolution via cdcf_get_source_post_id(). Existing tests gain pll_get_post_translations() stubs, and a new test verifies the cross-sibling detection.

Changes

Polylang Group Traversal for Public Submission Check

Layer / File(s) Summary
cdcf_is_public_submission() group traversal logic
wordpress/themes/cdcf-headless/includes/admin/submission-lifecycle.php
Replaces cdcf_get_source_post_id() with pll_get_post_translations() to build a candidate list of all sibling post IDs, then iterates them and returns true if any carries _submission_submitter_email or _referral_submitter_email. Docblock expanded to document the translation-group behavior.
Updated and new tests for group traversal
wordpress/themes/cdcf-headless/tests/SubmissionLifecycleTest.php
Existing submission-email, referral-email, and false-case tests gain pll_get_post_translations() stubs. A new test models a multi-language sibling group where only one sibling holds referral meta, asserting cdcf_is_public_submission() returns true for any sibling ID and the source post.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • CatholicOS/cdcf-website#37: Introduced auto-translation logic at approval time that relies on cdcf_is_public_submission() as a gate, which is directly affected by this group-traversal refactor.
  • CatholicOS/cdcf-website#200: Added cdcf_link_referral_on_publish hook that also gates on cdcf_is_public_submission(), making the Polylang sibling metadata recognition change directly relevant to its behavior and tests.

Poem

🐇 Hop across the sibling rows,
Each translation group now glows—
No single source shall gate the truth,
We scan them all, forsooth forsooth!
If any cousin holds the key,
The submission's public—trust in me! 🌍

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: fixing submission detection by walking the Polylang group instead of only checking the English source post.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/public-submission-walks-polylang-group

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...f-headless/includes/admin/submission-lifecycle.php 91.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 6 complexity

Metric Results
Complexity 6

View in Codacy

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.

@JohnRDOrazio

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@JohnRDOrazio JohnRDOrazio merged commit 3410d56 into main Jun 16, 2026
13 checks passed
@JohnRDOrazio JohnRDOrazio deleted the fix/public-submission-walks-polylang-group branch June 16, 2026 21:02
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.

2 participants