Changeset 61372
- Timestamp:
- 12/12/2025 05:06:16 AM (less than one hour ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
src/wp-includes/revision.php (modified) (1 diff)
-
tests/phpunit/tests/post/revisions.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/revision.php
r59715 r61372 188 188 189 189 foreach ( array_keys( _wp_post_revision_fields( $post ) ) as $field ) { 190 if ( normalize_whitespace( $post->$field ) !== normalize_whitespace( $latest_revision->$field) ) {190 if ( normalize_whitespace( maybe_serialize( $post->$field ) ) !== normalize_whitespace( maybe_serialize( $latest_revision->$field ) ) ) { 191 191 $post_has_changed = true; 192 192 break; -
trunk/tests/phpunit/tests/post/revisions.php
r60251 r61372 931 931 ); 932 932 } 933 934 /** 935 * @ticket 64314 936 * @covers ::wp_save_post_revision 937 */ 938 public function test_wp_save_post_revision_with_array_post_meta() { 939 // This filter is true by default, but this is explicitly to test looking for differences among non-scalar fields. 940 add_filter( 'wp_save_post_revision_check_for_changes', '__return_true' ); 941 942 $post_id = self::factory()->post->create(); 943 $meta_key = 'favorite_things'; 944 945 // Ensure the post meta is saved with each revision. 946 add_filter( 947 'wp_post_revision_meta_keys', 948 static function ( $meta_keys ) use ( $meta_key ) { 949 $meta_keys[] = $meta_key; 950 return $meta_keys; 951 } 952 ); 953 954 // Ensure the post meta are used when determining whether a revision should be saved. 955 add_filter( 956 '_wp_post_revision_fields', 957 static function ( $fields ) use ( $meta_key ) { 958 $fields[ $meta_key ] = 'Favorite Things'; 959 return $fields; 960 } 961 ); 962 963 // Set initial value. 964 $initial_favorites = array( 965 'raindrops on roses', 966 'whiskers on kittens', 967 'bright copper kettles', 968 ); 969 update_post_meta( $post_id, $meta_key, $initial_favorites ); 970 971 // Save the first revision. 972 $revision_id_1 = wp_save_post_revision( $post_id ); 973 $this->assertIsInt( $revision_id_1, 'Expected first revision to be created.' ); 974 $this->assertCount( 1, wp_get_post_revisions( $post_id ), 'First revision should be created.' ); 975 $this->assertSame( $initial_favorites, get_post_meta( $revision_id_1, $meta_key, true ), 'Expected first revision post meta to have the initial value.' ); 976 977 // Save the second revision. 978 $updated_favorites = array_merge( 979 $initial_favorites, 980 array( 981 'warm woolen mittens', 982 'crisp apple strudels', 983 'brown paper packages tied up with strings', 984 ) 985 ); 986 update_post_meta( $post_id, $meta_key, $updated_favorites ); 987 $revision_id_2 = wp_save_post_revision( $post_id ); 988 $this->assertIsInt( $revision_id_2, 'Expected second revision to be created.' ); 989 $this->assertCount( 2, wp_get_post_revisions( $post_id ), 'Second revision should be created after array field change.' ); 990 $this->assertSame( $updated_favorites, get_post_meta( $revision_id_2, $meta_key, true ), 'Expected second revision post meta to have the updated value.' ); 991 } 933 992 }
Note: See TracChangeset
for help on using the changeset viewer.