From 0b9d32a6143fecc616d398427a945b428319f010 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Tue, 22 Dec 2015 10:49:20 +0000 Subject: [PATCH] Embeds: Don't show embed discovery link on a static front page. There's currently no iframe content being generated for a static front page. Giving out a link to that isn't an ideal user experience. Props peterwilsoncc. Fixes #35194 for trunk. git-svn-id: https://develop.svn.wordpress.org/trunk@36059 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/embed.php | 2 +- tests/phpunit/tests/oembed/discovery.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/embed.php b/src/wp-includes/embed.php index 2736204f66..17b9ac4137 100644 --- a/src/wp-includes/embed.php +++ b/src/wp-includes/embed.php @@ -345,7 +345,7 @@ function wp_oembed_register_route() { function wp_oembed_add_discovery_links() { $output = ''; - if ( is_singular() ) { + if ( is_singular() && ! is_front_page() ) { $output .= '' . "\n"; if ( class_exists( 'SimpleXMLElement' ) ) { diff --git a/tests/phpunit/tests/oembed/discovery.php b/tests/phpunit/tests/oembed/discovery.php index 63eb5bbf3a..6331602360 100644 --- a/tests/phpunit/tests/oembed/discovery.php +++ b/tests/phpunit/tests/oembed/discovery.php @@ -8,6 +8,22 @@ class Tests_oEmbed_Discovery extends WP_UnitTestCase { $this->assertSame( '', get_echo( 'wp_oembed_add_discovery_links' ) ); } + function test_add_oembed_discovery_links_front_page() { + $this->go_to( home_url('/') ); + $this->assertSame( '', get_echo( 'wp_oembed_add_discovery_links' ) ); + } + + function test_add_oembed_discovery_links_static_front_page() { + update_option( 'show_on_front', 'page' ); + update_option( 'page_for_posts', self::factory()->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) ) ); + update_option( 'page_on_front', self::factory()->post->create( array( 'post_title' => 'front-page', 'post_type' => 'page' ) ) ); + + $this->go_to( home_url('/') ); + $this->assertSame( '', get_echo( 'wp_oembed_add_discovery_links' ) ); + + update_option( 'show_on_front', 'posts' ); + } + function test_add_oembed_discovery_links_to_post() { $post_id = self::factory()->post->create(); $this->go_to( get_permalink( $post_id ) );