| | 217 | * @ticket 44786 |
| | 218 | */ |
| | 219 | function test_revision_block_revision_for_autosave() { |
| | 220 | add_filter( 'wp_save_post_block_revision_for_autosave', '__return_false' ); |
| | 221 | $post = get_default_post_to_edit( 'post', true ); |
| | 222 | remove_filter( 'wp_save_post_block_revision_for_autosave', '__return_false' ); |
| | 223 | |
| | 224 | $post_id = $post->ID; |
| | 225 | |
| | 226 | $this->assertCount( 0, wp_get_post_revisions( $post_id ), 'There should be no revisions on auto-draft creation.' ); |
| | 227 | |
| | 228 | $filter_false_and_check_post_id = function( $autosave, $_post_id ) use ( $post_id ) { |
| | 229 | $this->assertSame( $post_id, $_post_id, 'post_id in the filtering function does not match.' ); |
| | 230 | return false; |
| | 231 | }; |
| | 232 | |
| | 233 | add_filter( 'wp_save_post_block_revision_for_autosave', $filter_false_and_check_post_id, 10, 2 ); |
| | 234 | |
| | 235 | wp_update_post( |
| | 236 | array( |
| | 237 | 'post_status' => 'draft', |
| | 238 | 'post_title' => 'some-post', |
| | 239 | 'post_type' => 'post', |
| | 240 | 'post_content' => 'some_content', |
| | 241 | 'ID' => $post_id, |
| | 242 | ) |
| | 243 | ); |
| | 244 | |
| | 245 | $this->assertCount( 1, wp_get_post_revisions( $post_id ), 'Revision count should be 1 after an update.' ); |
| | 246 | |
| | 247 | wp_update_post( |
| | 248 | array( |
| | 249 | 'post_content' => 'some updated content', |
| | 250 | 'ID' => $post_id, |
| | 251 | ) |
| | 252 | ); |
| | 253 | $this->assertCount( 2, wp_get_post_revisions( $post_id ), 'Revision count should be 2 after another update.' ); |
| | 254 | |
| | 255 | remove_filter( 'wp_save_post_block_revision_for_autosave', $filter_false_and_check_post_id ); |
| | 256 | |
| | 257 | add_filter( 'wp_save_post_block_revision_for_autosave', '__return_true' ); |
| | 258 | wp_update_post( |
| | 259 | array( |
| | 260 | 'post_content' => 'new update for some updated content', |
| | 261 | 'ID' => $post_id, |
| | 262 | ) |
| | 263 | ); |
| | 264 | remove_filter( 'wp_save_post_block_revision_for_autosave', '__return_true' ); |
| | 265 | |
| | 266 | $this->assertCount( 2, wp_get_post_revisions( $post_id ), 'Revision count should still be 2 after another update with blocking re-enabled.' ); |
| | 267 | } |
| | 268 | |
| | 269 | /** |