Changeset 36307
- Timestamp:
- 01/15/2016 07:55:19 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-rewrite.php
r36255 r36307 1023 1023 $feedquery2 = $feedindex . '?' . $query . '&feed=' . $this->preg_index($num_toks + 1); 1024 1024 1025 // Create query and regex for embeds. 1026 $embedmatch = $match . $embedregex; 1027 $embedquery = $embedindex . '?' . $query . '&embed=true'; 1028 1025 1029 // If asked to, turn the feed queries into comment feed ones. 1026 1030 if ( $forcomments ) { … … 1034 1038 // ...adding on /feed/ regexes => queries 1035 1039 if ( $feed ) { 1036 $rewrite = array( $feedmatch => $feedquery, $feedmatch2 => $feedquery2 );1040 $rewrite = array( $feedmatch => $feedquery, $feedmatch2 => $feedquery2, $embedmatch => $embedquery ); 1037 1041 } 1038 1042 -
trunk/src/wp-includes/embed.php
r36059 r36307 346 346 $output = ''; 347 347 348 if ( is_singular() && ! is_front_page()) {348 if ( is_singular() ) { 349 349 $output .= '<link rel="alternate" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n"; 350 350 … … 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 } -
trunk/src/wp-includes/post.php
r36269 r36307 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 { … … 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 { … … 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 { -
trunk/src/wp-includes/query.php
r36278 r36307 1457 1457 , 'fields' 1458 1458 , 'menu_order' 1459 , 'embed' 1459 1460 ); 1460 1461 … … 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; … … 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; … … 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 ) ); -
trunk/src/wp-includes/rewrite.php
r36217 r36307 479 479 } 480 480 481 // Get rid of the #anchor 482 $url_split = explode('#', $url); 483 $url = $url_split[0]; 484 485 // Get rid of URL ?query=string 486 $url_split = explode('?', $url); 487 $url = $url_split[0]; 488 489 // Set the correct URL scheme. 490 $url = set_url_scheme( $url ); 491 492 // Add 'www.' if it is absent and should be there 493 if ( false !== strpos(home_url(), '://www.') && false === strpos($url, '://www.') ) 494 $url = str_replace('://', '://www.', $url); 495 496 // Strip 'www.' if it is present and shouldn't be 497 if ( false === strpos(home_url(), '://www.') ) 498 $url = str_replace('://www.', '://', $url); 499 500 if ( trim( $url, '/' ) === home_url() && 'page' == get_option( 'show_on_front' ) ) { 501 $page_on_front = get_option( 'page_on_front' ); 502 503 if ( $page_on_front && get_post( $page_on_front ) instanceof WP_Post ) { 504 return (int) $page_on_front; 505 } 506 } 507 481 508 // Check to see if we are using rewrite rules 482 509 $rewrite = $wp_rewrite->wp_rewrite_rules(); … … 485 512 if ( empty($rewrite) ) 486 513 return 0; 487 488 // Get rid of the #anchor489 $url_split = explode('#', $url);490 $url = $url_split[0];491 492 // Get rid of URL ?query=string493 $url_split = explode('?', $url);494 $url = $url_split[0];495 496 // Set the correct URL scheme.497 $url = set_url_scheme( $url );498 499 // Add 'www.' if it is absent and should be there500 if ( false !== strpos(home_url(), '://www.') && false === strpos($url, '://www.') )501 $url = str_replace('://', '://www.', $url);502 503 // Strip 'www.' if it is present and shouldn't be504 if ( false === strpos(home_url(), '://www.') )505 $url = str_replace('://www.', '://', $url);506 514 507 515 // Strip 'index.php/' if we're not using path info permalinks -
trunk/tests/phpunit/tests/oembed/controller.php
r35654 r36307 170 170 } 171 171 172 function test_request_xml() {173 $user = self::factory()->user->create_and_get( array(174 'display_name' => 'John Doe',175 ) );172 /** 173 * @ticket 34971 174 */ 175 function test_request_static_front_page() { 176 176 $post = self::factory()->post->create_and_get( array( 177 'post_author' => $user->ID, 178 'post_title' => 'Hello World', 179 ) ); 180 181 $request = new WP_REST_Request( 'GET', '/oembed/1.0/embed' ); 182 $request->set_param( 'url', get_permalink( $post->ID ) ); 183 $request->set_param( 'format', 'xml' ); 177 'post_title' => 'Front page', 178 'post_type' => 'page', 179 ) ); 180 181 update_option( 'show_on_front', 'page' ); 182 update_option( 'page_on_front', $post->ID ); 183 184 $request = new WP_REST_Request( 'GET', '/oembed/1.0/embed' ); 185 $request->set_param( 'url', home_url() ); 184 186 $request->set_param( 'maxwidth', 400 ); 185 187 … … 202 204 $this->assertEquals( get_bloginfo( 'name' ), $data['provider_name'] ); 203 205 $this->assertEquals( get_home_url(), $data['provider_url'] ); 206 $this->assertEquals( get_bloginfo( 'name' ), $data['author_name'] ); 207 $this->assertEquals( get_home_url(), $data['author_url'] ); 208 $this->assertEquals( $post->post_title, $data['title'] ); 209 $this->assertEquals( 'rich', $data['type'] ); 210 $this->assertTrue( $data['width'] <= $request['maxwidth'] ); 211 212 update_option( 'show_on_front', 'posts' ); 213 } 214 215 function test_request_xml() { 216 $user = self::factory()->user->create_and_get( array( 217 'display_name' => 'John Doe', 218 ) ); 219 $post = self::factory()->post->create_and_get( array( 220 'post_author' => $user->ID, 221 'post_title' => 'Hello World', 222 ) ); 223 224 $request = new WP_REST_Request( 'GET', '/oembed/1.0/embed' ); 225 $request->set_param( 'url', get_permalink( $post->ID ) ); 226 $request->set_param( 'format', 'xml' ); 227 $request->set_param( 'maxwidth', 400 ); 228 229 $response = $this->server->dispatch( $request ); 230 $data = $response->get_data(); 231 232 $this->assertInternalType( 'array', $data ); 233 $this->assertNotEmpty( $data ); 234 235 $this->assertArrayHasKey( 'version', $data ); 236 $this->assertArrayHasKey( 'provider_name', $data ); 237 $this->assertArrayHasKey( 'provider_url', $data ); 238 $this->assertArrayHasKey( 'author_name', $data ); 239 $this->assertArrayHasKey( 'author_url', $data ); 240 $this->assertArrayHasKey( 'title', $data ); 241 $this->assertArrayHasKey( 'type', $data ); 242 $this->assertArrayHasKey( 'width', $data ); 243 244 $this->assertEquals( '1.0', $data['version'] ); 245 $this->assertEquals( get_bloginfo( 'name' ), $data['provider_name'] ); 246 $this->assertEquals( get_home_url(), $data['provider_url'] ); 204 247 $this->assertEquals( $user->display_name, $data['author_name'] ); 205 248 $this->assertEquals( get_author_posts_url( $user->ID, $user->user_nicename ), $data['author_url'] ); -
trunk/tests/phpunit/tests/oembed/discovery.php
r36059 r36307 10 10 11 11 function test_add_oembed_discovery_links_front_page() { 12 $this->go_to( home_url( '/') );12 $this->go_to( home_url() ); 13 13 $this->assertSame( '', get_echo( 'wp_oembed_add_discovery_links' ) ); 14 $this->assertSame( 0, url_to_postid( home_url() ) ); 14 15 } 15 16 17 /** 18 * @ticket 34971 19 */ 16 20 function test_add_oembed_discovery_links_static_front_page() { 17 21 update_option( 'show_on_front', 'page' ); 18 update_option( 'page_for_posts', self::factory()->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) ) );19 22 update_option( 'page_on_front', self::factory()->post->create( array( 'post_title' => 'front-page', 'post_type' => 'page' ) ) ); 20 23 21 $this->go_to( home_url('/') ); 22 $this->assertSame( '', get_echo( 'wp_oembed_add_discovery_links' ) ); 24 $this->go_to( home_url() ); 25 $this->assertQueryTrue( 'is_front_page', 'is_singular', 'is_page' ); 26 27 $expected = '<link rel="alternate" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n"; 28 $expected .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n"; 29 30 $this->assertSame( $expected, get_echo( 'wp_oembed_add_discovery_links' ) ); 23 31 24 32 update_option( 'show_on_front', 'posts' ); -
trunk/tests/phpunit/tests/oembed/postEmbedUrl.php
r35242 r36307 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(); … … 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 ); … … 29 27 $this->assertEquals( $permalink . '&embed=true', $embed_url ); 30 28 } 29 30 /** 31 * @ticket 34971 32 */ 33 function test_static_front_page() { 34 $this->set_permalink_structure( '/%postname%/' ); 35 36 $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); 37 38 update_option( 'show_on_front', 'page' ); 39 update_option( 'page_on_front', $post_id ); 40 41 $embed_url = get_post_embed_url( $post_id ); 42 43 $this->assertSame( user_trailingslashit( trailingslashit( home_url() ) . 'embed' ), $embed_url ); 44 45 update_option( 'show_on_front', 'posts' ); 46 } 47 48 /** 49 * @ticket 34971 50 */ 51 function test_static_front_page_with_ugly_permalinks() { 52 $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); 53 54 update_option( 'show_on_front', 'page' ); 55 update_option( 'page_on_front', $post_id ); 56 57 $embed_url = get_post_embed_url( $post_id ); 58 59 $this->assertSame( trailingslashit( home_url() ) . '?embed=true', $embed_url ); 60 61 update_option( 'show_on_front', 'posts' ); 62 } 63 64 /** 65 * @ticket 34971 66 */ 67 function test_page_conflicts_with_embed_slug() { 68 $this->set_permalink_structure( '/%postname%/' ); 69 70 $parent_page = self::factory()->post->create( array( 'post_type' => 'page' ) ); 71 72 add_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) ); 73 $child_page = self::factory()->post->create( array( 74 'post_type' => 'page', 75 'post_parent' => $parent_page, 76 'post_name' => 'embed', 77 ) ); 78 remove_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) ); 79 80 $this->assertSame( get_permalink( $parent_page ) . '?embed=true', get_post_embed_url( $parent_page ) ); 81 $this->assertSame( get_permalink( $child_page ) . 'embed/', get_post_embed_url( $child_page ) ); 82 } 83 84 /** 85 * @ticket 34971 86 */ 87 function test_static_front_page_conflicts_with_embed_slug() { 88 $this->set_permalink_structure( '/%postname%/' ); 89 90 // Create a post with the 'embed' post_name 91 add_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) ); 92 $post_embed_slug = self::factory()->post->create( array( 'post_name' => 'embed' ) ); 93 remove_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) ); 94 $page_front = self::factory()->post->create( array( 'post_type' => 'page' ) ); 95 96 update_option( 'show_on_front', 'page' ); 97 update_option( 'page_on_front', $page_front ); 98 99 $this->assertSame( home_url() . '/embed/embed/', get_post_embed_url( $post_embed_slug ) ); 100 $this->assertSame( home_url() . '/?embed=true', get_post_embed_url( $page_front ) ); 101 102 update_option( 'show_on_front', 'posts' ); 103 } 104 105 public function filter_unique_post_slug() { 106 return 'embed'; 107 } 31 108 } -
trunk/tests/phpunit/tests/post/wpUniquePostSlug.php
r35243 r36307 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->assertSame( '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->assertSame( '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->assertSame( 'embed-2', $found ); 349 } 305 350 } -
trunk/tests/phpunit/tests/rewrite.php
r36254 r36307 305 305 306 306 /** 307 * @ticket 34971 308 */ 309 function test_url_to_postid_static_front_page() { 310 $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); 311 312 $this->assertSame( 0, url_to_postid( home_url() ) ); 313 314 update_option( 'show_on_front', 'page' ); 315 update_option( 'page_on_front', $post_id ); 316 317 $this->assertSame( $post_id, url_to_postid( set_url_scheme( home_url(), 'http' ) ) ); 318 $this->assertSame( $post_id, url_to_postid( set_url_scheme( home_url(), 'https' ) ) ); 319 $this->assertSame( $post_id, url_to_postid( str_replace( array( 'http://', 'https://' ), 'http://www.', home_url() ) ) ); 320 $this->assertSame( $post_id, url_to_postid( home_url() . '#random' ) ); 321 $this->assertSame( $post_id, url_to_postid( home_url() . '?random' ) ); 322 323 update_option( 'show_on_front', 'posts' ); 324 } 325 326 /** 307 327 * @ticket 21970 308 328 */
Note: See TracChangeset
for help on using the changeset viewer.