WP_oEmbed_Controller::get_proxy_item( WP_REST_Request $request ): object|WP_Error
- Since
- 4.8.0
- Source
wp-includes/class-wp-oembed-controller.php:169
Description
Returns the JSON object for the proxied item.
Compatibility
- WordPress
- since 4.8.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$requestWP_REST_Request- Full data about the request.
Return value
object|WP_Error- oEmbed response data or WP_Error on failure.
Performance profile
How much work a call to WP_oEmbed_Controller::get_proxy_item() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Scales with input
- Instructions
- 21–76
- Plugin surface
- 2 hooks
- Called by
- 0
Reads stored settings via get_option(), cached per request but not free on a cold cache.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 112.
Third-party callbacks on 'oembed_result', 'rest_oembed_ttl' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- transienttransient
get_transient()called directly - hookthird-party callbacks
apply_filters()called directly - serializeserialisation
serialize()called directly - cacheobject cache
wp_cache_get()one call below WP_oEmbed_Controller::get_proxy_item() - optionoption read or write
get_option()one call below WP_oEmbed_Controller::get_proxy_item()
Further down the call graph this can also reach query. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_oEmbed_Controller::get_proxy_item() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!empty($data) | 21 | ->get_params(), serialize(), md5(), get_transient() |
empty($data) | 33–39 | ->get_params(), serialize(), md5(), get_transient(), get_oembed_response_data_for_url() |
empty($data) && $data === false | 56–62 | ->get_params(), serialize(), md5(), get_transient(), get_oembed_response_data_for_url(), _wp_oembed_get_object(), ->get_data(), ->get_embed_handler_html(), get_status_header_desc(), provider_name() |
empty($data) && $data === false | 59–66 | ->get_params(), serialize(), md5(), get_transient(), get_oembed_response_data_for_url(), _wp_oembed_get_object(), ->get_data(), ->get_embed_handler_html(), __() |
empty($data) && $data !== false | 70–76 | ->get_params(), serialize(), md5(), get_transient(), get_oembed_response_data_for_url(), _wp_oembed_get_object(), ->get_data(), _wp_oembed_get_object(), ->data2html(), apply_filters(), apply_filters(), set_transient() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 112 instructions, 21–76 executed per call, 8 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 2
2 hooks fire while WP_oEmbed_Controller::get_proxy_item() runs, in this order:
- apply_filters( oembed_result )filterline 226 (+57 into the body)
Filters the HTML returned by the oEmbed provider.
- apply_filters( rest_oembed_ttl )filterline 240 (+71 into the body)
Filters the oEmbed TTL value (time to live).
Uses · 10
- get_transient()Retrieves the value of a transient.
- get_oembed_response_data_for_url()Retrieves the oEmbed response data for a given URL.
- _wp_oembed_get_object()Returns the initialized WP_oEmbed object.
- __()Retrieves the translation of $text.
- get_status_header_desc()Retrieves the description for the HTTP status.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- set_transient()Sets/updates the value of a transient.
- _wp_oembed_get_object()::get_data()
- WP_Error::__construct()Initializes the error.
- _wp_oembed_get_object()::data2html()
Source code
public function get_proxy_item( $request ) { global $wp_embed, $wp_scripts; $args = $request->get_params(); // Serve oEmbed data from cache if set. unset( $args['_wpnonce'] ); $cache_key = 'oembed_' . md5( serialize( $args ) ); $data = get_transient( $cache_key ); if ( ! empty( $data ) ) { return $data; } $url = $request['url']; unset( $args['url'] ); // Copy maxwidth/maxheight to width/height since WP_oEmbed::fetch() uses these arg names. if ( isset( $args['maxwidth'] ) ) { $args['width'] = $args['maxwidth']; } if ( isset( $args['maxheight'] ) ) { $args['height'] = $args['maxheight']; } // Short-circuit process for URLs belonging to the current site. $data = get_oembed_response_data_for_url( $url, $args ); if ( $data ) { return $data; } $data = _wp_oembed_get_object()->get_data( $url, $args ); if ( false === $data ) { // Try using a classic embed, instead. /* @var WP_Embed $wp_embed */ $html = $wp_embed->get_embed_handler_html( $args, $url ); if ( $html ) { // Check if any scripts were enqueued by the shortcode, and include them in the response. $enqueued_scripts = array(); foreach ( $wp_scripts->queue as $script ) { $enqueued_scripts[] = $wp_scripts->registered[ $script ]->src; } return (object) array( 'provider_name' => __( 'Embed Handler' ), 'html' => $html, 'scripts' => $enqueued_scripts, ); } return new WP_Error( 'oembed_invalid_url', get_status_header_desc( 404 ), array( 'status' => 404 ) ); } /** This filter is documented in wp-includes/class-wp-oembed.php */ $data->html = apply_filters( 'oembed_result', _wp_oembed_get_object()->data2html( (object) $data, $url ), $url, $args ); /** * Filters the oEmbed TTL value (time to live). * * Similar to the {@see 'oembed_ttl'} filter, but for the REST API * oEmbed proxy endpoint. * * @since 4.8.0 * * @param int $time Time to live (in seconds). * @param string $url The attempted embed URL. * @param array $args An array of embed request arguments. */ $ttl = apply_filters( 'rest_oembed_ttl', DAY_IN_SECONDS, $url, $args ); set_transient( $cache_key, $data, $ttl ); return $data; }Changelog
Introduced in 4.8.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-includes/class-wp-oembed-controller.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.