/** * Create a new WordPress user with the specified identity URL and user data. * * @param string $identity_url OpenID to associate with the newly * created account * @param array $user_data array of user data */ function openid_create_new_user($identity_url, &$user_data) { global $wpdb; // Identity URL is new, so create a user @include_once( ABSPATH . 'wp-admin/upgrade-functions.php'); // 2.1 @include_once( ABSPATH . WPINC . '/registration-functions.php'); // 2.0.4 // otherwise, try to use preferred username if ( empty($username) && array_key_exists('nickname', $user_data) ) { $username = openid_generate_new_username($user_data['nickname'], false); } // finally, build username from OpenID URL if (empty($username)) { $username = openid_generate_new_username($identity_url); } $user_data['user_login'] = $username; $user_data['user_pass'] = substr( md5( uniqid( microtime() ) ), 0, 7); $user_id = wp_insert_user( $user_data ); if( $user_id ) { // created ok $user_data['ID'] = $user_id; // XXX this all looks redundant, see openid_set_current_user $user = new WP_User( $user_id ); if( ! wp_login( $user->user_login, $user_data['user_pass'] ) ) { openid_message(__('User was created fine, but wp_login() for the new user failed. This is probably a bug.', 'openid')); openid_status('error'); openid_error(openid_message()); return; } // notify of user creation wp_new_user_notification( $user->user_login ); wp_clearcookie(); wp_setcookie( $user->user_login, md5($user->user_pass), true, '', '', true ); // Bind the provided identity to the just-created user openid_add_user_identity($user_id, $identity_url); openid_status('redirect'); if ( !$user->has_cap('edit_posts') ) $redirect_to = '/wp-admin/profile.php'; } else { // failed to create user for some reason. openid_message(__('OpenID authentication successful, but failed to create WordPress user. This is probably a bug.', 'openid')); openid_status('error'); openid_error(openid_message()); } }
/** * Create a new WordPress user with the specified identity URL and user data. * * @param string $identity_url OpenID to associate with the newly * created account * @param array $user_data array of user data */ function openid_create_new_user($identity_url, &$user_data) { global $wpdb; // Identity URL is new, so create a user @(include_once ABSPATH . 'wp-admin/upgrade-functions.php'); // 2.1 @(include_once ABSPATH . WPINC . '/registration-functions.php'); // 2.0.4 // use email address for username if URL is from emailtoid.net $username = $identity_url; if (null != $_SESSION['openid_login_email'] and strpos($username, 'http://emailtoid.net/') == 0) { if ($user_data['user_email'] == NULL) { $user_data['user_email'] = $_SESSION['openid_login_email']; } $username = $_SESSION['openid_login_email']; unset($_SESSION['openid_login_email']); } $user_data['user_login'] = $wpdb->escape(openid_generate_new_username($username)); $user_data['user_pass'] = substr(md5(uniqid(microtime())), 0, 7); $user_id = wp_insert_user($user_data); if ($user_id) { // created ok $user_data['ID'] = $user_id; // XXX this all looks redundant, see openid_set_current_user $user = new WP_User($user_id); if (!wp_login($user->user_login, $user_data['user_pass'])) { openid_message(__('User was created fine, but wp_login() for the new user failed. This is probably a bug.', 'openid')); openid_action('error'); openid_error(openid_message()); return; } // notify of user creation wp_new_user_notification($user->user_login); wp_clearcookie(); wp_setcookie($user->user_login, md5($user->user_pass), true, '', '', true); // Bind the provided identity to the just-created user openid_add_user_identity($user_id, $identity_url); openid_status('redirect'); if (!$user->has_cap('edit_posts')) { $redirect_to = '/wp-admin/profile.php'; } } else { // failed to create user for some reason. openid_message(__('OpenID authentication successful, but failed to create WordPress user. This is probably a bug.', 'openid')); openid_status('error'); openid_error(openid_message()); } }
/** * Create a new WordPress user with the specified identity URL and user data. * * @param string $identity_url OpenID to associate with the newly * created account * @param array $user_data array of user data * @uses do_action() Calls 'openid_consumer_new_user_custom_data' hook action after creating user */ function openid_create_new_user($identity_url, &$user_data) { global $wpdb; // Identity URL is new, so create a user @(include_once ABSPATH . 'wp-admin/upgrade-functions.php'); // 2.1 @(include_once ABSPATH . WPINC . '/registration-functions.php'); // 2.0.4 // otherwise, try to use preferred username if (empty($username) && array_key_exists('nickname', $user_data)) { $username = openid_generate_new_username($user_data['nickname'], false); } // try using email address before resorting to URL if (empty($username) && array_key_exists('user_email', $user_data)) { $username = openid_generate_new_username($user_data['user_email'], false); } // finally, build username from OpenID URL if (empty($username)) { $username = openid_generate_new_username($identity_url); } $user_data['user_login'] = $username; $user_data['display_name'] = $username; $user_data['user_pass'] = substr(md5(uniqid(microtime())), 0, 7); $user_id = wp_insert_user($user_data); if ($user_id instanceof WP_Error) { openid_message($user_id->get_error_message()); openid_status('error'); return; } else { if (is_integer($user_id)) { // created ok $user_data['ID'] = $user_id; // XXX this all looks redundant, see openid_set_current_user $user = new WP_User($user_id); $credentials = array('user_login' => $user->user_login, 'user_password' => $user_data['user_pass'], 'remember' => true); if (!wp_signon($credentials)) { openid_message(__('User was created fine, but wp_signon() for the new user failed. This is probably a bug.', 'openid')); openid_status('error'); openid_error(openid_message()); return; } // notify of user creation wp_new_user_notification($user_id); wp_clear_auth_cookie(); wp_set_auth_cookie($user_id, true); // Bind the provided identity to the just-created user openid_add_user_identity($user_id, $identity_url); openid_status('redirect'); do_action('openid_consumer_new_user_custom_data', $user_id, $user_data); if (!$user->has_cap('edit_posts')) { $redirect_to = '/wp-admin/profile.php'; } } else { // failed to create user for some reason. openid_message(__('OpenID authentication successful, but failed to create WordPress user. This is probably a bug.', 'openid')); openid_status('error'); openid_error(openid_message()); } } }