Skip to content

Rosetta: Translation Teams: Don't read post content when no post is queried - #1258

Closed
obenland wants to merge 1 commit into
WordPress:trunkfrom
obenland:fix/teams-locale-feed-warning
Closed

obenland wants to merge 1 commit into
WordPress:trunkfrom
obenland:fix/teams-locale-feed-warning

Conversation

@obenland

@obenland obenland commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

See https://meta.trac.wordpress.org/ticket/4683

Follow-up to #1257. On singular requests that have no queried post, such as a post’s comment feed (/polyglots/2026/11/06/<slug>/feed/), get_displayed_locale() read post_content off null. That logged “Attempt to read property "post_content" on null” from the wporg_canonical_url filter.

This looks up the requested locale first, so requests without a valid ?locale= return before touching the post. It then reads the content only when the queried object is a WP_Post.

Testing

  1. Open a Polyglots post’s comment feed, for example https://make.wordpress.org/polyglots/2026/11/06/pte-request-for-depicter-chinese-singapore/feed/, and check that no warning is logged.
  2. Open https://make.wordpress.org/polyglots/teams/?locale=id_ID and check that the title still names Indonesian and the canonical still carries ?locale=id_id.
  3. Open https://make.wordpress.org/polyglots/teams/ and check that the title and canonical are the overview page’s.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Locale display now handles invalid locale requests and pages that aren’t eligible for locale information more safely. This prevents locale details from appearing in unsupported page contexts and avoids errors when page content is unavailable or doesn’t contain locale information.

…ueried

On singular requests without a queried post, such as a post's comment
feed, get_displayed_locale() read post_content off null and logged a
warning from the wporg_canonical_url filter. Look up the requested locale
first so most requests return early, and only read the content of a
queried WP_Post.

See #4683.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings November 12, 2026 22:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props obenland.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

get_displayed_locale() now resolves the requested locale before checking page context. It returns null when the request or queried object does not meet the added checks.

Changes: Displayed locale lookup

Layer / File(s) Summary
Guard displayed locale lookup
wordpress.org/public_html/wp-content/plugins/wp-i18n-teams/inc/locales.php
The function returns null if no locale was requested or the page is not singular. It checks that the queried object is a WP_Post containing the [wp-locales] shortcode before returning the locale.

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix

Possibly related PRs

Merge Risk: Minimal · up to 77979

This change stops a PHP warning on comment feeds of singular requests that have no queried post. Title and canonical behavior for valid locale requests is reported as preserved. No actionable merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: get_displayed_locale() no longer reads post_content when no post is queried. The raw summary confirms the locale is resolved first and post_content is read only from a…
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.
Full details: Title check

Explanation

The title names the main change: get_displayed_locale() no longer reads post_content when no post is queried. The raw summary confirms the locale is resolved first and post_content is read only from a WP_Post. The title's wording matches the described change and the PR objectives, so it is related to the changeset.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 87f89a76-3951-4c80-80c5-b1e9c80480af
Commits

Reviewing files that changed from the base of the PR and between 9e44e40 and 77979c3.

Files selected for processing: 1

  • wordpress.org/public_html/wp-content/plugins/wp-i18n-teams/inc/locales.php

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

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