Ticket #34971: 34971.diff
File 34971.diff, 10.5 KB (added by , 9 years ago) |
---|
-
src/wp-includes/class-wp-rewrite.php
diff --git src/wp-includes/class-wp-rewrite.php src/wp-includes/class-wp-rewrite.php index 1773929..490507b 100644
class WP_Rewrite { 1000 1000 $feedmatch2 = $match . $feedregex2; 1001 1001 $feedquery2 = $feedindex . '?' . $query . '&feed=' . $this->preg_index($num_toks + 1); 1002 1002 1003 // Create query and regex for embeds. 1004 $embedmatch = $match . $embedregex; 1005 $embedquery = $embedindex . '?' . $query . '&embed=true'; 1006 1003 1007 // If asked to, turn the feed queries into comment feed ones. 1004 1008 if ( $forcomments ) { 1005 1009 $feedquery .= '&withcomments=1'; … … class WP_Rewrite { 1011 1015 1012 1016 // ...adding on /feed/ regexes => queries 1013 1017 if ( $feed ) { 1014 $rewrite = array( $feedmatch => $feedquery, $feedmatch2 => $feedquery2 );1018 $rewrite = array( $feedmatch => $feedquery, $feedmatch2 => $feedquery2, $embedmatch => $embedquery ); 1015 1019 } 1016 1020 1017 1021 //...and /page/xx ones -
src/wp-includes/query.php
diff --git src/wp-includes/query.php src/wp-includes/query.php index 55f6172..ef5b00c 100644
class WP_Query { 1456 1456 , 'title' 1457 1457 , 'fields' 1458 1458 , 'menu_order' 1459 , 'embed' 1459 1460 ); 1460 1461 1461 1462 foreach ( $keys as $key ) { … … class WP_Query { 1756 1757 if ( '' != $qv['feed'] ) 1757 1758 $this->is_feed = true; 1758 1759 1760 if ( '' != $qv['embed'] ) { 1761 $this->is_embed = true; 1762 } 1763 1759 1764 if ( '' != $qv['tb'] ) 1760 1765 $this->is_trackback = true; 1761 1766 … … class WP_Query { 1788 1793 // pagename can be set and empty depending on matched rewrite rules. Ignore an empty pagename. 1789 1794 if ( isset($_query['pagename']) && '' == $_query['pagename'] ) 1790 1795 unset($_query['pagename']); 1796 1797 unset( $_query['embed'] ); 1798 1791 1799 if ( empty($_query) || !array_diff( array_keys($_query), array('preview', 'page', 'paged', 'cpage') ) ) { 1792 1800 $this->is_page = true; 1793 1801 $this->is_home = false; … … class WP_Query { 1859 1867 if ( '404' == $qv['error'] ) 1860 1868 $this->set_404(); 1861 1869 1862 $this->is_embed = isset( $qv['embed'] )&& ( $this->is_singular || $this->is_404 );1870 $this->is_embed = $this->is_embed && ( $this->is_singular || $this->is_404 ); 1863 1871 1864 1872 $this->query_vars_hash = md5( serialize( $this->query_vars ) ); 1865 1873 $this->query_vars_changed = false; -
src/wp-includes/rewrite.php
diff --git src/wp-includes/rewrite.php src/wp-includes/rewrite.php index 7f3b2ed..b867cdc 100644
function url_to_postid( $url ) { 445 445 return $id; 446 446 } 447 447 448 // Check to see if we are using rewrite rules449 $rewrite = $wp_rewrite->wp_rewrite_rules();450 451 // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options452 if ( empty($rewrite) )453 return 0;454 455 448 // Get rid of the #anchor 456 449 $url_split = explode('#', $url); 457 450 $url = $url_split[0]; … … function url_to_postid( $url ) { 471 464 if ( false === strpos(home_url(), '://www.') ) 472 465 $url = str_replace('://www.', '://', $url); 473 466 467 if ( trim( $url, '/' ) === home_url() && 'page' == get_option( 'show_on_front' ) ) { 468 $page_on_front = get_option( 'page_on_front' ); 469 470 if ( $page_on_front && get_post( $page_on_front ) instanceof WP_Post ) { 471 return (int) $page_on_front; 472 } 473 } 474 475 // Check to see if we are using rewrite rules 476 $rewrite = $wp_rewrite->wp_rewrite_rules(); 477 478 // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options 479 if ( empty($rewrite) ) 480 return 0; 481 474 482 // Strip 'index.php/' if we're not using path info permalinks 475 483 if ( !$wp_rewrite->using_index_permalinks() ) 476 484 $url = str_replace( $wp_rewrite->index . '/', '', $url ); -
tests/phpunit/tests/oembed/controller.php
diff --git tests/phpunit/tests/oembed/controller.php tests/phpunit/tests/oembed/controller.php index 5cca696..9aa1524 100644
class Test_oEmbed_Controller extends WP_UnitTestCase { 169 169 $this->assertTrue( $data['width'] <= $request['maxwidth'] ); 170 170 } 171 171 172 /** 173 * @ticket 34971 174 */ 175 function test_request_static_front_page() { 176 $show_on_front = get_option( 'show_on_front' ); 177 $page_on_front = get_option( 'page_on_front' ); 178 179 $post = self::factory()->post->create_and_get( array( 180 'post_title' => 'Front page', 181 'post_type' => 'page', 182 ) ); 183 184 update_option( 'show_on_front', 'page' ); 185 update_option( 'page_on_front', $post->ID ); 186 187 $request = new WP_REST_Request( 'GET', '/oembed/1.0/embed' ); 188 $request->set_param( 'url', home_url() ); 189 $request->set_param( 'maxwidth', 400 ); 190 191 $response = $this->server->dispatch( $request ); 192 $data = $response->get_data(); 193 194 $this->assertInternalType( 'array', $data ); 195 $this->assertNotEmpty( $data ); 196 197 $this->assertArrayHasKey( 'version', $data ); 198 $this->assertArrayHasKey( 'provider_name', $data ); 199 $this->assertArrayHasKey( 'provider_url', $data ); 200 $this->assertArrayHasKey( 'author_name', $data ); 201 $this->assertArrayHasKey( 'author_url', $data ); 202 $this->assertArrayHasKey( 'title', $data ); 203 $this->assertArrayHasKey( 'type', $data ); 204 $this->assertArrayHasKey( 'width', $data ); 205 206 $this->assertEquals( '1.0', $data['version'] ); 207 $this->assertEquals( get_bloginfo( 'name' ), $data['provider_name'] ); 208 $this->assertEquals( get_home_url(), $data['provider_url'] ); 209 $this->assertEquals( get_bloginfo( 'name' ), $data['author_name'] ); 210 $this->assertEquals( get_home_url(), $data['author_url'] ); 211 $this->assertEquals( $post->post_title, $data['title'] ); 212 $this->assertEquals( 'rich', $data['type'] ); 213 $this->assertTrue( $data['width'] <= $request['maxwidth'] ); 214 215 update_option( 'show_on_front', $show_on_front ); 216 update_option( 'page_on_front', $page_on_front ); 217 } 218 172 219 function test_request_xml() { 173 220 $user = self::factory()->user->create_and_get( array( 174 221 'display_name' => 'John Doe', -
tests/phpunit/tests/oembed/discovery.php
diff --git tests/phpunit/tests/oembed/discovery.php tests/phpunit/tests/oembed/discovery.php index 63eb5bb..f3d5e2c 100644
class Tests_oEmbed_Discovery extends WP_UnitTestCase { 47 47 48 48 $this->assertEquals( $expected, get_echo( 'wp_oembed_add_discovery_links' ) ); 49 49 } 50 51 /** 52 * @ticket 34971 53 */ 54 function test_add_oembed_discovery_links_static_front_page() { 55 $show_on_front = get_option( 'show_on_front' ); 56 $page_on_front = get_option( 'page_on_front' ); 57 58 $page_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); 59 60 $this->assertSame( 0, url_to_postid( home_url() ) ); 61 62 update_option( 'show_on_front', 'page' ); 63 update_option( 'page_on_front', $page_id ); 64 65 $this->go_to( home_url() ); 66 $this->assertQueryTrue( 'is_front_page', 'is_singular', 'is_page' ); 67 68 $expected = '<link rel="alternate" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n"; 69 $expected .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n"; 70 71 $this->assertEquals( $expected, get_echo( 'wp_oembed_add_discovery_links' ) ); 72 73 update_option( 'show_on_front', $show_on_front ); 74 update_option( 'page_on_front', $page_on_front ); 75 } 50 76 } -
tests/phpunit/tests/oembed/postEmbedUrl.php
diff --git tests/phpunit/tests/oembed/postEmbedUrl.php tests/phpunit/tests/oembed/postEmbedUrl.php index dda0f3c..c38a249 100644
class Tests_Post_Embed_URL extends WP_UnitTestCase { 21 21 update_option( 'permalink_structure', '' ); 22 22 } 23 23 24 /** 25 * @ticket 34971 26 */ 27 function test_get_post_embed_url_static_front_page() { 28 $show_on_front = get_option( 'show_on_front' ); 29 $page_on_front = get_option( 'page_on_front' ); 30 31 update_option( 'permalink_structure', '/%postname%' ); 32 33 $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); 34 35 update_option( 'show_on_front', 'page' ); 36 update_option( 'page_on_front', $post_id ); 37 38 $embed_url = get_post_embed_url( $post_id ); 39 40 $this->assertEquals( user_trailingslashit( trailingslashit( home_url() ) . 'embed' ), $embed_url ); 41 42 update_option( 'show_on_front', $show_on_front ); 43 update_option( 'page_on_front', $page_on_front ); 44 update_option( 'permalink_structure', '' ); 45 } 46 24 47 function test_get_post_embed_url_with_ugly_permalinks() { 25 48 $post_id = self::factory()->post->create(); 26 49 $permalink = get_permalink( $post_id ); … … class Tests_Post_Embed_URL extends WP_UnitTestCase { 28 51 29 52 $this->assertEquals( $permalink . '&embed=true', $embed_url ); 30 53 } 54 55 /** 56 * @ticket 34971 57 */ 58 function test_get_post_embed_url_static_front_page_with_ugly_permalinks() { 59 $show_on_front = get_option( 'show_on_front' ); 60 $page_on_front = get_option( 'page_on_front' ); 61 62 $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); 63 64 update_option( 'show_on_front', 'page' ); 65 update_option( 'page_on_front', $post_id ); 66 67 $embed_url = get_post_embed_url( $post_id ); 68 69 $this->assertEquals( trailingslashit( home_url() ) . '?embed=true', $embed_url ); 70 71 update_option( 'show_on_front', $show_on_front ); 72 update_option( 'page_on_front', $page_on_front ); 73 } 31 74 } -
tests/phpunit/tests/rewrite.php
diff --git tests/phpunit/tests/rewrite.php tests/phpunit/tests/rewrite.php index 1f7426e..3df47fb 100644
class Tests_Rewrite extends WP_UnitTestCase { 304 304 } 305 305 306 306 /** 307 * @ticket 34971 308 */ 309 function test_url_to_postid_static_front_page() { 310 $show_on_front = get_option( 'show_on_front' ); 311 $page_on_front = get_option( 'page_on_front' ); 312 313 $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); 314 315 $this->assertSame( 0, url_to_postid( home_url() ) ); 316 317 update_option( 'show_on_front', 'page' ); 318 update_option( 'page_on_front', $post_id ); 319 320 $this->assertSame( $post_id, url_to_postid( set_url_scheme( home_url(), 'http' ) ) ); 321 $this->assertSame( $post_id, url_to_postid( set_url_scheme( home_url(), 'https' ) ) ); 322 $this->assertSame( $post_id, url_to_postid( str_replace( array( 'http://', 'https://' ), 'http://www.', home_url() ) ) ); 323 $this->assertSame( $post_id, url_to_postid( home_url() . '#random' ) ); 324 $this->assertSame( $post_id, url_to_postid( home_url() . '?random' ) ); 325 326 update_option( 'show_on_front', $show_on_front ); 327 update_option( 'page_on_front', $page_on_front ); 328 } 329 330 /** 307 331 * @ticket 21970 308 332 */ 309 333 function test_parse_request_with_post_slug_that_clashes_with_a_trashed_page() {