fix(polylang): repair single-post machine translation#27
Merged
Conversation
gds/translations-machine crashed on the single-post path (string and post-collection paths were unaffected) due to two bugs in MachineTranslateAbility::translatePost(): 1. send_to_export() expects WP_Post[], but we passed [$postId] (int). The int reached Polylang Pro's ACF block dispatcher as `new Blocks($post->ID)` where `->ID` on an int is null, throwing a TypeError. Pass the WP_Post object we already fetched. 2. Polylang's save path calls get_default_post_to_edit(), a wp-admin/includes/post.php function not loaded in the REST/MCP/CLI context. Guarded require_once, matching ManageRevisionsAbility and MediaUploadAbility. Adds a regression test driving the export path with a block post; it reproduces bug 1 without needing DeepL (skips when Polylang Pro is absent, e.g. under wp-env's free Polylang; runs under DDEV). Verified end-to-end against DeepL: new translation, overwrite of an existing translation, a second target language, a custom post type with ACF meta, and undo/revert all succeed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
gds/translations-machinefailed on the single-post path while the bulk string path worked fine. Two separate bugs inMachineTranslateAbility::translatePost():Blocks::__construct(): Argument #1 ($id) must be of type int, null givenPLL_Export_Data_From_Posts::send_to_export()expectsWP_Post[], but we passed[$postId](an int). Inside Polylang Pro the int reaches the ACF block dispatcher asnew Blocks($post->ID)—->IDon an int isnull, so it throws aTypeError.Call to undefined function get_default_post_to_edit()Polylang's save path calls
get_default_post_to_edit(), which lives inwp-admin/includes/post.phpand isn't loaded in the REST/MCP/CLI context this ability runs in.Fix
$postWP_Postobject we already fetched, instead of the int ID.require_once ABSPATH.'wp-admin/includes/post.php'— the same pattern already used inManageRevisionsAbilityandMediaUploadAbility.Tests
Adds
test_machine_translate_export_accepts_post_object, which drives the same export path the ability uses with a block post. It reproduces bug 1 without needing DeepL. It skips when Polylang Pro is absent (e.g. wp-env's free Polylang) and runs under DDEV where Pro is installed.Verification
Confirmed end-to-end against real DeepL:
🤖 Generated with Claude Code