Changeset 41887
- Timestamp:
- 10/17/2017 08:14:56 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/css/common.css
r41882 r41887 965 965 } 966 966 967 #misc-publishing-actions .notice { 968 margin-left: 10px; 969 margin-right: 10px; 970 } 971 967 972 /* Filter bar */ 968 973 .wp-filter { -
trunk/src/wp-admin/includes/meta-boxes.php
r41763 r41887 222 222 </fieldset> 223 223 </div><?php // /misc-pub-section ?> 224 <?php endif; ?> 225 226 <?php if ( 'draft' === $post->post_status && get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) : ?> 227 <div class="notice notice-info notice-alt inline"> 228 <p> 229 <?php 230 echo sprintf( 231 /* translators: %s is the URL to the Customizer */ 232 __( 'This draft comes from your <a href="%s">unpublished customization changes</a>. You can edit, but there’s no need to publish now. It will be published automatically with those changes.' ), 233 esc_url( 234 add_query_arg( 235 'changeset_uuid', 236 rawurlencode( get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ), 237 admin_url( 'customize.php' ) 238 ) 239 ) 240 ); 241 ?> 242 </p> 243 </div> 224 244 <?php endif; ?> 225 245 -
trunk/src/wp-admin/includes/template.php
r41684 r41887 1737 1737 if ( 'private' == $post->post_status && 'private' != $post_status ) 1738 1738 $post_states['private'] = __('Private'); 1739 if ( 'draft' == $post->post_status && 'draft' != $post_status ) 1740 $post_states['draft'] = __('Draft'); 1739 if ( 'draft' === $post->post_status ) { 1740 if ( get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) { 1741 $post_states[] = __( 'Customization Draft' ); 1742 } elseif ( 'draft' !== $post_status ) { 1743 $post_states['draft'] = __( 'Draft' ); 1744 } 1745 } elseif ( 'trash' === $post->post_status && get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) { 1746 $post_states[] = __( 'Customization Draft' ); 1747 } 1741 1748 if ( 'pending' == $post->post_status && 'pending' != $post_status ) 1742 1749 $post_states['pending'] = _x('Pending', 'post status'); -
trunk/src/wp-admin/js/customize-nav-menus.js
r41868 r41887 98 98 'customize-menus-nonce': api.settings.nonce['customize-menus'], 99 99 'wp_customize': 'on', 100 'customize_changeset_uuid': api.settings.changeset.uuid, 100 101 'params': params 101 102 } ); -
trunk/src/wp-includes/class-wp-customize-nav-menus.php
r41868 r41887 795 795 } 796 796 797 /* 798 * If the changeset is a draft, this will change to draft the next time the changeset 799 * is updated; otherwise, auto-draft will persist in autosave revisions, until save. 800 */ 797 801 $postarr['post_status'] = 'auto-draft'; 798 802 … … 805 809 } 806 810 $postarr['meta_input']['_customize_draft_post_name'] = $postarr['post_name']; 811 $postarr['meta_input']['_customize_changeset_uuid'] = $this->manager->changeset_uuid(); 807 812 unset( $postarr['post_name'] ); 808 813 … … 1173 1178 1174 1179 /** 1175 * Sanitize post IDs for auto-draftposts created for nav menu items to be published.1180 * Sanitize post IDs for posts created for nav menu items to be published. 1176 1181 * 1177 1182 * @since 4.7.0 … … 1187 1192 } 1188 1193 $post = get_post( $post_id ); 1189 if ( 'auto-draft' !== $post->post_status ) {1194 if ( 'auto-draft' !== $post->post_status && 'draft' !== $post->post_status ) { 1190 1195 continue; 1191 1196 } … … 1218 1223 if ( ! empty( $post_ids ) ) { 1219 1224 foreach ( $post_ids as $post_id ) { 1225 1226 // Prevent overriding the status that a user may have prematurely updated the post to. 1227 $current_status = get_post_status( $post_id ); 1228 if ( 'auto-draft' !== $current_status && 'draft' !== $current_status ) { 1229 continue; 1230 } 1231 1220 1232 $target_status = 'attachment' === get_post_type( $post_id ) ? 'inherit' : 'publish'; 1221 1233 $args = array( -
trunk/src/wp-includes/nav-menu.php
r41811 r41887 1052 1052 } 1053 1053 remove_action( 'delete_post', '_wp_delete_customize_changeset_dependent_auto_drafts' ); 1054 foreach ( $data['nav_menus_created_posts']['value'] as $post_id ) { 1055 if ( ! empty( $post_id ) && 'auto-draft' === get_post_status( $post_id ) ) { 1056 wp_delete_post( $post_id, true ); 1054 foreach ( $data['nav_menus_created_posts']['value'] as $stub_post_id ) { 1055 if ( empty( $stub_post_id ) ) { 1056 continue; 1057 } 1058 if ( 'auto-draft' === get_post_status( $stub_post_id ) ) { 1059 wp_delete_post( $stub_post_id, true ); 1060 } elseif ( 'draft' === get_post_status( $stub_post_id ) ) { 1061 wp_trash_post( $stub_post_id ); 1062 delete_post_meta( $stub_post_id, '_customize_changeset_uuid' ); 1057 1063 } 1058 1064 } -
trunk/src/wp-includes/theme.php
r41824 r41887 3052 3052 3053 3053 /** 3054 * Make sure that auto-draft posts get their post_date bumped to prevent premature garbage-collection.3054 * Make sure that auto-draft posts get their post_date bumped or status changed to draft to prevent premature garbage-collection. 3055 3055 * 3056 3056 * When a changeset is updated but remains an auto-draft, ensure the post_date … … 3061 3061 * unless the changeset post itself is deleted. 3062 3062 * 3063 * When a changeset is updated to be a persistent draft or to be scheduled for 3064 * publishing, then transition any dependent auto-drafts to a draft status so 3065 * that they likewise will not be garbage-collected but also so that they can 3066 * be edited in the admin before publishing since there is not yet a post/page 3067 * editing flow in the Customizer. See #39752. 3068 * 3069 * @link https://core.trac.wordpress.org/ticket/39752 3070 * 3063 3071 * @since 4.8.0 3064 3072 * @access private … … 3079 3087 } 3080 3088 3089 $data = json_decode( $post->post_content, true ); 3090 if ( empty( $data['nav_menus_created_posts']['value'] ) ) { 3091 return; 3092 } 3093 3094 /* 3095 * Actually, in lieu of keeping alive, trash any customization drafts here if the changeset itself is 3096 * getting trashed. This is needed because when a changeset transitions to a draft, then any of the 3097 * dependent auto-draft post/page stubs will also get transitioned to customization drafts which 3098 * are then visible in the WP Admin. We cannot wait for the deletion of the changeset in which 3099 * _wp_delete_customize_changeset_dependent_auto_drafts() will be called, since they need to be 3100 * trashed to remove from visibility immediately. 3101 */ 3102 if ( 'trash' === $new_status ) { 3103 foreach ( $data['nav_menus_created_posts']['value'] as $post_id ) { 3104 if ( ! empty( $post_id ) && 'draft' === get_post_status( $post_id ) ) { 3105 wp_trash_post( $post_id ); 3106 } 3107 } 3108 return; 3109 } 3110 3111 $post_args = array(); 3081 3112 if ( 'auto-draft' === $new_status ) { 3082 3113 /* … … 3084 3115 * so that it will not be garbage-collected before the changeset. 3085 3116 */ 3086 $ new_post_date = $post->post_date;3117 $post_args['post_date'] = $post->post_date; // Note wp_delete_auto_drafts() only looks at this date. 3087 3118 } else { 3088 3119 /* 3089 3120 * Since the changeset no longer has an auto-draft (and it is not published) 3090 3121 * it is now a persistent changeset, a long-lived draft, and so any 3091 * associated auto-draft posts should have their dates 3092 * pushed out very far into the future to prevent them from ever 3093 * being garbage-collected. 3122 * associated auto-draft posts should likewise transition into having a draft 3123 * status. These drafts will be treated differently than regular drafts in 3124 * that they will be tied to the given changeset. The publish metabox is 3125 * replaced with a notice about how the post is part of a set of customized changes 3126 * which will be published when the changeset is published. 3094 3127 */ 3095 $new_post_date = gmdate( 'Y-m-d H:i:d', strtotime( '+100 years' ) ); 3096 } 3097 3098 $data = json_decode( $post->post_content, true ); 3099 if ( empty( $data['nav_menus_created_posts']['value'] ) ) { 3100 return; 3101 } 3128 $post_args['post_status'] = 'draft'; 3129 } 3130 3102 3131 foreach ( $data['nav_menus_created_posts']['value'] as $post_id ) { 3103 3132 if ( empty( $post_id ) || 'auto-draft' !== get_post_status( $post_id ) ) { … … 3106 3135 $wpdb->update( 3107 3136 $wpdb->posts, 3108 array( 'post_date' => $new_post_date ), // Note wp_delete_auto_drafts() only looks at this date.3137 $post_args, 3109 3138 array( 'ID' => $post_id ) 3110 3139 ); -
trunk/tests/phpunit/tests/ajax/CustomizeMenus.php
r39506 r41887 604 604 $this->assertEquals( '', $post->post_name ); 605 605 $this->assertEquals( 'hello-world', get_post_meta( $post->ID, '_customize_draft_post_name', true ) ); 606 $this->assertEquals( $this->wp_customize->changeset_uuid(), get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ); 606 607 } 607 608 -
trunk/tests/phpunit/tests/customize/nav-menus.php
r41204 r41887 542 542 $r = $menus->insert_auto_draft_post( array( 'post_title' => 'Non-existent', 'post_type' => 'nonexistent' ) ); 543 543 $this->assertInstanceOf( 'WP_Post', $r ); 544 $this->assertEquals( $this->wp_customize->changeset_uuid(), get_post_meta( $r->ID, '_customize_changeset_uuid', true ) ); 544 545 545 546 $r = $menus->insert_auto_draft_post( array( 'post_type' => 'post' ) ); … … 556 557 $this->assertEquals( '', $r->post_name ); 557 558 $this->assertEquals( 'hello-world', get_post_meta( $r->ID, '_customize_draft_post_name', true ) ); 559 $this->assertEquals( $this->wp_customize->changeset_uuid(), get_post_meta( $r->ID, '_customize_changeset_uuid', true ) ); 558 560 $this->assertEquals( 'post', $r->post_type ); 559 561 … … 564 566 $this->assertEquals( '', $r->post_name ); 565 567 $this->assertEquals( 'greetings-world', get_post_meta( $r->ID, '_customize_draft_post_name', true ) ); 568 $this->assertEquals( $this->wp_customize->changeset_uuid(), get_post_meta( $r->ID, '_customize_changeset_uuid', true ) ); 566 569 $this->assertEquals( 'Hi World', $r->post_content ); 567 570 } … … 717 720 ) ); 718 721 722 $draft_post_id = $this->factory()->post->create( array( 723 'post_status' => 'draft', 724 'post_title' => 'Draft', 725 'post_author' => $administrator_user_id, 726 ) ); 727 728 $private_post_id = $this->factory()->post->create( array( 729 'post_status' => 'private', 730 'post_title' => 'Private', 731 'post_author' => $administrator_user_id, 732 ) ); 733 719 734 $value = array( 720 735 'bad', … … 722 737 $author_post_id, 723 738 $administrator_post_id, 739 $draft_post_id, 740 $private_post_id, 724 741 ); 725 742 … … 734 751 wp_set_current_user( $administrator_user_id ); 735 752 $sanitized = $menus->sanitize_nav_menus_created_posts( $value ); 736 $this->assertEquals( array( $contributor_post_id, $author_post_id, $administrator_post_id ), $sanitized );753 $this->assertEquals( array( $contributor_post_id, $author_post_id, $administrator_post_id, $draft_post_id ), $sanitized ); 737 754 } 738 755 … … 747 764 748 765 $post_ids = array(); 749 for ( $i = 0; $i < 3; $i += 1 ) { 750 $r = $menus->insert_auto_draft_post( array( 751 'post_title' => 'Auto Draft ' . $i, 752 'post_type' => 'post', 753 'post_name' => 'auto-draft-' . $i, 754 ) ); 755 $this->assertInstanceOf( 'WP_Post', $r ); 756 $post_ids[] = $r->ID; 757 } 766 767 // Auto-draft. 768 $r = $menus->insert_auto_draft_post( array( 769 'post_title' => 'Auto Draft', 770 'post_type' => 'post', 771 'post_name' => 'auto-draft-1', 772 ) ); 773 $this->assertInstanceOf( 'WP_Post', $r ); 774 $post_ids[] = $r->ID; 775 776 // Draft. 777 $r = $menus->insert_auto_draft_post( array( 778 'post_title' => 'Draft', 779 'post_type' => 'post', 780 'post_name' => 'auto-draft-2', 781 ) ); 782 $this->assertInstanceOf( 'WP_Post', $r ); 783 wp_update_post( array( 784 'ID' => $r->ID, 785 'post_status' => 'draft', 786 ) ); 787 $post_ids[] = $r->ID; 788 789 $drafted_post_ids = $post_ids; 790 791 // Private (this will exclude it from being considered a stub). 792 $r = $menus->insert_auto_draft_post( array( 793 'post_title' => 'Private', 794 'post_type' => 'post', 795 'post_name' => 'auto-draft-3', 796 ) ); 797 $this->assertInstanceOf( 'WP_Post', $r ); 798 wp_update_post( array( 799 'ID' => $r->ID, 800 'post_status' => 'private', 801 ) ); 802 $post_ids[] = $r->ID; 803 $private_post_id = $r->ID; 804 805 // Trashed (this will exclude it from being considered a stub). 806 $r = $menus->insert_auto_draft_post( array( 807 'post_title' => 'Trash', 808 'post_type' => 'post', 809 'post_name' => 'auto-draft-4', 810 ) ); 811 $this->assertInstanceOf( 'WP_Post', $r ); 812 wp_trash_post( $r->ID ); 813 $post_ids[] = $r->ID; 814 $trashed_post_id = $r->ID; 758 815 759 816 $pre_published_post_id = $this->factory()->post->create( array( 'post_status' => 'publish' ) ); … … 764 821 $this->assertInstanceOf( 'WP_Customize_Filter_Setting', $setting ); 765 822 $this->assertEquals( array( $menus, 'sanitize_nav_menus_created_posts' ), $setting->sanitize_callback ); 766 $this->assertEquals( $post_ids, $setting->post_value() ); 767 foreach ( $post_ids as $post_id ) { 768 $this->assertEquals( 'auto-draft', get_post_status( $post_id ) ); 823 $this->assertEquals( $drafted_post_ids, $setting->post_value() ); 824 $this->assertArrayNotHasKey( $private_post_id, $post_ids ); 825 $this->assertArrayNotHasKey( $trashed_post_id, $post_ids ); 826 827 $this->assertEquals( 'auto-draft', get_post_status( $drafted_post_ids[0] ) ); 828 $this->assertEquals( 'draft', get_post_status( $drafted_post_ids[1] ) ); 829 foreach ( $drafted_post_ids as $post_id ) { 769 830 $this->assertEmpty( get_post( $post_id )->post_name ); 770 831 $this->assertNotEmpty( get_post_meta( $post_id, '_customize_draft_post_name', true ) ); … … 774 835 $setting->save(); 775 836 $this->assertEquals( $save_action_count + 1, did_action( 'customize_save_nav_menus_created_posts' ) ); 776 foreach ( $ post_ids as $post_id ) {837 foreach ( $drafted_post_ids as $post_id ) { 777 838 $this->assertEquals( 'publish', get_post_status( $post_id ) ); 778 839 $this->assertRegExp( '/^auto-draft-\d+$/', get_post( $post_id )->post_name ); … … 780 841 } 781 842 843 $this->assertEquals( 'private', get_post_status( $private_post_id ) ); 844 $this->assertEquals( 'trash', get_post_status( $trashed_post_id ) ); 845 782 846 // Ensure that unique slugs were assigned. 783 $posts = array_map( 'get_post', $ post_ids );847 $posts = array_map( 'get_post', $drafted_post_ids ); 784 848 $post_names = wp_list_pluck( $posts, 'post_name' ); 785 849 $this->assertEqualSets( $post_names, array_unique( $post_names ) ); -
trunk/tests/phpunit/tests/post/nav-menu.php
r41766 r41887 550 550 */ 551 551 function test_wp_delete_customize_changeset_dependent_auto_drafts() { 552 $ nav_created_post_ids = $this->factory()->post->create_many(2,array(552 $auto_draft_post_id = $this->factory()->post->create( array( 553 553 'post_status' => 'auto-draft', 554 554 ) ); 555 $draft_post_id = $this->factory()->post->create( array( 556 'post_status' => 'draft', 557 ) ); 558 $private_post_id = $this->factory()->post->create( array( 559 'post_status' => 'private', 560 ) ); 561 562 $nav_created_post_ids = array( 563 $auto_draft_post_id, 564 $draft_post_id, 565 $private_post_id, 566 ); 555 567 $data = array( 556 568 'nav_menus_created_posts' => array( … … 567 579 'data' => $data, 568 580 ) ); 569 $this->assertInstanceOf( 'WP_Post', get_post( $nav_created_post_ids[0] ) ); 570 $this->assertInstanceOf( 'WP_Post', get_post( $nav_created_post_ids[1] ) ); 581 $this->assertEquals( 'auto-draft', get_post_status( $auto_draft_post_id ) ); 582 $this->assertEquals( 'draft', get_post_status( $draft_post_id ) ); 583 $this->assertEquals( 'private', get_post_status( $private_post_id ) ); 571 584 wp_delete_post( $wp_customize->changeset_post_id(), true ); 572 $this->assertNotInstanceOf( 'WP_Post', get_post( $nav_created_post_ids[0] ) ); 573 $this->assertNotInstanceOf( 'WP_Post', get_post( $nav_created_post_ids[1] ) ); 585 $this->assertFalse( get_post_status( $auto_draft_post_id ) ); 586 $this->assertEquals( 'trash', get_post_status( $draft_post_id ) ); 587 $this->assertEquals( 'private', get_post_status( $private_post_id ) ); 574 588 } 575 589 -
trunk/tests/phpunit/tests/theme.php
r40676 r41887 319 319 $nav_created_post_ids = $this->factory()->post->create_many(2, array( 320 320 'post_status' => 'auto-draft', 321 'post_date' => gmdate( 'Y-m-d H:i:s', strtotime( '-2 days' ) ), 321 322 ) ); 322 323 $data = array( … … 329 330 $wp_customize = new WP_Customize_Manager(); 330 331 do_action( 'customize_register', $wp_customize ); 332 333 // The post_date for auto-drafts is bumped to match the changeset post_date whenever it is modified to keep them from from being garbage collected by wp_delete_auto_drafts(). 331 334 $wp_customize->save_changeset_post( array( 332 335 'data' => $data, … … 334 337 $this->assertEquals( get_post( $nav_created_post_ids[0] )->post_date, get_post( $wp_customize->changeset_post_id() )->post_date ); 335 338 $this->assertEquals( get_post( $nav_created_post_ids[1] )->post_date, get_post( $wp_customize->changeset_post_id() )->post_date ); 339 $this->assertEquals( 'auto-draft', get_post_status( $nav_created_post_ids[0] ) ); 340 $this->assertEquals( 'auto-draft', get_post_status( $nav_created_post_ids[1] ) ); 341 342 // Stubs transition to drafts when changeset is saved as a draft. 336 343 $wp_customize->save_changeset_post( array( 337 344 'status' => 'draft', 338 345 'data' => $data, 339 346 ) ); 340 $expected_year = date( 'Y' ) + 100; 341 $this->assertEquals( $expected_year, date( 'Y', strtotime( get_post( $nav_created_post_ids[0] )->post_date ) ) ); 342 $this->assertEquals( $expected_year, date( 'Y', strtotime( get_post( $nav_created_post_ids[1] )->post_date ) ) ); 347 $this->assertEquals( get_post( $nav_created_post_ids[0] )->post_date, get_post( $wp_customize->changeset_post_id() )->post_date ); 348 $this->assertEquals( get_post( $nav_created_post_ids[1] )->post_date, get_post( $wp_customize->changeset_post_id() )->post_date ); 349 $this->assertEquals( 'draft', get_post_status( $nav_created_post_ids[0] ) ); 350 $this->assertEquals( 'draft', get_post_status( $nav_created_post_ids[1] ) ); 351 352 // Status remains unchanged for stub that the user broke out of the changeset. 353 wp_update_post( array( 354 'ID' => $nav_created_post_ids[1], 355 'post_status' => 'private', 356 ) ); 357 $wp_customize->save_changeset_post( array( 358 'status' => 'draft', 359 'data' => $data, 360 ) ); 361 $this->assertEquals( 'draft', get_post_status( $nav_created_post_ids[0] ) ); 362 $this->assertEquals( 'private', get_post_status( $nav_created_post_ids[1] ) ); 363 364 // Draft stub is trashed when the changeset is trashed. 365 $wp_customize->trash_changeset_post( $wp_customize->changeset_post_id() ); 366 $this->assertEquals( 'trash', get_post_status( $nav_created_post_ids[0] ) ); 367 $this->assertEquals( 'private', get_post_status( $nav_created_post_ids[1] ) ); 343 368 } 344 369 }
Note: See TracChangeset
for help on using the changeset viewer.