function test_add_oembed_discovery_links_to_attachment() { $post_id = self::factory()->post->create(); $file = DIR_TESTDATA . '/images/canola.jpg'; $attachment_id = self::factory()->attachment->create_object($file, $post_id, array('post_mime_type' => 'image/jpeg')); $this->go_to(get_permalink($attachment_id)); $this->assertQueryTrue('is_attachment', 'is_singular', 'is_single'); $expected = '<link rel="alternate" type="application/json+oembed" href="' . esc_url(get_oembed_endpoint_url(get_permalink())) . '" />' . "\n"; $expected .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url(get_oembed_endpoint_url(get_permalink(), 'xml')) . '" />' . "\n"; $this->assertEquals($expected, get_echo('wp_oembed_add_discovery_links')); }
/** * Test output of add_oembed_discovery_links. */ function test_add_oembed_discovery_links() { $post_id = $this->factory->post->create(); $this->go_to(get_permalink($post_id)); $this->assertQueryTrue('is_single', 'is_singular'); ob_start(); wp_oembed_add_discovery_links(); $actual = ob_get_clean(); $expected = '<link rel="alternate" type="application/json+oembed" href="' . esc_url(get_oembed_endpoint_url(get_permalink())) . '" />' . "\n"; $expected .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url(get_oembed_endpoint_url(get_permalink(), 'xml')) . '" />' . "\n"; $this->assertEquals($expected, $actual); }
/** * Add oEmbed discovery links in the website <head>. */ function wp_oembed_add_discovery_links() { $output = ''; if (is_singular()) { $output .= '<link rel="alternate" type="application/json+oembed" href="' . esc_url(get_oembed_endpoint_url(get_permalink())) . '" />' . "\n"; $output .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url(get_oembed_endpoint_url(get_permalink(), 'xml')) . '" />' . "\n"; } /** * Filter the oEmbed discovery links. * * @param string $output HTML of the discovery links. */ echo apply_filters('oembed_discovery_links', $output); }
function test_get_oembed_endpoint_url() { $this->assertEquals(home_url() . '/?oembed=true', get_oembed_endpoint_url()); $this->assertEquals(home_url() . '/?oembed=true', get_oembed_endpoint_url('', 'json')); $this->assertEquals(home_url() . '/?oembed=true', get_oembed_endpoint_url('', 'xml')); $post_id = self::factory()->post->create(); $url = get_permalink($post_id); $url_encoded = urlencode($url); $this->assertEquals(home_url() . '/?oembed=true&url=' . $url_encoded, get_oembed_endpoint_url($url)); $this->assertEquals(home_url() . '/?oembed=true&url=' . $url_encoded . '&format=xml', get_oembed_endpoint_url($url, 'xml')); }
/** * Adds oEmbed discovery links in the website <head>. * * @since 4.4.0 */ function wp_oembed_add_discovery_links() { $output = ''; if (is_singular() && !is_front_page()) { $output .= '<link rel="alternate" type="application/json+oembed" href="' . esc_url(get_oembed_endpoint_url(get_permalink())) . '" />' . "\n"; if (class_exists('SimpleXMLElement')) { $output .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url(get_oembed_endpoint_url(get_permalink(), 'xml')) . '" />' . "\n"; } } /** * Filter the oEmbed discovery links HTML. * * @since 4.4.0 * * @param string $output HTML of the discovery links. */ echo apply_filters('oembed_discovery_links', $output); }
/** * Adds oEmbed discovery links in the website <head> for the IdeaStream user's profile root page. * * @since 2.3.0 */ function wp_idea_stream_oembed_add_discovery_links() { if (!wp_idea_stream_is_user_profile_ideas() || !wp_idea_stream_is_embed_profile()) { return; } $user_link = wp_idea_stream_users_get_user_profile_url(wp_idea_stream_users_displayed_user_id(), '', true); $output = '<link rel="alternate" type="application/json+oembed" href="' . esc_url(get_oembed_endpoint_url($user_link)) . '" />' . "\n"; if (class_exists('SimpleXMLElement')) { $output .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url(get_oembed_endpoint_url($user_link, 'xml')) . '" />' . "\n"; } /** * Filter the oEmbed discovery links HTML. * * @since 2.3.0 * * @param string $output HTML of the discovery links. */ echo apply_filters('wp_idea_stream_users_oembed_add_discovery_links', $output); }
/** * Add this site to the whitelist of oEmbed providers. */ function wp_oembed_add_site_as_provider() { wp_oembed_add_provider(home_url('/*'), get_oembed_endpoint_url()); }
/** * Test get_oembed_endpoint_url */ function test_get_oembed_endpoint_url_pretty_permalinks() { update_option('permalink_structure', '/%postname%'); $this->assertEquals(home_url() . '/wp-json/wp/v2/oembed', get_oembed_endpoint_url()); $this->assertEquals(home_url() . '/wp-json/wp/v2/oembed', get_oembed_endpoint_url('', 'xml')); $post_id = $this->factory->post->create(); $url = get_permalink($post_id); $this->assertEquals(home_url() . '/wp-json/wp/v2/oembed?url=' . $url, get_oembed_endpoint_url($url)); $this->assertEquals(home_url() . '/wp-json/wp/v2/oembed?url=' . $url . '&format=xml', get_oembed_endpoint_url($url, 'xml')); update_option('permalink_structure', ''); }
/** * Adds oEmbed discovery links on single activity pages. * * @since 2.6.0 * * @param string $retval Current discovery links. * @return string */ public function add_oembed_discovery_links($retval) { if (!$this->is_page()) { return $retval; } $permalink = $this->set_permalink(); if (empty($permalink)) { return $retval; } add_filter('rest_url', array($this, 'filter_rest_url')); $retval = '<link rel="alternate" type="application/json+oembed" href="' . esc_url(get_oembed_endpoint_url($permalink)) . '" />' . "\n"; if (class_exists('SimpleXMLElement')) { $retval .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url(get_oembed_endpoint_url($permalink, 'xml')) . '" />' . "\n"; } remove_filter('rest_url', array($this, 'filter_rest_url')); return $retval; }
/** * Outputs oembed resource links on the /all/ pages for recurring events * * @since 4.2 * * @param string $output Resource links to output * * @return string */ public function oembed_discovery_links_for_recurring_events($output) { global $wp_query; if ($output) { return $output; } if (!tribe_is_showing_all()) { return $output; } if (empty($wp_query->posts[0])) { return $output; } $post = $wp_query->posts[0]; $post_id = $post->ID; $output = '<link rel="alternate" type="application/json+oembed" href="' . esc_url(get_oembed_endpoint_url(add_query_arg('post_id', $post_id, get_permalink($post_id)))) . '" />' . "\n"; if (class_exists('SimpleXMLElement')) { $output .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url(get_oembed_endpoint_url(add_query_arg('post_id', $post_id, get_permalink($post_id)), 'xml')) . '" />' . "\n"; } return $output; }