-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: trunk
Are you sure you want to change the base?
Conversation
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 refactoring the approach to fit the new partial payload implementation!
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?
@@ -47,7 +49,7 @@ public static function init() { | |||
} | |||
|
|||
add_action( 'init', [ __CLASS__, 'register_data_event_actions' ] ); | |||
add_action( 'shutdown', [ __CLASS__, 'distribute_queued_posts' ] ); | |||
add_action( 'shutdown', [ __CLASS__, 'distribute_queued_posts' ], 20 ); |
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.
Any reason for the change in priority?
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.
No, I think that is a relic from when I was trying to game the timing of things. :) I removed it
* @param int $post_id The post ID. | ||
* @param bool $is_linked Whether the post is linked. | ||
* @param array $payload The post payload. | ||
* @param int $post_id The post ID. | ||
* @param bool $is_linked Whether the post is linked. | ||
* @param array $payload The post payload. |
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.
Why this change in linting?
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.
It was probably just my editor when it autoformats. There are too many spaces I think it picked up?
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.
It follows the standard we use for functions and methods so the parameters info is aligned. It could be that your IDE doesn't interpret the do_action()
as a thing that can precede that type of docblock.
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.
You are right! I had the editor set to not WP for some reason and it felt like I had to keep tweaking it :)
return [ | ||
'site_url' => get_bloginfo( 'url' ), | ||
'post_id' => $this->post->ID, | ||
'post_url' => get_permalink( $this->post->ID ), | ||
'network_post_id' => $this->get_network_post_id(), | ||
'sites' => $this->get_distribution(), | ||
'status_on_create' => $status_on_create, | ||
'multiple_authors' => is_wp_error( $multiple_authors ) ? [] : $multiple_authors, |
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.
Partial payload filters through the contents of post_data
. This should move there in order to work as designed.
As it is now, at the root-level, it'll be always part of the payload. It works, but not how we expect it to.
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.
👍 Moved it to post_data
* | ||
* @return WP_Error|array | ||
*/ | ||
public static function get_wp_user_for_distribution( $user ) { |
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.
I don't think we need a whole class for this. WDYT of moving this to the Outgoing_Post
class?
It's similar to other methods we have there that are meant to build the payload, like get_processed_post_content()
, get_post_taxonomy_terms()
, and get_post_meta()
.
/** | ||
* Class to handle author ingestion for content distribution. | ||
*/ | ||
class Incoming_Author { |
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.
I also think this class could become methods inside Incoming_Post
.
return new WP_Error( 'insert_error', __( 'Error inserting post.', 'newspack-network' ) ); | ||
} | ||
|
||
// Update the object. | ||
$this->ID = $post_id; | ||
$this->post = get_post( $this->ID ); | ||
|
||
Incoming_Author::ingest_author_for_post( $this->ID, $this->get_original_site_url(), $post_data['author'] ); |
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 method makes a second post update to the db. Can we dissolve it and move its logic upper in this method's $postarr
arguments?
Regular WP author is a core aspect of the post and should fit well in the composition of our insert() logic.
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.
Makes sense! thanks :)
@@ -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.
Can you share more about the use case for this filter? It's missing a docblock.
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.
It was an attempt to make it so other implementations of multiple authors (like other than the CAP plugin) could chime in. I'm missing an equivalent on incoming – I'll add that and add those in-function docblocks
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.
I also added a filter for incoming "mulitple_authors", so any implementation could hook in in both directions.
Co-authored-by: Miguel Peixe <[email protected]>
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. |
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: