-
Notifications
You must be signed in to change notification settings - Fork 2
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/distribute authors #17
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.
if ( is_a( $co_author, 'WP_User' ) ) { | ||
$authors[] = self::get_wp_user_for_distribution( $co_author ); | ||
} | ||
$authors[] = self::get_guest_author_for_distribution( $co_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.
Shouldn't line 99 be inside an else
block? If $co_author
is a user, it's being added twice (through the wp_user and guest methods).
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.
Done in df7f3d8
} | ||
|
||
if ( ! $user ) { | ||
return []; |
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 not use WP_Error
here for improved debugging?
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.
Mainly because all this happens as side effects in the background and we don't have any opportunity to surface these errors to the user. How would you debug it?
But yes, I guess we could return a wp_error there... but then we need more lines in the method that call this to check what has been returned
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.
Not really seeing a benefit of returning a WP_Error, but added some debugging on 2e26d03
public static function get_guest_author_for_distribution( $guest_author ) { | ||
|
||
if ( ! is_object( $guest_author ) || ! isset( $guest_author->type ) || 'guest-author' !== $guest_author->type ) { | ||
return []; |
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.
Same for debugging, a WP_Error
could be good here.
|
||
Debugger::log( 'Ingesting author: ' . $author['user_email'] ); | ||
|
||
$user = User_Utils::get_or_create_user_by_email( $author['user_email'], get_post_meta( $post_id, 'dt_original_site_url', true ), $author['id'] ); |
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 is a bit confusing. Is the 3rd argument meant to be the author ID or the site ID?
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.
The author id. Why confusing? When we create a user that has been propagated by another site we store their original ID
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.
Because according to the code inline docs:
@param string $remote_site_id The ID of the remote site. Used only when a new user is created.
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'll fix the docs. It should be The id ON the remote site... I'll make it clearer
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.
Done in 92c6b32
includes/distributor-customizations/class-author-distribution.php
Outdated
Show resolved
Hide resolved
Co-authored-by: Miguel Peixe <miguel.peixe@automattic.com>
Co-authored-by: Miguel Peixe <miguel.peixe@automattic.com>
Co-authored-by: Miguel Peixe <miguel.peixe@automattic.com>
Co-authored-by: Miguel Peixe <miguel.peixe@automattic.com>
Good catch! Fixed in b529b36. |
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!
includes/distributor-customizations/class-author-distribution.php
Outdated
Show resolved
Hide resolved
Co-authored-by: Miguel Peixe <miguel.peixe@automattic.com>
🎉 This PR is included in version 1.0.0-alpha.2 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 1.0.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Distributes authors upon post distribution via the Distributor plugin
When a post is distributed via Distributor, all the authors (and co-authors if CAP is enabled) information will be attached to the post.
In the site where the post was distributed to, the authorship information will be stored in a post meta, and later will be used to override the bylines of the posts.
Also in the target site, every author that is a WP user in the origin site, will be created as an
author
if an user with that email yet doesn't exist. Then the post authorship will be assigned to the distributed authors, in the same way they are in the origin site.Guest Authors will not be created and the authorship will not be established. Information about Guest Authors will only exist in the post_meta, and will be used to filter the byline on the fly (in a future PR).
How to test
newspack_network_authors
post_meta and see all authors are there, including the guest author