-
Notifications
You must be signed in to change notification settings - Fork 49
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: reader registration on donate #1655
Conversation
@miguelpeixe Depending on what is the next/roadmap for reader revenue, shall there be an option to change title of button from donate. |
Hi, @yogeshbeniwal! I don't think we have that in our roadmap. I like that suggestion, do you mind filing an issue so we can have a dedicated place for this discussion? |
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.
Some stuff to iron out, but for the general approach is good!
Unfortunately [login form] hook is not applied to the WooCommerce's My Account page login form.
Is there no WooCommerce hook that could be used here?
} else { | ||
Logger::log( 'This order will result in a membership, creating account for user.' ); | ||
$user_login = sanitize_title( $full_name ); | ||
$user_id = wc_create_new_customer( $email_address, $user_login, '', [ 'display_name' => $full_name ] ); |
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 user creation is duplicated – here and in the Reader Activation module. The module should expose a method for handling user creation, and the is_enabled
only used for the reader-activation-flow specific tasks: currently adding the meta fields. Or, the user creation should be delegated to the main Newspack
class.
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 wouldn't call duplicated, the original intended behavior is preserved while reader activation is experimental.
WP core already provides a straightforward API for generic user creation that should be used if not making use of reader activation logic. I don't see why reader activation would provide methods outside of its concept.
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 was thinking about a method that would either wp_insert_user
or wc_create_new_customer
– but on a second thought it should not be used here because at this point we only wanna handle customer creation, not user creation. I was overthinking it.
Still, I think it'd be more readable if Reader_Activation
- in this code block - only set metadata on the created user, not take over the user creation and flow. Something like:
$user_id = wc_create_new_customer …
if ( Reader_Activation::is_enabled() ) {
Reader_Activation::setup_reader( $user_id );
}
wp_set_current_user …
But it's not a blocker.
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.
A "reader" is a fairly flexible concept:
Currently any subscriber or customer is eligible to use the reader-related tools, including register_reader( $email )
. What happens when we call setup_reader( $user_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.
To clarify on why we have the user meta to also determine the same thing: the user roles that determine a reader are filterable. If by any chance this is filtered to an empty array, we must still be able to know readers that were created through this flow.
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.
What happens when we call setup_reader( $user_id )?
The meta fields are set up. Actually, it can be register_reader
– it can be called with an existing user 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.
That's an interesting idea, we should probably do it in a separate method to not necessarily trigger all the side effects of a reader registration if we just want to set the user as a reader.
If you don't mind, I think we could work on that on a separate PR, once we have more practical use on other cases.
Another small change with c052066. Use |
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.
One renaming was neglected, otherwise it's looking great! Good to see some tests, too.
} else { | ||
Logger::log( 'This order will result in a membership, creating account for user.' ); | ||
$user_login = sanitize_title( $full_name ); | ||
$user_id = wc_create_new_customer( $email_address, $user_login, '', [ 'display_name' => $full_name ] ); |
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 was thinking about a method that would either wp_insert_user
or wc_create_new_customer
– but on a second thought it should not be used here because at this point we only wanna handle customer creation, not user creation. I was overthinking it.
Still, I think it'd be more readable if Reader_Activation
- in this code block - only set metadata on the created user, not take over the user creation and flow. Something like:
$user_id = wc_create_new_customer …
if ( Reader_Activation::is_enabled() ) {
Reader_Activation::setup_reader( $user_id );
}
wp_set_current_user …
But it's not a blocker.
Thank you for reviewing, @adekbadek! 🙇 |
# [1.84.0-alpha.1](v1.83.1...v1.84.0-alpha.1) (2022-06-02) ### Bug Fixes * **reader-revenue:** initial order state with total of 0 ([7c30b09](7c30b09)) ### Features * **ads:** handle gam default ad units ([#1654](#1654)) ([321b98e](321b98e)) * reader registration on donate ([#1655](#1655)) ([5821b57](5821b57)) * remove theme selection from setup wizard ([#1656](#1656)) ([94e4580](94e4580))
🎉 This PR is included in version 1.84.0-alpha.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
# [1.84.0](v1.83.3...v1.84.0) (2022-06-13) ### Bug Fixes * **ads:** resolve conflicts from hotfix merge ([#1685](#1685)) ([8ce12cd](8ce12cd)) * **reader-revenue:** initial order state with total of 0 ([7c30b09](7c30b09)) ### Features * **ads:** handle gam default ad units ([#1654](#1654)) ([321b98e](321b98e)) * **analytics:** automatically link GA4 with Site Kit ([#1698](#1698)) ([266135f](266135f)) * reader registration on donate ([#1655](#1655)) ([5821b57](5821b57)) * remove theme selection from setup wizard ([#1656](#1656)) ([94e4580](94e4580))
🎉 This PR is included in version 1.84.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
All Submissions:
Changes proposed in this Pull Request:
Implements reader registration functionality to the donation block.
Auth intention
If the reader registration detects an existing user, a cookie stores the auth intention that is accessible through the
Reader_Activation::get_auth_intention()
method. This API can be used across other plugins to improve UX over resolving the reader authentication, subscription, donation, etc.This PR currently implements the auth intention to the
wp_login_form()
defaults, which is used by the core's Login block. Unfortunately this hook is not applied to the WooCommerce's My Account page login form.The reader
The PR also proposes the definition of a reader user, which can be any user with the
np_reader
meta or within the rolessubscriber
orcustomer
. Identifying a reader helps us build flows tied specifically to this type of user, such as the magic link functionality.Email verification
Reader registration aims for a quick user registration and doesn't impose any validation for a new reader to be created and authenticated. The
Reader_Activation::verify_reader_email()
method is public but also executed on the reset password form action hook (resetpass_form
). Once a registered reader clicks on the reset password link received on their email, it'll trigger the method to make the reader verified.Experimental flag
This PR also proposes that all experimental features related to reader activation should be placed behind
NEWSPACK_EXPERIMENTAL_READER_ACTIVATION
, or theReader_Activation::is_enabled()
method for easier deprecation of theEXPERIMENTAL
flag in the future.How to test the changes in this Pull Request:
define( 'NEWSPACK_EXPERIMENTAL_READER_ACTIVATION', true );
my-account/orders
page and confirm you are logged in and you see the donation ordermy-account/orders
and confirm you are not authenticatednp_auth_intention
cookie with the email as the valueOther information: