/** * Hook into the query parsing to detect oEmbed requests. * * If an oEmbed request is made, trigger the output. * * @since 4.4.0 * * @param WP_Query $wp_query The WP_Query instance (passed by reference). */ public function parse_query($wp_query) { if (false === $wp_query->get('oembed', false)) { return; } if (false === $wp_query->get('url', false)) { status_header(400); echo 'URL parameter missing'; exit; } $url = esc_url_raw(get_query_var('url')); $format = wp_oembed_ensure_format(get_query_var('format')); /** * Filter the maxwidth oEmbed parameter. * * @since 4.4.0 * * @param int $maxwidth Maximum allowed width. Default 600. */ $maxwidth = apply_filters('oembed_default_width', 600); $maxwidth = absint(get_query_var('maxwidth', $maxwidth)); $callback = get_query_var('_jsonp', false); $request = array('url' => $url, 'format' => $format, 'maxwidth' => $maxwidth, 'callback' => $callback); echo $this->dispatch($request); exit; }
/** * Hook into the query parsing to detect oEmbed requests. * * If an oEmbed request is made, trigger the output. * * @codeCoverageIgnore * * @param WP_Query $wp_query The WP_Query instance (passed by reference). */ public function parse_query($wp_query) { // Check for required params. if (false === $wp_query->get('oembed', false)) { return; } if (false === $wp_query->get('url', false)) { status_header(400); echo 'URL parameter missing'; exit; } /** * Check for the allowed query vars and set defaults. * * @see WP_REST_oEmbed_Controller::register_routes() */ $url = esc_url_raw(get_query_var('url')); $format = wp_oembed_ensure_format(get_query_var('format')); /** * Filter the maxwidth oEmbed parameter. * * @param int $maxwidth Maximum allowed width. Defaults to 600. */ $maxwidth = apply_filters('oembed_default_width', 600); $maxwidth = get_query_var('maxwidth', $maxwidth); $callback = get_query_var('_jsonp', false); $request = array('url' => $url, 'format' => $format, 'maxwidth' => $maxwidth, 'callback' => $callback); echo $this->dispatch($request); exit; }
function test_wp_oembed_ensure_format() { $this->assertEquals('json', wp_oembed_ensure_format('json')); $this->assertEquals('xml', wp_oembed_ensure_format('xml')); $this->assertEquals('json', wp_oembed_ensure_format(123)); $this->assertEquals('json', wp_oembed_ensure_format('random')); $this->assertEquals('json', wp_oembed_ensure_format(array())); }