Ticket #34971: 34971.3.diff
File 34971.3.diff, 17.6 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 035bbc3..8926a6c 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/embed.php
diff --git src/wp-includes/embed.php src/wp-includes/embed.php index 2736204..cdeaf79 100644
function get_post_embed_url( $post = null ) { 387 387 return false; 388 388 } 389 389 390 if ( get_option( 'permalink_structure' ) ) { 391 $embed_url = trailingslashit( get_permalink( $post ) ) . user_trailingslashit( 'embed' ); 392 } else { 390 $embed_url = trailingslashit( get_permalink( $post ) ) . user_trailingslashit( 'embed' ); 391 $path_conflict = get_page_by_path( str_replace( home_url(), '', $embed_url ), OBJECT, get_post_types( array( 'public' => true ) ) ); 392 393 if ( ! get_option( 'permalink_structure' ) || $path_conflict ) { 393 394 $embed_url = add_query_arg( array( 'embed' => 'true' ), get_permalink( $post ) ); 394 395 } 395 396 -
src/wp-includes/post.php
diff --git src/wp-includes/post.php src/wp-includes/post.php index 75850bc..aad6609 100644
function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p 3574 3574 * @param bool $bad_slug Whether the slug would be bad as an attachment slug. 3575 3575 * @param string $slug The post slug. 3576 3576 */ 3577 if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) {3577 if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) { 3578 3578 $suffix = 2; 3579 3579 do { 3580 3580 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; … … function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p 3604 3604 * @param string $post_type Post type. 3605 3605 * @param int $post_parent Post parent ID. 3606 3606 */ 3607 if ( $post_name_check || in_array( $slug, $feeds ) || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) {3607 if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) { 3608 3608 $suffix = 2; 3609 3609 do { 3610 3610 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; … … function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p 3649 3649 * @param string $slug The post slug. 3650 3650 * @param string $post_type Post type. 3651 3651 */ 3652 if ( $post_name_check || in_array( $slug, $feeds ) || $conflicts_with_date_archive || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) {3652 if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || $conflicts_with_date_archive || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) { 3653 3653 $suffix = 2; 3654 3654 do { 3655 3655 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; -
src/wp-includes/query.php
diff --git src/wp-includes/query.php src/wp-includes/query.php index ee0fc97..185b936 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..bb6a7c8 100644
4 4 * @group oembed 5 5 */ 6 6 class Tests_Post_Embed_URL extends WP_UnitTestCase { 7 function test_ get_post_embed_url_non_existent_post() {7 function test_non_existent_post() { 8 8 $embed_url = get_post_embed_url( 0 ); 9 9 $this->assertFalse( $embed_url ); 10 10 } 11 11 12 function test_ get_post_embed_url_with_pretty_permalinks() {13 update_option( 'permalink_structure','/%postname%' );12 function test_with_pretty_permalinks() { 13 $this->set_permalink_structure( '/%postname%' ); 14 14 15 15 $post_id = self::factory()->post->create(); 16 16 $permalink = get_permalink( $post_id ); 17 17 $embed_url = get_post_embed_url( $post_id ); 18 18 19 $this->assertEquals( user_trailingslashit( trailingslashit( $permalink ) . 'embed' ), $embed_url ); 20 21 update_option( 'permalink_structure', '' ); 19 $this->assertEquals( $permalink . '/embed', $embed_url ); 22 20 } 23 21 24 function test_ get_post_embed_url_with_ugly_permalinks() {22 function test_with_ugly_permalinks() { 25 23 $post_id = self::factory()->post->create(); 26 24 $permalink = get_permalink( $post_id ); 27 25 $embed_url = get_post_embed_url( $post_id ); 28 26 29 27 $this->assertEquals( $permalink . '&embed=true', $embed_url ); 30 28 } 29 30 /** 31 * @ticket 34971 32 */ 33 function test_static_front_page() { 34 $show_on_front = get_option( 'show_on_front' ); 35 $page_on_front = get_option( 'page_on_front' ); 36 37 $this->set_permalink_structure( '/%postname%/' ); 38 39 $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); 40 41 update_option( 'show_on_front', 'page' ); 42 update_option( 'page_on_front', $post_id ); 43 44 $embed_url = get_post_embed_url( $post_id ); 45 46 $this->assertEquals( user_trailingslashit( trailingslashit( home_url() ) . 'embed' ), $embed_url ); 47 48 update_option( 'show_on_front', $show_on_front ); 49 update_option( 'page_on_front', $page_on_front ); 50 } 51 52 /** 53 * @ticket 34971 54 */ 55 function test_static_front_page_with_ugly_permalinks() { 56 $show_on_front = get_option( 'show_on_front' ); 57 $page_on_front = get_option( 'page_on_front' ); 58 59 $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); 60 61 update_option( 'show_on_front', 'page' ); 62 update_option( 'page_on_front', $post_id ); 63 64 $embed_url = get_post_embed_url( $post_id ); 65 66 $this->assertEquals( trailingslashit( home_url() ) . '?embed=true', $embed_url ); 67 68 update_option( 'show_on_front', $show_on_front ); 69 update_option( 'page_on_front', $page_on_front ); 70 } 71 72 /** 73 * @ticket 34971 74 */ 75 function test_page_conflicts_with_embed_slug() { 76 $this->set_permalink_structure( '/%postname%/' ); 77 78 $parent_page = self::factory()->post->create( array( 'post_type' => 'page' ) ); 79 80 add_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) ); 81 $child_page = self::factory()->post->create( array( 82 'post_type' => 'page', 83 'post_parent' => $parent_page, 84 'post_name' => 'embed', 85 ) ); 86 remove_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) ); 87 88 $this->assertEquals( get_permalink( $parent_page ) . '?embed=true', get_post_embed_url( $parent_page ) ); 89 $this->assertEquals( get_permalink( $child_page ) . 'embed/', get_post_embed_url( $child_page ) ); 90 } 91 92 /** 93 * @ticket 34971 94 */ 95 function test_static_front_page_conflicts_with_embed_slug() { 96 $show_on_front = get_option( 'show_on_front' ); 97 $page_on_front = get_option( 'page_on_front' ); 98 99 $this->set_permalink_structure( '/%postname%/' ); 100 101 // Create a post with the 'embed' post_name 102 add_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) ); 103 $post_embed_slug = self::factory()->post->create( array( 'post_name' => 'embed' ) ); 104 remove_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) ); 105 $page_front = self::factory()->post->create( array( 'post_type' => 'page' ) ); 106 107 update_option( 'show_on_front', 'page' ); 108 update_option( 'page_on_front', $page_front ); 109 110 $this->assertEquals( home_url() . '/embed/embed/', get_post_embed_url( $post_embed_slug ) ); 111 $this->assertEquals( home_url() . '/?embed=true', get_post_embed_url( $page_front ) ); 112 113 update_option( 'show_on_front', $show_on_front ); 114 update_option( 'page_on_front', $page_on_front ); 115 update_option( 'permalink_structure', '' ); 116 } 117 118 public function filter_unique_post_slug() { 119 return 'embed'; 120 } 31 121 } -
tests/phpunit/tests/post/wpUniquePostSlug.php
diff --git tests/phpunit/tests/post/wpUniquePostSlug.php tests/phpunit/tests/post/wpUniquePostSlug.php index 354997e..2296510 100644
class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { 302 302 $found = wp_unique_post_slug( '32', $p, 'publish', 'post', 0 ); 303 303 $this->assertEquals( '32', $found ); 304 304 } 305 306 /** 307 * @ticket 34971 308 */ 309 public function test_embed_slug_should_be_suffixed_for_posts() { 310 $this->set_permalink_structure( '/%postname%/' ); 311 312 $p = self::factory()->post->create( array( 313 'post_type' => 'post', 314 'post_name' => 'embed', 315 ) ); 316 317 $found = wp_unique_post_slug( 'embed', $p, 'publish', 'post', 0 ); 318 $this->assertEquals( 'embed-2', $found ); 319 } 320 321 /** 322 * @ticket 34971 323 */ 324 public function test_embed_slug_should_be_suffixed_for_pages() { 325 $this->set_permalink_structure( '/%postname%/' ); 326 327 $p = self::factory()->post->create( array( 328 'post_type' => 'page', 329 'post_name' => 'embed', 330 ) ); 331 332 $found = wp_unique_post_slug( 'embed', $p, 'publish', 'paage', 0 ); 333 $this->assertEquals( 'embed-2', $found ); 334 } 335 336 /** 337 * @ticket 34971 338 */ 339 public function test_embed_slug_should_be_suffixed_for_attachments() { 340 $this->set_permalink_structure( '/%postname%/' ); 341 342 $p = self::factory()->post->create( array( 343 'post_type' => 'attachment', 344 'post_name' => 'embed', 345 ) ); 346 347 $found = wp_unique_post_slug( 'embed', $p, 'publish', 'attachment', 0 ); 348 $this->assertEquals( 'embed-2', $found ); 349 } 305 350 } -
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() {