10up / distributor

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

Ensure author ID is correctly set. #1133

Closed peterwilsoncc closed 1 year ago

peterwilsoncc commented 1 year ago

Description of the Change

In block themes an invalid author ID (such as zero) prevents the filter running on the author name due to some code in the post author block.

This modifies the check for an invalid author ID when pulling/pushing posts to ensure that a valid ID is used.

When pulling from an external post, this removes the author ID of the remove user and records the post as authored by the user pulling the post. Author IDs almost certainly do not match across external connections so there is a risk the author is being assigned to a user that ought not be able to edit the post.

Closes #1129

How to test the Change

  1. Install Distributor on a network
  2. Activate the 2023 theme if required
  3. Create a sub-site
  4. Use WPCLI to generate posts on the main site wp post generate --count=10 -- this will generate posts with the author 0
  5. On the sub-site, uncheck "pull as draft" pull one of the generated posts
  6. Once the post has been pulled, click view for the post
  7. The author block should correctly show the source site on the front end.

Changelog Entry

Fixed - Invalid author IDs being set when pushing and pulling posts.

Credits

Props @peterwilsoncc

Checklist: