-
Notifications
You must be signed in to change notification settings - Fork 4
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 authors #194
Conversation
Thanks for the review @miguelpeixe I implemented your suggestions. If you think the whole hooks thing for multiple authors is over engineering things, let me know and I can change them to function calls. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the revisions, @naxoc! It's looking great.
Maybe you missed this bit from my previous review:
I'm able to get multiple authors synced, but with the standard guest author approach from CAP I'm unable to get the guest authors distributed.
I'm activating it via define( 'NEWSPACK_ENABLE_CAP_GUEST_AUTHORS', true ); on all sites. Should I be doing something different?
I'm still unable to get it to work. The payload does include the data, though:
{
"site_url": "http:\/\/localhost",
"post_id": 827,
"post_url": "http:\/\/localhost\/2025\/01\/my-new-cap-post\/",
"network_post_id": "6dc7943077f7903f656015af0ebb029e",
"sites": [
"http:\/\/node1.test"
],
"status_on_create": "draft",
"post_data": {
"multiple_authors": [
{
"type": "wp_user",
"ID": 1,
"display_name": "wordpress",
"user_email": "[email protected]",
"user_url": "http:\/\/localhost"
},
{
"ID": "825",
"display_name": "My CAP Guest Author",
"first_name": "",
"last_name": "",
"user_login": "my-cap-guest-author",
"user_email": "[email protected]",
"linked_account": "",
"website": "",
"description": "",
"newspack_job_title": "",
"newspack_role": "",
"newspack_employer": "",
"newspack_phone_number": "",
"user_nicename": "my-cap-guest-author",
"type": "guest_author",
"nickname": ""
},
{
"type": "wp_user",
"ID": 2,
"display_name": "Contributor",
"user_email": "[email protected]",
"first_name": "Contributor",
"last_name": "Contributor"
}
],
"date_gmt": "2025-01-30 17:37:01",
"modified_gmt": "2025-01-30 17:39:22"
},
"partial": true
}
* Action callback. | ||
* | ||
* Add a postmeta entry with the Co-Authors Plus authors for outgoing posts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This docblock needs an update.
@@ -202,15 +202,20 @@ public function get_payload_hash( $payload = null ) { | |||
* @return array|WP_Error The post payload or WP_Error if the post is invalid. | |||
*/ | |||
public function get_payload( $status_on_create = 'draft' ) { | |||
$post_author = $this->post->post_author ? Outgoing_Author::get_wp_user_for_distribution( $this->post->post_author ) : []; | |||
$multiple_authors = apply_filters( 'newspack_network_multiple_authors_for_post', [], $this->post ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. I didn't realize that's how the CAP data is being added to the payload.
Non-blocking suggestion: maybe instead of filtering this specific property we can go with a more generic approach and filter the payload post_data
to let additional features determine their properties. That'll also generate a cleaner payload for sites that don't have CAP at all - no permanent empty array.
Woops. I didn't click comment on this one:
I copied the behavior from the existing code that handles guest authors It would be great to also have it work in admin – at least in the posts listing 🤔 It works for me. They only show on the front end, so might that have been it? Let me know if the front end is not showing them for you. |
Thank you Miguel – I love the idea of filtering the whole post_data part instead. I'll add that tomorrow 👍 |
OK, @miguelpeixe I added the payload filtering. That is a great idea – it makes everything much more readable and extendable. Ready for re-review :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @naxoc! Looks good and tests well 💯
One small ✂️ and we're good to go!
Co-authored-by: Miguel Peixe <[email protected]>
Hey @naxoc, good job getting this PR merged! 🎉 Now, the Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label. If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label. Thank you! ❤️ |
# [2.6.0-alpha.1](v2.5.0...v2.6.0-alpha.1) (2025-02-07) ### Bug Fixes * **content-distribution:** use payload hash on partial updates ([#207](#207)) ([31b342d](31b342d)) * **event-log:** data css overflow ([#206](#206)) ([f81adfe](f81adfe)) ### Features * **content-distribution:** migration tweaks ([#201](#201)) ([9c61fa8](9c61fa8)) * **content-distribution:** partial payload ([#205](#205)) ([b844d06](b844d06)) * **content-distribution:** remove "Quick Edit" from linked posts ([#200](#200)) ([6ad3a4a](6ad3a4a)) * **content-distribution:** Sync authors ([#194](#194)) ([3156d35](3156d35)) * increase pull frequency and amount ([#209](#209)) ([6791da1](6791da1))
🎉 This PR is included in version 2.6.0-alpha.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
# [2.6.0](v2.5.0...v2.6.0) (2025-02-17) ### Bug Fixes * **content-distribution:** use payload hash on partial updates ([#207](#207)) ([31b342d](31b342d)) * **event-log:** data css overflow ([#206](#206)) ([f81adfe](f81adfe)) ### Features * **content-distribution:** migration tweaks ([#201](#201)) ([9c61fa8](9c61fa8)) * **content-distribution:** partial payload ([#205](#205)) ([b844d06](b844d06)) * **content-distribution:** remove "Quick Edit" from linked posts ([#200](#200)) ([6ad3a4a](6ad3a4a)) * **content-distribution:** Sync authors ([#194](#194)) ([3156d35](3156d35)) * increase pull frequency and amount ([#209](#209)) ([6791da1](6791da1))
🎉 This PR is included in version 2.6.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This copies most of the existing code for distributed post authors.
I tried to make the naming of classes make a bit more sense (using outgoing/incoming) naming-wise, but I think I might have lost my way somewhere in the process. It's still pretty unwieldy. Suggestions very welcome!
One thing I still lack: when a post is new and I click "publish" and then distribute it (without having touched authors), the cap authors are not added to the payload. I think the best way to fix that is to save the post from JS before distributing the first time. What do you think @miguelpeixe ?
How to test
Still remains: