Changeset 53883
- Timestamp:
- 08/11/2022 07:58:21 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r53878 r53883 4143 4143 // Filter out empty terms. 4144 4144 $post_category = array_filter( $postarr['post_category'] ); 4145 } elseif ( $update && ! isset( $postarr['post_category'] ) ) { 4146 $post_category = $post_before->post_category; 4145 4147 } 4146 4148 -
trunk/tests/phpunit/tests/post/wpInsertPost.php
r53789 r53883 878 878 879 879 /** 880 * @ticket 19954 881 */ 882 function test_updating_a_post_should_not_trash_categories() { 883 // Create a category and attach it to a new post. 884 $term_id = self::factory()->term->create( 885 array( 886 'name' => 'Term', 887 'taxonomy' => 'category', 888 ) 889 ); 890 891 $post_id = self::factory()->post->create( 892 array( 893 'post_type' => 'post', 894 'post_title' => 'Post with categories', 895 'post_status' => 'publish', 896 'post_category' => array( $term_id ), 897 ) 898 ); 899 900 // Validate that the term got assigned. 901 $assigned_terms = wp_get_object_terms( array( $post_id ), array( 'category' ), array() ); 902 $this->assertCount( 1, $assigned_terms ); 903 $this->assertEquals( $term_id, $assigned_terms[0]->term_id ); 904 905 // Update the post with no changes. 906 $post = get_post( $post_id ); 907 wp_insert_post( $post ); 908 909 // Validate the term is still assigned. 910 $assigned_terms = wp_get_object_terms( array( $post_id ), array( 'category' ), array() ); 911 $this->assertCount( 1, $assigned_terms ); 912 $this->assertEquals( $term_id, $assigned_terms[0]->term_id ); 913 914 // Remove the term from the post. 915 $post->post_category = array(); 916 wp_insert_post( $post ); 917 $assigned_terms = wp_get_object_terms( array( $post_id ), array( 'category' ), array() ); 918 919 // Validate that the post has had the default category assigned again. 920 $this->assertCount( 1, $assigned_terms ); 921 $this->assertEquals( get_option( 'default_category' ), $assigned_terms[0]->term_id ); 922 } 923 924 /** 880 925 * @ticket 48113 881 926 */
Note: See TracChangeset
for help on using the changeset viewer.