Make WordPress Core

Opened 9 years ago

Last modified 6 months ago

#41554 new enhancement

REST API: Use `wp.apiRequest` helper to build URLs for media embed requests

Reported by: jnylen0 Owned by:
Priority: normal Milestone: Awaiting Review
Component: REST API Version:
Severity: normal Keywords: good-first-bug has-patch has-unit-tests
Cc: Focuses: javascript, administration, rest-api

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)

41554.diff​ (3.3 KB ) - added by nezhar 9 years ago.
41554.2.diff​ (3.3 KB ) - added by nezhar 9 years ago.

Download all attachments as: .zip

Change History (5)

@nezhar
9 years ago

@nezhar
9 years ago

#1 @nezhar
9 years ago

  • Keywords has-patch added; needs-patch removed

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.

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.


6 months 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 into wp.media / related scripts).

## Testing

Manual:

  1. Open the media modal and use Insert from URL (not only the block editor Embed block).
  2. Paste a supported URL (e.g. a YouTube watch URL) and confirm the embed preview loads.
  3. In the browser Network tab, confirm the request targets the /oembed/1.0/proxy REST 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.

Note: See TracTickets for help on using tickets.