Ticket #3433: 3433.01.patch
File 3433.01.patch, 3.4 KB (added by , 23 months ago) |
---|
-
src/includes/common/functions.php
271 271 return (int) apply_filters( 'bbp_get_trash_days', $days, $context ); 272 272 } 273 273 274 /** 275 * Use the previous status when restoring a topic or reply. 276 * 277 * Fixes an issue since WordPress 5.6.0. See 278 * {@link https://bbpress.trac.wordpress.org/ticket/3433}. 279 * 280 * @since 2.6.x bbPress (rXXX) 281 * 282 * @param string $retval Current status to use when untrashing. Default: 'draft' 283 * @param int $post_id Post ID 284 * @param string $previous_status Previous post status from '_wp_trash_meta_status' meta key. 285 */ 286 function bbp_use_previous_status_for_untrash( $retval, $post_id, $previous_status ) { 287 if ( ! bbp_is_topic( $post_id ) && ! bbp_is_reply( $post_id ) ) { 288 return $retval; 289 } 290 291 if ( ! empty( $previous_status ) ) { 292 return $previous_status; 293 } else { 294 return $retval; 295 } 296 } 297 274 298 /** Statistics ****************************************************************/ 275 299 276 300 /** -
src/includes/core/filters.php
52 52 // Fix post author id for anonymous posts (set it back to 0) when the post status is changed 53 53 add_filter( 'wp_insert_post_data', 'bbp_fix_post_author', 30, 2 ); 54 54 55 // Fix untrash status after a topic or reply is re-instated 56 add_filter( 'wp_untrash_post_status', 'bbp_use_previous_status_for_untrash', 10, 3 ); 57 55 58 // Force comments_status on bbPress post types 56 59 add_filter( 'comments_open', 'bbp_force_comment_status' ); 57 60 -
tests/phpunit/testcases/topics/functions/topic.php
423 423 424 424 /** 425 425 * @covers ::bbp_untrash_topic 426 * @todo Implement test_bbp_untrash_topic().427 426 */ 428 427 public function test_bbp_untrash_topic() { 429 // Remove the following lines when you implement this test. 430 $this->markTestIncomplete( 431 'This test has not been implemented yet.' 432 ); 428 $f = $this->factory->forum->create(); 429 $t = $this->factory->topic->create( array( 430 'post_parent' => $f, 431 'topic_meta' => array( 432 'forum_id' => $f, 433 ), 434 ) ); 435 436 wp_trash_post( $t ); 437 438 wp_untrash_post( $t ); 439 440 $this->assertTrue( 'publish' === get_post_status( $t ) ); 433 441 } 434 442 435 443 /** 436 444 * @covers ::bbp_untrash_topic_replies 437 * @todo Implement test_bbp_untrash_topic_replies().438 445 */ 439 446 public function test_bbp_untrash_topic_replies() { 440 // Remove the following lines when you implement this test. 441 $this->markTestIncomplete( 442 'This test has not been implemented yet.' 443 ); 447 $f = $this->factory->forum->create(); 448 $t = $this->factory->topic->create( array( 449 'post_parent' => $f, 450 'topic_meta' => array( 451 'forum_id' => $f, 452 ), 453 ) ); 454 $r = $this->factory->reply->create_many( 2, array( 455 'post_parent' => $t, 456 'reply_meta' => array( 457 'forum_id' => $f, 458 'topic_id' => $t, 459 ), 460 ) ); 461 462 wp_trash_post( $t ); 463 464 wp_untrash_post( $t ); 465 466 $expected = []; 467 $expected[] = get_post_status( $r[0] ); 468 $expected[] = get_post_status( $r[1] ); 469 470 $this->assertSame( [ 'publish', 'publish' ], $expected ); 444 471 } 445 472 446 473 /**