From bf2d1d401666a11d292e6c606d39d115f71a739e Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Sun, 26 Jan 2014 20:14:13 -0200 Subject: [PATCH] don't create a new user if registration is disabled (fixes #19) --- social-connect.php | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/social-connect.php b/social-connect.php index 725efc4..28326f6 100644 --- a/social-connect.php +++ b/social-connect.php @@ -214,15 +214,27 @@ function sc_social_connect_process_login( $is_ajax = false ) { $user_login = $user_data->user_login; } else { // Create new user and associate provider identity - $user_login = sc_get_unique_username($user_login); - - $userdata = array( 'user_login' => $user_login, 'user_email' => $sc_email, 'first_name' => $sc_first_name, 'last_name' => $sc_last_name, 'user_url' => $sc_profile_url, 'user_pass' => wp_generate_password() ); - - // Create a new user - $user_id = wp_insert_user( $userdata ); - - if ( $user_id && is_integer( $user_id ) ) - update_user_meta( $user_id, $sc_provider_identity_key, $sc_provider_identity ); + if ( get_option( 'users_can_register' ) ) { + $user_login = sc_get_unique_username($user_login); + + $userdata = array( 'user_login' => $user_login, 'user_email' => $sc_email, 'first_name' => $sc_first_name, 'last_name' => $sc_last_name, 'user_url' => $sc_profile_url, 'user_pass' => wp_generate_password() ); + + // Create a new user + $user_id = wp_insert_user( $userdata ); + + if ( $user_id && is_integer( $user_id ) ) { + update_user_meta( $user_id, $sc_provider_identity_key, $sc_provider_identity ); + } + } else { + add_filter( 'wp_login_errors', function ( $errors ) { + $errors->errors = array(); + $errors->add( 'registration_disabled', __( 'ERROR: Registration is disabled.', 'social-connect' ) ); + + return $errors; + }); + + return; + } } wp_set_auth_cookie( $user_id );