Skip to content

fix: missing remote attachments issue#243

Open
Kallyan01 wants to merge 24 commits into
mainfrom
fix/remote-attachment
Open

fix: missing remote attachments issue#243
Kallyan01 wants to merge 24 commits into
mainfrom
fix/remote-attachment

Conversation

@Kallyan01

@Kallyan01 Kallyan01 commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

What

Remote site post thumbnail issue on the search area.

Why

It's impacting search result functionality.

Related Issue(s):

Closes https://github.com/rtCamp/OnePress/issues/73

How

The thumbnails were not loading in the search results because remote posts were assigned negative post IDs. To address this, we intercepted those posts and generated the thumbnail data through filters, ensuring that thumbnails are displayed correctly in the search results.

AI Disclosure

Claude Opus 4.6 ( Research )

Testing Instructions

  • Set up both the Governing and Brand sites in a local environment using wp-env.
  • Upload a few media files to the Brand site and run the re-index process.
  • On the Governing site, search for the uploaded media file names.
  • Verify that the media results now display visible thumbnails, whereas previously the thumbnails were not appearing.

Screenshots

Before:
image

After:
image

Additional Info

Checklist

  • I have read the Contribution Guidelines.
  • I have read the Development Guidelines.
  • I have added necessary tests to cover my changes.
  • I have updated the project documentation as needed.
  • My code has detailed inline documentation.
  • My code is tested to the best of my abilities.
  • My code passes all lints, tests, and checks.
Open WordPress Playground Preview

@Kallyan01 Kallyan01 self-assigned this Jun 12, 2026
@Kallyan01 Kallyan01 added the Bug label Jun 12, 2026
@Kallyan01 Kallyan01 changed the title Fixed missing remote attachments issue fix:missing remote attachments issue Jun 12, 2026
@Kallyan01 Kallyan01 changed the title fix:missing remote attachments issue fix: missing remote attachments issue Jun 12, 2026
@Kallyan01 Kallyan01 requested a review from justlevine June 12, 2026 10:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes missing thumbnails for remote (Algolia-hydrated) attachment results in the search UI by carrying thumbnail metadata on mocked remote WP_Post objects and intercepting WordPress image/thumbnail rendering paths to use that metadata.

Changes:

  • Adds remote thumbnail plumbing by storing Algolia thumbnail record data on remote WP_Post objects.
  • Hooks into WordPress image/thumbnail/content rendering filters to output remote thumbnail URLs/HTML for negative-ID (remote) posts and attachments.
  • Updates PHPStan stubs to model the new dynamic onesearch_thumbnail property.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
phpstan/stubs/wordpress-extended.php Adds PHPStan typing for the new WP_Post::$onesearch_thumbnail dynamic property.
inc/Modules/Search/Search.php Adds filters + helper logic to render remote thumbnails correctly for search results containing remote/negative-ID posts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread inc/Modules/Search/Search.php Outdated
Comment thread inc/Modules/Search/Search.php Outdated
Comment thread inc/Modules/Search/Search.php
Comment thread inc/Modules/Search/Search.php Outdated
Comment thread inc/Modules/Search/Search.php Outdated

@justlevine justlevine left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ignore the copilot noise for now: this is what I was concerned about:

Image

(Left is the local post, right is the remote)

It's possible that the preg_replace can be fixed to better support other block image attachments, and even switching to the more ideal HTML API could catch even more. But ultimately the use of replacing the image output is always going to be flawed, fragile, and susceptible to edge cases.

As mentioned both in the GH issue and on slack, unless you have a reason otherwise, I think the best way to address the bug will be to:

  1. Programmatically create a single fictitious attachment at plugin activation (and checking/recreating it when using) and assign that number as the post attachment id instead of a non-existent negative post id. It should be hidden from the UX.
  2. Use the attachment hooks to swap out the metadata on the attachment to the specific remote file, instead of trying to finagle the post directly.

This way any attachment-related functionality work natively the image routing is an isolated implementation detail.

@codecov-commenter

codecov-commenter commented Jun 16, 2026

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@Kallyan01

Copy link
Copy Markdown
Collaborator Author

@justlevine, the issue with the current fix isn't clear to me. Could you please help me if I'm missing any details or edge cases? All I can see is a missing publish date and a bit smaller thumbnail size.

