10up / distributor

Share content between your websites.
https://distributorplugin.com
GNU General Public License v2.0
632 stars 154 forks source link

Improve/verify handling of post status changes #112

Open adamsilverstein opened 6 years ago

adamsilverstein commented 6 years ago

Updating post status

What happens when a post that has been distributed is published, or changed from published to draft (or moved to the trash)

Opening this issue to discuss the expected behavior when a post that has been distributed has it's post status changed.

Related: https://github.com/10up/distributor/issues/107 & https://github.com/10up/distributor/pull/110 & https://github.com/10up/distributor/pull/159

Expected behavior

After some internal discussion, we have decided that the expected behavior for post status changes is as follows:

Distributing:

Updating:

Deleting

Connections

Remaining Todo after testing

Add a dt_published_posts_distribute_status filter to determine if a posts's status should be distributed along with other post data.

adamsilverstein commented 6 years ago

cc: @tlovett1

tlovett1 commented 6 years ago

@adamsilverstein did #159 solve this?

adamsilverstein commented 6 years ago

Yes, I think this is resolved although I haven't gone back to test. I'll try to to that soon and close.

jeffpaul commented 5 years ago

@adamsilverstein mind re-testing this to see if it can be closed?

jeffpaul commented 5 years ago

@adamsilverstein mind re-testing this to see if it can be closed?

adamsilverstein commented 5 years ago

Testing results

Pushing draft posts is disabled by default.

verified

Pushing drafts can be enabled by returning true from the dt_drafts_can_be_distributed filter. [Update] This was replaced by the distributable_post_statuses filter .

verified filter works as expected, added:

add_filter( 'dt_distributable_post_statuses', function() { return array( 'publish', 'draft' ); } ); and draft was distributable.

When a draft post is distributed, copies will always have a status of draft. The 'As Draft' option is not available when distributing drafts (showing it would be confusing).

verified this

When a published post is distributed, copies will have a status of draft if the 'As Draft' checkbox is left checked, or 'publish' if it is unchecked.

Verified.

Updating:

When an origin published post is updated (or a draft published), no change is made to the status of distributed copies.This behavior can be overwritten by returning true from the (not yet implemented) dt_published_posts_distribute_status filter.

verified no change in remote status. don't see dt_published_posts_distribute_status

_it might be possible to achieve this with the dt_push_post_args filter._

If the dt_published_posts_distribute_status is set to true and an origin post status is changed from publish to any other status (a "takedown"), or any non published post is updated, the statuses of distributed copies are updated to match. Status could be trash, private, draft, autodraft, future, pending, etc.

not in place as far as I can tell.

Deleting

When an origin post is deleted, remote posts are unlinked and the editor shows a warning message: This post was distributed from [SITENAME]. However, the original has been deleted.

verified. post also becomes unlinked (editable)

Results

The one thing missing is a dt_published_posts_distribute_status filter to determine if a posts's status should be distributed.

adamsilverstein commented 5 years ago

I started work on addressing the final issue here in https://github.com/10up/distributor/pull/446

TangramWerbeagentur commented 3 years ago

I found a simple workaround to automatically trash posts on the receiving site that were trashed on the pushing site. It's possible since the permalink does update to "__trashed" correctly, just the post status doesn't. With this added to the receiving site's functions.php it does:

$args = array(
  'post_type' => array('post'), // post types you want to check
  'posts_per_page' => -1
);
$posts = get_posts($args);

foreach($posts as $p){

  $expiredlink = get_permalink( $p->ID );

  if(strpos($expiredlink, "__trashed") !== false) {
    $postdata = array(
      'ID' => $p->ID,
      'post_status' => 'trash'
    );
    wp_update_post($postdata);
  }
}
jeffpaul commented 3 years ago

Thanks for this @TangramWerbeagentur! We're working to document and think through the various implications this has, especially as this inter-relates to distributing "as draft", to ensure we're considering all use cases and not negatively impacting a current use case with a PR on this topic.