Changeset 39507
- Timestamp:
- 12/05/2016 07:38:16 PM (8 years ago)
- Location:
- branches/4.7
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.7
-
branches/4.7/src/wp-includes/class-wp-customize-manager.php
r39500 r39507 1007 1007 ) ); 1008 1008 foreach ( $existing_posts_query->posts as $existing_post ) { 1009 $existing_starter_content_posts[ $existing_post->post_type . ':' . $existing_post->post_name ] = $existing_post; 1009 $post_name = $existing_post->post_name; 1010 if ( empty( $post_name ) ) { 1011 $post_name = get_post_meta( $existing_post->ID, '_customize_draft_post_name', true ); 1012 } 1013 $existing_starter_content_posts[ $existing_post->post_type . ':' . $post_name ] = $existing_post; 1010 1014 } 1011 1015 } … … 1068 1072 1069 1073 $attachment_post_data = array_merge( 1070 wp_array_slice_assoc( $attachment, array( 'post_title', 'post_content', 'post_excerpt' , 'post_name') ),1074 wp_array_slice_assoc( $attachment, array( 'post_title', 'post_content', 'post_excerpt' ) ), 1071 1075 array( 1072 1076 'post_status' => 'auto-draft', // So attachment will be garbage collected in a week if changeset is never published. … … 1086 1090 } 1087 1091 update_post_meta( $attachment_id, '_starter_content_theme', $this->get_stylesheet() ); 1092 update_post_meta( $attachment_id, '_customize_draft_post_name', $attachment['post_name'] ); 1088 1093 } 1089 1094 -
branches/4.7/src/wp-includes/class-wp-customize-nav-menus.php
r39346 r39507 804 804 $postarr['post_name'] = sanitize_title( $postarr['post_title'] ); 805 805 } 806 if ( ! isset( $postarr['meta_input'] ) ) { 807 $postarr['meta_input'] = array(); 808 } 809 $postarr['meta_input']['_customize_draft_post_name'] = $postarr['post_name']; 810 unset( $postarr['post_name'] ); 806 811 807 812 add_filter( 'wp_insert_post_empty_content', '__return_false', 1000 ); … … 1193 1198 foreach ( $post_ids as $post_id ) { 1194 1199 $target_status = 'attachment' === get_post_type( $post_id ) ? 'inherit' : 'publish'; 1200 $args = array( 1201 'ID' => $post_id, 1202 'post_status' => $target_status, 1203 ); 1204 $post_name = get_post_meta( $post_id, '_customize_draft_post_name', true ); 1205 if ( $post_name ) { 1206 $args['post_name'] = $post_name; 1207 } 1195 1208 1196 1209 // Note that wp_publish_post() cannot be used because unique slugs need to be assigned. 1197 wp_update_post( array( 'ID' => $post_id, 'post_status' => $target_status ) ); 1210 wp_update_post( wp_slash( $args ) ); 1211 1212 delete_post_meta( $post_id, '_customize_draft_post_name' ); 1198 1213 } 1199 1214 } -
branches/4.7/src/wp-includes/post.php
r39463 r39507 3679 3679 if ( 'attachment' == $post_type ) { 3680 3680 // Attachment slugs must be unique across all types. 3681 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_ status != 'auto-draft' AND post_name = %s AND ID != %d LIMIT 1";3681 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1"; 3682 3682 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID ) ); 3683 3683 … … 3707 3707 * namespace than posts so page slugs are allowed to overlap post slugs. 3708 3708 */ 3709 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_ status != 'auto-draft' AND post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1";3709 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1"; 3710 3710 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID, $post_parent ) ); 3711 3711 … … 3731 3731 } else { 3732 3732 // Post slugs must be unique across all posts. 3733 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_ status != 'auto-draft' AND post_name = %s AND post_type = %s AND ID != %d LIMIT 1";3733 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; 3734 3734 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) ); 3735 3735 -
branches/4.7/tests/phpunit/tests/ajax/CustomizeMenus.php
r39138 r39507 602 602 $this->assertEquals( 'Hello World', $post->post_title ); 603 603 $this->assertEquals( 'post', $post->post_type ); 604 $this->assertEquals( 'hello-world', $post->post_name ); 604 $this->assertEquals( '', $post->post_name ); 605 $this->assertEquals( 'hello-world', get_post_meta( $post->ID, '_customize_draft_post_name', true ) ); 605 606 } 606 607 -
branches/4.7/tests/phpunit/tests/customize/manager.php
r39435 r39507 454 454 } else { 455 455 $this->assertEquals( 'auto-draft', $post->post_status ); 456 $this->assertEmpty( $post->post_name ); 456 457 } 457 $posts_by_name[ $post->post_name ] = $post->ID; 458 $post_name = $post->post_name; 459 if ( empty( $post_name ) ) { 460 $post_name = get_post_meta( $post->ID, '_customize_draft_post_name', true ); 461 } 462 $posts_by_name[ $post_name ] = $post->ID; 458 463 } 459 464 $this->assertEquals( array( 'waffles', 'canola', 'home', 'about', 'blog', 'custom' ), array_keys( $posts_by_name ) ); … … 465 470 $attachment_metadata = wp_get_attachment_metadata( $posts_by_name['waffles'] ); 466 471 $this->assertEquals( 'Waffles', get_post( $posts_by_name['waffles'] )->post_title ); 472 $this->assertEquals( 'waffles', get_post_meta( $posts_by_name['waffles'], '_customize_draft_post_name', true ) ); 467 473 $this->assertArrayHasKey( 'file', $attachment_metadata ); 468 474 $this->assertContains( 'waffles', $attachment_metadata['file'] ); … … 489 495 $wp_customize->import_theme_starter_content(); 490 496 $changeset_data = $wp_customize->changeset_data(); 491 $this->assertEqualSets( array_values( $posts_by_name ), $changeset_data['nav_menus_created_posts']['value'] , 'Auto-drafts should not get re-created and amended with each import.' );497 $this->assertEqualSets( array_values( $posts_by_name ), $changeset_data['nav_menus_created_posts']['value'] ); // Auto-drafts should not get re-created and amended with each import. 492 498 493 499 // Test that saving non-starter content on top of the changeset clears the starter_content flag. … … 540 546 $this->assertContains( 'waffles', get_header_image() ); 541 547 $this->assertContains( 'waffles', get_background_image() ); 548 $this->assertEquals( 'waffles', get_post( $posts_by_name['waffles'] )->post_name ); 549 $this->assertEmpty( get_post_meta( $posts_by_name['waffles'], '_customize_draft_post_name', true ) ); 542 550 } 543 551 -
branches/4.7/tests/phpunit/tests/customize/nav-menus.php
r39038 r39507 550 550 $this->assertInstanceOf( 'WP_Post', $r ); 551 551 $this->assertEquals( 'Hello World', $r->post_title ); 552 $this->assertEquals( 'hello-world', $r->post_name ); 552 $this->assertEquals( '', $r->post_name ); 553 $this->assertEquals( 'hello-world', get_post_meta( $r->ID, '_customize_draft_post_name', true ) ); 553 554 $this->assertEquals( 'post', $r->post_type ); 554 555 … … 557 558 $this->assertEquals( 'Hello World', $r->post_title ); 558 559 $this->assertEquals( 'post', $r->post_type ); 559 $this->assertEquals( 'greetings-world', $r->post_name ); 560 $this->assertEquals( '', $r->post_name ); 561 $this->assertEquals( 'greetings-world', get_post_meta( $r->ID, '_customize_draft_post_name', true ) ); 560 562 $this->assertEquals( 'Hi World', $r->post_content ); 561 563 } … … 740 742 do_action( 'customize_register', $this->wp_customize ); 741 743 742 $post_ids = $this->factory()->post->create_many( 3, array( 743 'post_status' => 'auto-draft', 744 'post_type' => 'post', 745 'post_name' => 'auto-draft', 746 ) ); 744 $post_ids = array(); 745 for ( $i = 0; $i < 3; $i += 1 ) { 746 $r = $menus->insert_auto_draft_post( array( 747 'post_title' => 'Auto Draft ' . $i, 748 'post_type' => 'post', 749 'post_name' => 'auto-draft-' . $i, 750 ) ); 751 $this->assertInstanceOf( 'WP_Post', $r ); 752 $post_ids[] = $r->ID; 753 } 754 747 755 $pre_published_post_id = $this->factory()->post->create( array( 'post_status' => 'publish' ) ); 748 756 … … 755 763 foreach ( $post_ids as $post_id ) { 756 764 $this->assertEquals( 'auto-draft', get_post_status( $post_id ) ); 765 $this->assertEmpty( get_post( $post_id )->post_name ); 766 $this->assertNotEmpty( get_post_meta( $post_id, '_customize_draft_post_name', true ) ); 757 767 } 758 768 … … 762 772 foreach ( $post_ids as $post_id ) { 763 773 $this->assertEquals( 'publish', get_post_status( $post_id ) ); 774 $this->assertRegExp( '/^auto-draft-\d+$/', get_post( $post_id )->post_name ); 775 $this->assertEmpty( get_post_meta( $post_id, '_customize_draft_post_name', true ) ); 764 776 } 765 777 -
branches/4.7/tests/phpunit/tests/post/wpUniquePostSlug.php
r39412 r39507 348 348 $this->assertSame( 'embed-2', $found ); 349 349 } 350 351 /**352 * @ticket 38928353 */354 public function test_non_unique_slugs_for_existing_auto_draft_posts() {355 $auto_draft_post_id = self::factory()->post->create( array(356 'post_type' => 'post',357 'post_name' => 'existing-post',358 'post_status' => 'auto-draft',359 ) );360 $auto_draft_page_id = self::factory()->post->create( array(361 'post_type' => 'page',362 'post_name' => 'existing-page',363 'post_status' => 'auto-draft',364 ) );365 $auto_draft_attachment_id = self::factory()->attachment->create_object( 'image.jpg', $auto_draft_page_id, array(366 'post_mime_type' => 'image/jpeg',367 'post_type' => 'attachment',368 'post_name' => 'existing-attachment',369 'post_status' => 'auto-draft',370 ) );371 372 $post_id = self::factory()->post->create( array( 'post_type' => 'post' ) );373 $page_id = self::factory()->post->create( array( 'post_type' => 'page' ) );374 $attachment_id = self::factory()->attachment->create_object( 'image2.jpg', $page_id, array(375 'post_mime_type' => 'image/jpeg',376 'post_type' => 'attachment',377 'post_name' => 'existing-image',378 ) );379 380 $this->assertEquals( 'existing-post', wp_unique_post_slug( 'existing-post', $post_id, 'publish', get_post_type( $post_id ), 0 ) );381 wp_publish_post( $auto_draft_post_id );382 $this->assertEquals( 'existing-post-2', wp_unique_post_slug( 'existing-post', $post_id, 'publish', get_post_type( $post_id ), 0 ) );383 384 $this->assertEquals( 'existing-page', wp_unique_post_slug( 'existing-page', $page_id, 'publish', get_post_type( $page_id ), 0 ) );385 wp_publish_post( $auto_draft_page_id );386 $this->assertEquals( 'existing-page-2', wp_unique_post_slug( 'existing-page', $page_id, 'publish', get_post_type( $page_id ), 0 ) );387 388 $this->assertEquals( 'existing-attachment', wp_unique_post_slug( 'existing-attachment', $attachment_id, 'publish', get_post_type( $attachment_id ), 0 ) );389 wp_publish_post( $auto_draft_attachment_id );390 $this->assertEquals( 'existing-attachment-2', wp_unique_post_slug( 'existing-attachment', $attachment_id, 'publish', get_post_type( $attachment_id ), 0 ) );391 }392 350 }
Note: See TracChangeset
for help on using the changeset viewer.