Skip to content

Keep bibliography data out of Jetpack Search - #317

Merged
dknauss merged 4 commits into
mainfrom
claude/project-thread-q82hkw
Nov 30, 2026
Merged

dknauss merged 4 commits into
mainfrom
claude/project-thread-q82hkw

Conversation

@dknauss

@dknauss dknauss commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Requested by Dan · project thread

Fixes #290.

Summary

  • What changed? A new file, 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, and jetpack_sync_before_send_jetpack_full_sync_posts. Priority 20 puts it after Jetpack's own callbacks, which render post_content_filtered and turn full-sync IDs into post objects.
    • For each post object in the arguments (or in a list there, for full sync), it cleans a clone of post_content and post_content_filtered.
    • Inside each <section class="wp-block-bibliography-builder-bibliography"> it removes:
      • the JSON-LD and CSL-JSON scripts, both the current form and the pre-1.11 array form;
      • COinS and the hidden microformats span;
      • the legacy Cite / Export <details> panel and the data-cite-* data.
    • Email and feeds already make these removals. The code moves unchanged into bibliography_builder_strip_site_only_markup(), which bibliography_builder_portable_markup() now calls.
    • Content outside bibliography blocks, including other plugins' scripts, is left alone. The stored post and the rendered page don't change, so neither does the structured data search engines read.
    • The bibliography_builder_clean_jetpack_sync filter (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.
  • Why? Jetpack Search's indexer keeps the text inside <script> elements. Result excerpts showed raw data like "author":[{"@type":"Person",… and labels like "Cite / Export Copy citation RIS CSL-JSON BibTeX BibLaTeX".
  • No automatic full sync on upgrade. Dan chose this. A one-time resync would need a stored version marker, and the no-persistence audit in verify-metrics.sh forbids that. Posts that are already indexed get cleaned the next time they sync. The readme FAQ and CHANGELOG give wp jetpack sync start --modules=posts for cleaning everything at once.
  • Playground demo: no change. Jetpack Search can't run in Playground, and the demo post shows nothing different.
  • I checked the argument shapes against class-posts.php in Jetpack's jetpack-sync package: 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:js passes (no JS changed)
  • npm run lint:css passes (no CSS changed)
  • npm run lint:i18n passes when source strings or translation docs change (no strings changed)
  • npm run test passes (CI)
  • npm run build succeeds (CI)
  • Tested in the block editor (not applicable: only the sync payload changes)
  • composer test:php: all 879 tests pass, including the new JetpackSearchTest. It checks that:
    • every deprecation fixture is cleaned;
    • scripts outside bibliographies are kept;
    • flags and metadata are untouched;
    • the original post object is not mutated.
  • composer lint:php and verify-metrics.sh pass (metrics updated)

Checklist

🤖 Generated with Claude Code

https://claude.ai/code/session_01WPtgA1o74AsoqnRXEGoYa1

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
@dknauss dknauss self-assigned this Nov 29, 2026
@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Plugin readme preview

Open preview · Commit 874db8a

37 passed · 0 warnings · 0 notes

Passed checks (37)
  • 145 / 150 characters in the short description.
  • Plugin name header recognized.
  • License header recognized: GPLv2 or later.
  • 5 tags accepted within the five-tag limit.
  • Description is within the parser’s word limit.
  • Installation is within the parser’s word limit.
  • Faq is within the parser’s word limit.
  • Changelog is within the parser’s word limit.
  • Tested up to 7.1, the latest WordPress major release.
  • Stable tag is declared: 1.23.0.
  • The PHP Version header is declared: 1.23.0.
  • Stable tag matches the PHP Version header: 1.23.0.
  • The readme “Requires at least” value is valid: 6.4.
  • The PHP “Requires at least” header is a numeric version: 6.4.
  • “Requires at least” matches between the readme and PHP header: 6.4.
  • The readme “Requires PHP” value is valid: 8.1.
  • The PHP “Requires PHP” header is a numeric version: 8.1.
  • “Requires PHP” matches between the readme and PHP header: 8.1.
  • “Tested up to” 7.1 meets the minimum WordPress version 6.4.
  • Installation content is present.
  • FAQ content is present.
  • Changelog content is present.
  • Screenshot captions are present.
  • The first changelog release matches Stable tag: 1.23.0.
  • The first changelog release matches PHP Version: 1.23.0.
  • Banner image loaded.
  • Plugin icon loaded.
  • Screenshot 1 has a matching image and caption.
  • Screenshot 2 has a matching image and caption.
  • Screenshot 3 has a matching image and caption.
  • Screenshot 4 has a matching image and caption.
  • Screenshot 5 has a matching image and caption.
  • Screenshot 6 has a matching image and caption.
  • Screenshot 7 has a matching image and caption.
  • Screenshot 8 has a matching image and caption.
  • Screenshot 9 has a matching image and caption.
  • Plugin PHP header loaded.

Readme and PHP-header checks only; this does not test plugin runtime compatibility.

@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.34%. Comparing base (90abd89) to head (874db8a).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dknauss
dknauss marked this pull request as ready for review November 29, 2026 22:30
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-29T22:30:15.555228Z
We couldn’t complete this review. Comment @codex review to try again.
f986fdb Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

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
dknauss merged commit 97a7538 into main Nov 30, 2026
24 checks passed
@dknauss
dknauss deleted the claude/project-thread-q82hkw branch November 30, 2026 05:23

@dknauss dknauss left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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:

  1. bibliography_builder_strip_site_only_markup() turns a regex failure into an empty string (low, mostly pre-existing). (string) preg_replace( … ) casts null to ''. Reproduced: a block whose JSON-LD <script> is over ~1 MB returns int(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, and bibliography_builder_strip_bibliography_site_only_markup() correctly falls back to the original content. But bibliography_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.
  2. 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.
  3. Worth confirming on a real Jetpack site: that immediate full sync (Full_Sync_Immediately, the default in current Jetpack) still sends posts through jetpack_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.
  4. Verify, maybe nothing: raw post_content also 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

@dknauss dknauss mentioned this pull request Nov 30, 2026
5 of 9 tasks
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.

Keep bibliography JSON-LD, CSL-JSON and Cite / Export labels out of Jetpack Search

2 participants