Opened 9 years ago
Last modified 2 weeks ago
#41554 new enhancement
REST API: Use `wp.apiRequest` helper to build URLs for media embed requests
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | REST API | Keywords: | good-first-bug has-patch has-unit-tests |
| Focuses: | javascript, administration, rest-api | Cc: |
Description
Follow-up to #40919.
Let's explore getting rid of the oEmbedProxyUrl property used to pass a REST API URL down to wp-admin code that calls out to this endpoint (example). We can use the helper library introduced in #40919 instead:
wp.apiRequest( { namespace: 'oembed/1.0', path: '/proxy', // ... } );
This helper will allow us to eliminate all rest_url calls passed to client code through script localization. This will eventually lead to a lot of duplication, but it seems like it should be very clear from the requesting code which API endpoint is being called.
Attachments (2)
Change History (5)
This ticket was mentioned in Slack in #core by m.usama.masood. View the logs.
7 years ago
This ticket was mentioned in PR #11479 on WordPress/wordpress-develop by @iampi20.
2 weeks ago
#3
- Keywords has-unit-tests added
## Summary
Replaces localized oEmbedProxyUrl (full REST URL from PHP) with wp.apiRequest() using namespace: 'oembed/1.0' and endpoint: 'proxy', so admin embed code builds the oEmbed proxy URL consistently with other REST clients and avoids passing rest_url() output through script localization.
Follow-up to #40919; implements #41554.
## Changes
- Update media embed JS to call
wp.apiRequest()for oEmbed proxy previews. - Remove the corresponding
wp_localize_script/ settings property from PHP (where previously passed intowp.media/ related scripts).
## Testing
Manual:
- Open the media modal and use Insert from URL (not only the block editor Embed block).
- Paste a supported URL (e.g. a YouTube watch URL) and confirm the embed preview loads.
- In the browser Network tab, confirm the request targets the
/oembed/1.0/proxyREST route (or equivalent with plain permalinks /rest_route).
Automated:
- Run relevant PHPUnit tests for the oEmbed REST proxy (e.g.
tests/phpunit/tests/oembed/controller.php) in your environment.
Trac ticket: https://core.trac.wordpress.org/ticket/41554
## Use of AI Tools
AI assistance: Yes
Tool(s): Cursor
Used for: Exploring the codebase, drafting and iterating on the patch, and PR description text; implementation was reviewed and adjusted manually before submission.
---
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.
I have done the path a described above. How can I test this actually? I tried by embedding a Youtube video, but I don't think it uses the action that got modified.