Merge pull request #11594 from woothemes/multisite-login-11409

Add user to site on login
This commit is contained in:
Claudio Sanches 2016-08-02 16:00:33 -03:00 committed by GitHub
commit 4271617c79
2 changed files with 17 additions and 6 deletions

View File

@ -873,9 +873,12 @@ class WC_Form_Handler {
if ( ! empty( $_POST['login'] ) && wp_verify_nonce( $nonce_value, 'woocommerce-login' ) ) { if ( ! empty( $_POST['login'] ) && wp_verify_nonce( $nonce_value, 'woocommerce-login' ) ) {
try { try {
$creds = array(); $creds = array(
$username = trim( $_POST['username'] ); 'user_password' => $_POST['password'],
'remember' => isset( $_POST['rememberme'] ),
);
$username = trim( $_POST['username'] );
$validation_error = new WP_Error(); $validation_error = new WP_Error();
$validation_error = apply_filters( 'woocommerce_process_login_errors', $validation_error, $_POST['username'], $_POST['password'] ); $validation_error = apply_filters( 'woocommerce_process_login_errors', $validation_error, $_POST['username'], $_POST['password'] );
@ -904,10 +907,17 @@ class WC_Form_Handler {
$creds['user_login'] = $username; $creds['user_login'] = $username;
} }
$creds['user_password'] = $_POST['password']; // On multisite, ensure user exists on current site, if not add them before allowing login.
$creds['remember'] = isset( $_POST['rememberme'] ); if ( is_multisite() ) {
$secure_cookie = is_ssl() ? true : false; $user_data = get_user_by( 'login', $username );
$user = wp_signon( apply_filters( 'woocommerce_login_credentials', $creds ), $secure_cookie );
if ( $user_data && ! is_user_member_of_blog( $user_data->ID, get_current_blog_id() ) ) {
add_user_to_blog( get_current_blog_id(), $user_data->ID, 'customer' );
}
}
// Perform the login
$user = wp_signon( apply_filters( 'woocommerce_login_credentials', $creds ), is_ssl() );
if ( is_wp_error( $user ) ) { if ( is_wp_error( $user ) ) {
$message = $user->get_error_message(); $message = $user->get_error_message();

View File

@ -164,6 +164,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Improved handling of shop page rewrite rules to allow subpages. * Improved handling of shop page rewrite rules to allow subpages.
* Redirect to login after password reset. * Redirect to login after password reset.
* When using authorizations in PayPal standard, automatically capture funds when the order goes processing/completed. * When using authorizations in PayPal standard, automatically capture funds when the order goes processing/completed.
* On multisite, when a user logs into a store with an account on a site, but not the current site, rather than error, add the user to the current site as a customer.
[See changelog for all versions](https://raw.githubusercontent.com/woothemes/woocommerce/master/CHANGELOG.txt). [See changelog for all versions](https://raw.githubusercontent.com/woothemes/woocommerce/master/CHANGELOG.txt).