diff --git a/includes/content-distribution/class-incoming-post.php b/includes/content-distribution/class-incoming-post.php index cb9f002e..dda3ccbc 100644 --- a/includes/content-distribution/class-incoming-post.php +++ b/includes/content-distribution/class-incoming-post.php @@ -414,15 +414,17 @@ public function insert( $payload = [] ) { } $postarr = [ - 'ID' => $this->ID, - 'post_date_gmt' => $post_data['date_gmt'], - 'post_title' => $post_data['title'], - 'post_name' => $post_data['slug'], - 'post_content' => use_block_editor_for_post_type( $post_type ) ? + 'ID' => $this->ID, + 'post_date_gmt' => $post_data['date_gmt'], + 'post_title' => $post_data['title'], + 'post_name' => $post_data['slug'], + 'post_content' => use_block_editor_for_post_type( $post_type ) ? $post_data['raw_content'] : $post_data['content'], - 'post_excerpt' => $post_data['excerpt'], - 'post_type' => $post_type, + 'post_excerpt' => $post_data['excerpt'], + 'post_type' => $post_type, + 'comment_status' => $post_data['comment_status'], + 'ping_status' => $post_data['ping_status'], ]; // The default status for a new post is 'draft'. diff --git a/includes/content-distribution/class-outgoing-post.php b/includes/content-distribution/class-outgoing-post.php index 55e649fa..40e253ba 100644 --- a/includes/content-distribution/class-outgoing-post.php +++ b/includes/content-distribution/class-outgoing-post.php @@ -185,18 +185,20 @@ public function get_payload() { 'network_post_id' => $this->get_network_post_id(), 'sites' => $this->get_distribution(), 'post_data' => [ - 'title' => html_entity_decode( get_the_title( $this->post->ID ), ENT_QUOTES, get_bloginfo( 'charset' ) ), - 'post_status' => $this->post->post_status, - 'date_gmt' => $this->post->post_date_gmt, - 'modified_gmt' => $this->post->post_modified_gmt, - 'slug' => $this->post->post_name, - 'post_type' => $this->post->post_type, - 'raw_content' => $this->post->post_content, - 'content' => $this->get_processed_post_content(), - 'excerpt' => $this->post->post_excerpt, - 'taxonomy' => $this->get_post_taxonomy_terms(), - 'thumbnail_url' => get_the_post_thumbnail_url( $this->post->ID, 'full' ), - 'post_meta' => $this->get_post_meta(), + 'title' => html_entity_decode( get_the_title( $this->post->ID ), ENT_QUOTES, get_bloginfo( 'charset' ) ), + 'post_status' => $this->post->post_status, + 'date_gmt' => $this->post->post_date_gmt, + 'modified_gmt' => $this->post->post_modified_gmt, + 'slug' => $this->post->post_name, + 'post_type' => $this->post->post_type, + 'raw_content' => $this->post->post_content, + 'content' => $this->get_processed_post_content(), + 'excerpt' => $this->post->post_excerpt, + 'comment_status' => $this->post->comment_status, + 'ping_status' => $this->post->ping_status, + 'taxonomy' => $this->get_post_taxonomy_terms(), + 'thumbnail_url' => get_the_post_thumbnail_url( $this->post->ID, 'full' ), + 'post_meta' => $this->get_post_meta(), ], ]; } diff --git a/tests/unit-tests/content-distribution/test-incoming-post.php b/tests/unit-tests/content-distribution/test-incoming-post.php index 27ad1bce..708c6f97 100644 --- a/tests/unit-tests/content-distribution/test-incoming-post.php +++ b/tests/unit-tests/content-distribution/test-incoming-post.php @@ -413,4 +413,29 @@ public function test_reserved_taxonomies() { $terms = wp_get_post_terms( $post_id, $taxonomy ); $this->assertEmpty( $terms ); } + + /** + * Test comment and ping statuses. + */ + public function test_comment_and_ping_statuses() { + $payload = $this->get_sample_payload(); + + // Insert the linked post with comment and ping statuses. + $post_id = $this->incoming_post->insert( $payload ); + + // Assert that the post has the comment and ping statuses. + $this->assertSame( 'open', get_post_field( 'comment_status', $post_id ) ); + $this->assertSame( 'open', get_post_field( 'ping_status', $post_id ) ); + + // Update the comment and ping statuses. + $payload['post_data']['comment_status'] = 'closed'; + $payload['post_data']['ping_status'] = 'closed'; + + // Insert the updated linked post. + $this->incoming_post->insert( $payload ); + + // Assert that the post has the updated comment and ping statuses. + $this->assertSame( 'closed', get_post_field( 'comment_status', $post_id ) ); + $this->assertSame( 'closed', get_post_field( 'ping_status', $post_id ) ); + } } diff --git a/tests/unit-tests/content-distribution/test-outgoing-post.php b/tests/unit-tests/content-distribution/test-outgoing-post.php index 0e58f57b..6ca81296 100644 --- a/tests/unit-tests/content-distribution/test-outgoing-post.php +++ b/tests/unit-tests/content-distribution/test-outgoing-post.php @@ -143,6 +143,8 @@ public function test_get_payload() { 'raw_content', 'content', 'excerpt', + 'comment_status', + 'ping_status', 'thumbnail_url', 'taxonomy', 'post_meta', diff --git a/tests/unit-tests/content-distribution/util.php b/tests/unit-tests/content-distribution/util.php index f145a190..5b2806b5 100644 --- a/tests/unit-tests/content-distribution/util.php +++ b/tests/unit-tests/content-distribution/util.php @@ -29,17 +29,19 @@ function get_sample_payload( $origin = '', $destination = '' ) { 'network_post_id' => '1234567890abcdef1234567890abcdef', 'sites' => [ $destination ], 'post_data' => [ - 'title' => 'Title', - 'post_status' => 'publish', - 'date_gmt' => '2021-01-01 00:00:00', - 'modified_gmt' => '2021-01-01 00:00:00', - 'slug' => 'slug', - 'post_type' => 'post', - 'raw_content' => 'Content', - 'content' => '
Content
', - 'excerpt' => 'Excerpt', - 'thumbnail_url' => 'https://picsum.photos/id/1/300/300.jpg', - 'taxonomy' => [ + 'title' => 'Title', + 'post_status' => 'publish', + 'date_gmt' => '2021-01-01 00:00:00', + 'modified_gmt' => '2021-01-01 00:00:00', + 'slug' => 'slug', + 'post_type' => 'post', + 'raw_content' => 'Content', + 'content' => 'Content
', + 'excerpt' => 'Excerpt', + 'thumbnail_url' => 'https://picsum.photos/id/1/300/300.jpg', + 'comment_status' => 'open', + 'ping_status' => 'open', + 'taxonomy' => [ 'category' => [ [ 'name' => 'Category 1', @@ -61,7 +63,7 @@ function get_sample_payload( $origin = '', $destination = '' ) { ], ], ], - 'post_meta' => [ + 'post_meta' => [ 'single' => [ 'value' ], 'array' => [ [ 'a' => 'b', 'c' => 'd' ] ], // phpcs:ignore WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound 'multiple' => [ 'value 1', 'value 2' ],