Repository navigation
Keep bibliography data out of Jetpack Search - #317
Conversation
Jetpack Search indexes the text inside <script> elements, so result excerpts showed bibliography JSON-LD and CSL-JSON, and posts saved before 1.12.0 showed the Cite / Export panel's labels. Filter the post objects Jetpack Sync queues and sends (save_post, published_post, and full sync posts, at priority 20 so Jetpack has rendered post_content_filtered) and remove the same site-only parts email and feeds drop, inside each bibliography <section>, from a clone of post_content and post_content_filtered. Stored posts and rendered pages are unchanged. The removals move into bibliography_builder_strip_site_only_markup(), shared with bibliography_builder_portable_markup(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WPtgA1o74AsoqnRXEGoYa1
Plugin readme previewOpen preview · Commit 37 passed · 0 warnings · 0 notes Passed checks (37)
Readme and PHP-header checks only; this does not test plugin runtime compatibility. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #317 +/- ##
============================================
+ Coverage 87.30% 87.34% +0.04%
Complexity 67 67
============================================
Files 114 115 +1
Lines 12875 12917 +42
Branches 1373 1373
============================================
+ Hits 11240 11282 +42
Misses 489 489
Partials 1146 1146 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
…-q82hkw # Conflicts: # docs/current-metrics.md
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WPtgA1o74AsoqnRXEGoYa1
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WPtgA1o74AsoqnRXEGoYa1
dknauss
left a comment
There was a problem hiding this comment.
Independent review
I read includes/jetpack-search.php and the email-output.php split fresh and ran the regexes in PHP 8.3 (JIT on, default pcre.backtrack_limit of 1,000,000). No blocker. The mutation question checks out: bibliography_builder_jetpack_sync_clean_post() returns a shallow clone only when a field changed, and the fields are strings, so the save_post object and the cached WP_Post other callbacks see are untouched. Non-object members ($flags, $update, metadata and term objects without post_content) pass through array_map() with keys kept, and false (Jetpack dropping an action) passes through.
Findings, ranked:
bibliography_builder_strip_site_only_markup()turns a regex failure into an empty string (low, mostly pre-existing).(string) preg_replace( … )castsnullto''. Reproduced: a block whose JSON-LD<script>is over ~1 MB returnsint(0)length, because.*?</script>hits the backtrack limit. In the sync path this can't fire, since the outer.*?</section>spans the whole block, hits the limit first, andbibliography_builder_strip_bibliography_site_only_markup()correctly falls back to the original content. Butbibliography_builder_portable_markup()(email and feeds) has no outer guard, so a very large bibliography would vanish from the email. Suggest:$out = preg_replace( … ); return is_string( $out ) ? $out : $html;. Worth doing now that the function is shared.- Huge blocks sync uncleaned (fail-open, by design). A block over ~1 MB makes the outer pattern fail, so the whole post goes to Jetpack unchanged and the raw JSON is indexed. That's the right failure direction, but a line in the docblock would help.
- Worth confirming on a real Jetpack site: that immediate full sync (
Full_Sync_Immediately, the default in current Jetpack) still sends posts throughjetpack_sync_before_send_jetpack_full_sync_posts, after the posts module's ID expansion at priority 10. That path can't run in CI, and the tests only call the callback directly. - Verify, maybe nothing: raw
post_contentalso carries the full CSL-JSON in the block comment delimiter (<!-- wp:bibliography-builder/bibliography {"citations":[…]} -->). If Jetpack's indexer strips HTML comments (it should, via tag stripping), this is a non-issue; if excerpts ever show"citations":[, that's where it comes from.
On the HTML API (Dan's question): I don't think it's a clear win here. WP_HTML_Tag_Processor finds tags and edits attributes, but it can't remove elements, and this code removes <details>, <span>s, and <script>s. Since 6.7 set_modifiable_text() can empty a <script>'s contents, which would be enough for search, but the plugin supports 6.4, and the PHPUnit bootstrap has no copy of the processor. The patterns here are anchored to save()'s exact output, so with the null guard from item 1 I'd keep the regex.
Generated by Claude Code
Requested by Dan · project thread
Fixes #290.
Summary
includes/jetpack-search.php, hooks three Jetpack Sync filters at priority 20:jetpack_sync_before_enqueue_jetpack_sync_save_post,jetpack_sync_before_enqueue_jetpack_published_post, andjetpack_sync_before_send_jetpack_full_sync_posts. Priority 20 puts it after Jetpack's own callbacks, which renderpost_content_filteredand turn full-sync IDs into post objects.post_contentandpost_content_filtered.<section class="wp-block-bibliography-builder-bibliography">it removes:<details>panel and thedata-cite-*data.bibliography_builder_strip_site_only_markup(), whichbibliography_builder_portable_markup()now calls.bibliography_builder_clean_jetpack_syncfilter (default true) turns the cleaning off, for example once Search: indexed content keeps the text of <script> elements (JSON-LD shows up in result excerpts) Automattic/jetpack#54779 is fixed upstream.<script>elements. Result excerpts showed raw data like"author":[{"@type":"Person",…and labels like "Cite / Export Copy citation RIS CSL-JSON BibTeX BibLaTeX".verify-metrics.shforbids that. Posts that are already indexed get cleaned the next time they sync. The readme FAQ and CHANGELOG givewp jetpack sync start --modules=postsfor cleaning everything at once.class-posts.phpin Jetpack'sjetpack-syncpackage: save_post is[$id, $post, $update, $prev], published_post is[$id, $flags, $post], and full sync is[$posts[], $meta, $terms, $end].Validation
npm run lint:jspasses (no JS changed)npm run lint:csspasses (no CSS changed)npm run lint:i18npasses when source strings or translation docs change (no strings changed)npm run testpasses (CI)npm run buildsucceeds (CI)composer test:php: all 879 tests pass, including the newJetpackSearchTest. It checks that:composer lint:phpandverify-metrics.shpass (metrics updated)Checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_01WPtgA1o74AsoqnRXEGoYa1