Automattic / Automattic/jetpack

Photon: filter attachment_url_to_postid() to support Photon CDN URLs

Open
#23,405 3 comments 0 reactions 0 assignees View on GitHub
[Feature] Photon [Plugin] Jetpack [Pri] Low Enhancement Good For Community
Dominant language
PHP
Stars
1.8k
Forks
898
Avg merge
1d 18h
Merged PRs (30d)
774

Description

### Impacted plugin

Jetpack

### Steps to Reproduce

1. Install Jetpack.
2. Turn on the Photon image CDN, (Jetpack > Settings > Performance > Performance & Speed and turn on the "Enable site accelerator" and "Speed up image load times" toggles).
3. Pass the CDN URL of any image in the media gallery to WordPress's [`attachment_url_to_postid()`](https://developer.wordpress.org/reference/functions/attachment_url_to_postid/) function.
4. Inspect the return value from the function. It should be an integer post ID, but it'll be zero.

### A clear and concise description of what you expected to happen.

I expect the post ID of the attachment to be returned by `attachment_url_to_postid()` even with Photon active.

### What actually happened

`attachment_url_to_postid()` returns a zero, which means it failed to look up the post ID of the image.

### Other information

This bug makes sense, because `attachment_url_to_postid()` queries the database for the URL that was passed in, and the CDN URL is not in the database.

However, there is a `attachment_url_to_postid` filter, and I expect that Jetpack would be a good WordPress citizen and, when Photon is on, use that filter to extract the original from the CDN URL and look up the post ID based on the original URL.

### Operating System

macOS, Linux

### OS Version

Confirmed on both Linux webserver and macOS localhost.

### Browser

Other / Not applicable

### Browser Version(s)

Not a browser problem.

Contributor guide

Open the contributing guide

Research direction

Start by searching Jetpack's Photon CDN URL handling and WordPress's attachment_url_to_postid filter. Reproduce the failure with a CDN image URL, then verify that the filter allows the attachment post ID to be found from the original image URL.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, wordpress
Domain
backend, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.