Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(content-distribution): sync comment and ping statuses #179

Merged
merged 15 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions includes/content-distribution/class-incoming-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
Expand Down
26 changes: 14 additions & 12 deletions includes/content-distribution/class-outgoing-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
],
];
}
Expand Down
25 changes: 25 additions & 0 deletions tests/unit-tests/content-distribution/test-incoming-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ public function test_get_payload() {
'raw_content',
'content',
'excerpt',
'comment_status',
'ping_status',
'thumbnail_url',
'taxonomy',
'post_meta',
Expand Down
26 changes: 14 additions & 12 deletions tests/unit-tests/content-distribution/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '<p>Content</p>',
'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' => '<p>Content</p>',
'excerpt' => 'Excerpt',
'thumbnail_url' => 'https://picsum.photos/id/1/300/300.jpg',
'comment_status' => 'open',
'ping_status' => 'open',
'taxonomy' => [
'category' => [
[
'name' => 'Category 1',
Expand All @@ -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' ],
Expand Down
Loading