Source Site Result
image

Remote Site Result
image

@justlevine

justlevine commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

@justlevine, the issue with the current fix isn't clear to me. Could you please help me if I'm missing any details or edge cases? All I can see is a missing publish date and a bit smaller thumbnail size.

Inspect the actual html for both. Different blocks (and settings) render images differently with different html attributes and patterns. Your search-replace ditches all of that for a specific <img > , and trying to manually enumerate the specific blocks as conditionals means that we need to manually add support for every new block and anything the end-user has custom is SOL.

@justlevine

justlevine commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Here's the dummy post from above that you can use for testing. Don't forget to update the images after you paste it in.

<!-- wp:paragraph -->
<p>image</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":7,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="http://localhost:8888/wp-content/uploads/2026/06/900-536x354-1.jpg" alt="Some picsum for my testsum" class="wp-image-7"/><figcaption class="wp-element-caption">Picsum ID: 900</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Gallery</p>
<!-- /wp:paragraph -->

<!-- wp:gallery {"linkTo":"none"} -->
<figure class="wp-block-gallery has-nested-images columns-default is-cropped"><!-- wp:image {"id":7,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="http://localhost:8888/wp-content/uploads/2026/06/900-536x354-1.jpg" alt="Some picsum for my testsum" class="wp-image-7"/><figcaption class="wp-element-caption">Picsum ID: 900</figcaption></figure>
<!-- /wp:image --></figure>
<!-- /wp:gallery -->

<!-- wp:paragraph -->
<p>Media/Text</p>
<!-- /wp:paragraph -->

<!-- wp:media-text {"mediaId":7,"mediaLink":"http://localhost:8888/picsum-id-900/","linkDestination":"none","mediaType":"image"} -->
<div class="wp-block-media-text is-stacked-on-mobile"><figure class="wp-block-media-text__media"><img src="http://localhost:8888/wp-content/uploads/2026/06/900-536x354-1.jpg" alt="Some picsum for my testsum" class="wp-image-7 size-full"/></figure><div class="wp-block-media-text__content"><!-- wp:paragraph {"placeholder":"Content…"} -->
<p>Media text</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:media-text -->

<!-- wp:cover {"url":"http://localhost:8888/wp-content/uploads/2026/06/900-536x354-1.jpg","id":7,"alt":"Some picsum for my testsum","dimRatio":50,"customOverlayColor":"#9b7861","isUserOverlayColor":false,"isDark":false,"sizeSlug":"full","layout":{"type":"constrained"}} -->
<div class="wp-block-cover is-light"><img class="wp-block-cover__image-background wp-image-7 size-full" alt="Some picsum for my testsum" src="http://localhost:8888/wp-content/uploads/2026/06/900-536x354-1.jpg" data-object-fit="cover"/><span aria-hidden="true" class="wp-block-cover__background has-background-dim" style="background-color:#9b7861"></span><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"placeholder":"Write title…","style":{"typography":{"textAlign":"center"}},"fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Cover Image</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

<!-- wp:post-featured-image /-->

Kallyan01 and others added 10 commits June 23, 2026 16:27
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
* tests: added tests for Search/Index module

* tests: added tests for Search/Search module

* tests: improved tests for Search/Search module

* fix: resolved phpcs errors

* tests: improved tests for Search/Watcher module

* tests: improved tests for Search/Settings module

* fix: resolved PHPCS errors

* tests: enhance error handling tests for Index and Search modules

* tests: enhance WatcherTest to intercept Algolia SDK requests and validate reindexing behavior

* fix: resolved PHPCS errors

* tests: enhance Algolia SDK request interception and add new tests for Index and Search modules

* tests: enhance IndexTest to validate error handling for SDK exceptions during delete, save, and search operations

* chore: added minor testcase fixes

* tests: remove unwanted comments in IndexTest, SearchTest, SettingsTest, and WatcherTest

* tests: refactor IndexTest and SearchTest for improved credential handling and remove unused code

* tests: add integration tests for Algolia reindexing on site type changes in SettingsTest and WatcherTest

* fix: phpcs errors resolved

* refactor: clean up test teardown methods by removing redundant option resets and updating settings test logic

* test: add pagination test for indexing more than batch size posts

* test: enhance Algolia and Post_Record tests with additional cases

* Revert "test: enhance Algolia and Post_Record tests with additional cases"

This reverts commit 3878c3e.

* fix: removed unwanted tests related to hooks registration

* test: added suggested edits

* fix: resolved wrong testcase edit

---------

Co-authored-by: Dovid Levine <david@axepress.dev>
Bumps [form-data](https://github.com/form-data/form-data) from 4.0.5 to 4.0.6.
- [Changelog](https://github.com/form-data/form-data/blob/master/CHANGELOG.md)
- [Commits](form-data/form-data@v4.0.5...v4.0.6)

---
updated-dependencies:
- dependency-name: form-data
  dependency-version: 4.0.6
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* tests: rename PHP `Unit` to `Integration`

* chore: formatting

* test: fix PHPUnit suite name

* chore: dir rename
#252)

Bumps the github-actions-updates group with 1 update: [actions/checkout](https://github.com/actions/checkout).


Updates `actions/checkout` from 6.0.3 to 7.0.0
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@df4cb1c...9c091bb)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: 7.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions-updates
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [wp-phpunit/wp-phpunit](https://github.com/wp-phpunit/wp-phpunit) from 6.9.4 to 7.0.0.
- [Commits](wp-phpunit/wp-phpunit@6.9.4...7.0.0)

---
updated-dependencies:
- dependency-name: wp-phpunit/wp-phpunit
  dependency-version: 7.0.0
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…y with 3 updates (#255)

Bumps the npm-dev-minor-patch group with 3 updates in the / directory: [@playwright/test](https://github.com/microsoft/playwright), [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) and [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser).


Updates `@playwright/test` from 1.60.0 to 1.61.0
- [Release notes](https://github.com/microsoft/playwright/releases)
- [Commits](microsoft/playwright@v1.60.0...v1.61.0)

Updates `@typescript-eslint/eslint-plugin` from 8.61.0 to 8.61.1
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.61.1/packages/eslint-plugin)

Updates `@typescript-eslint/parser` from 8.61.0 to 8.61.1
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.61.1/packages/parser)

---
updated-dependencies:
- dependency-name: "@playwright/test"
  dependency-version: 1.61.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: npm-dev-minor-patch
- dependency-name: "@typescript-eslint/eslint-plugin"
  dependency-version: 8.61.1
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm-dev-minor-patch
- dependency-name: "@typescript-eslint/parser"
  dependency-version: 8.61.1
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm-dev-minor-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 25, 2026 20:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Comment thread tests/phpstan/stubs/wordpress-extended.php
Comment thread inc/Modules/Search/Search.php
Comment thread inc/Modules/Search/Search.php
Comment thread inc/Modules/Search/Search.php Outdated
Comment thread uninstall.php Outdated
Comment thread inc/Modules/Search/Search.php
Comment thread uninstall.php
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 26, 2026 06:43
Kallyan01 and others added 3 commits June 26, 2026 12:15
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (1)

uninstall.php:35

  • Indentation on this inline phpcs ignore comment uses spaces instead of the surrounding tab indentation, which can trip formatting/lint checks and makes the block inconsistent.
		// phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.switch_to_blog_switch_to_blog -- The state doesn't matter during uninstall.

Comment thread inc/Modules/Search/Search.php
Comment thread inc/Modules/Search/Search.php
Comment thread inc/Modules/Search/Search.php
Comment thread inc/Modules/Search/Search.php Outdated
Copilot AI review requested due to automatic review settings June 26, 2026 06:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI review requested due to automatic review settings June 26, 2026 08:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread inc/Modules/Search/Search.php
Comment thread inc/Modules/Search/Search.php
Kallyan01 and others added 2 commits June 26, 2026 14:16
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 26, 2026 08:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Comment thread inc/Modules/Search/Search.php
Comment thread inc/Modules/Search/Search.php
Comment thread uninstall.php
@Kallyan01 Kallyan01 requested a review from justlevine June 26, 2026 12:18
@Kallyan01

Copy link
Copy Markdown
Collaborator Author

@justlevine, I've replaced our previous approach with the proxy attachment method you suggested.

I also tested the sample block of code you shared, but I wasn't able to reproduce the issue. Our current problem appears to be specific to media files. When I added the shared code to a post and searched for it, it appeared as expected on both the source and remote sites.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants