Changeset 7600
- Timestamp:
- 09/19/2026 12:08:11 AM (3 days ago)
- Location:
- branches/2.6
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.6/src/includes/admin/classes/class-bbp-converter-base.php
r7598 r7600 635 635 636 636 default : 637 $post_id = wp_insert_post( $insert_post, true);637 $post_id = $this->insert_post( $insert_post ); 638 638 639 639 if ( is_numeric( $post_id ) ) { … … 693 693 694 694 /** 695 * Insert a converted post without changing imported counts. 696 * 697 * Converter field maps include the source forum and topic counts. Prevent 698 * post-status transition callbacks from incrementing those counts again as 699 * each converted topic and reply is inserted. 700 * 701 * @since 2.6.18 702 * 703 * @param array $post_data Converted post data. 704 * @return int|WP_Error Post ID on success, WP_Error on failure. 705 */ 706 protected function insert_post( $post_data = array() ) { 707 $suppress_count_updates = function () { 708 return false; 709 }; 710 711 add_filter( 'bbp_pre_update_counts_on_transition_post_status', $suppress_count_updates ); 712 713 try { 714 $post_id = wp_insert_post( $post_data, true ); 715 } finally { 716 remove_filter( 'bbp_pre_update_counts_on_transition_post_status', $suppress_count_updates ); 717 } 718 719 return $post_id; 720 } 721 722 /** 695 723 * This method converts old forum hierarchy to new bbPress hierarchy. 696 724 */ -
branches/2.6/tests/phpunit/testcases/admin/converters/base.php
r7588 r7600 22 22 public function get_pass_array( $value ) { 23 23 return $this->unserialize_pass( $value ); 24 } 25 26 public function insert_converted_post( $post_data ) { 27 return $this->insert_post( $post_data ); 24 28 } 25 29 } … … 67 71 68 72 /** 73 * @covers BBP_Converter_Base::insert_post 74 * @ticket BBP3686 75 */ 76 public function test_insert_post_does_not_increment_imported_counts() { 77 $converter = new BBP_Tests_Admin_Converters_Base_Converter(); 78 $forum_id = $this->factory->forum->create(); 79 80 update_post_meta( $forum_id, '_bbp_topic_count', 4 ); 81 82 $topic_id = $converter->insert_converted_post( 83 array( 84 'post_type' => bbp_get_topic_post_type(), 85 'post_status' => bbp_get_public_status_id(), 86 'post_parent' => $forum_id, 87 'post_title' => 'Converted topic', 88 ) 89 ); 90 91 $this->assertIsInt( $topic_id ); 92 $this->assertSame( 4, bbp_get_forum_topic_count( $forum_id, false, true ) ); 93 $this->assertNull( apply_filters( 'bbp_pre_update_counts_on_transition_post_status', null, 'publish', 'new', get_post( $topic_id ) ) ); 94 } 95 96 /** 69 97 * @covers BBP_Converter_Base::unserialize_pass 70 98 * @ticket BBP3684
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)