From e6fbceae9f682b6a333c787f8476f35c0b3c58e3 Mon Sep 17 00:00:00 2001 From: wpmuguru Date: Sat, 24 Apr 2010 18:39:22 +0000 Subject: [PATCH] fix site administrator add user to site logic, see #12488 git-svn-id: http://svn.automattic.com/wordpress/trunk@14226 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/ms-functions.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/wp-includes/ms-functions.php b/wp-includes/ms-functions.php index 0abbb9ca34..e9e47feac6 100644 --- a/wp-includes/ms-functions.php +++ b/wp-includes/ms-functions.php @@ -252,7 +252,7 @@ function add_user_to_blog( $blog_id, $user_id, $role ) { $user = new WP_User($user_id); - if ( empty($user) ) + if ( empty($user) || !$user->ID ) return new WP_Error('user_does_not_exist', __('That user does not exist.')); if ( !get_user_meta($user_id, 'primary_blog', true) ) { @@ -1317,16 +1317,21 @@ function maybe_add_existing_user_to_blog() { $key = array_pop( $parts ); $details = get_option( 'new_user_' . $key ); - add_existing_user_to_blog( $details ); - delete_option( 'new_user_' . $key ); - wp_die( sprintf(__('You have been added to this blog. Please visit the homepage or login using your username and password.'), site_url(), admin_url() ) ); + if ( !empty( $details ) ) + delete_option( 'new_user_' . $key ); + + if ( empty( $details ) || is_wp_error( add_existing_user_to_blog( $details ) ) ) + wp_die( sprintf(__('An error occurred adding you to this site. Back to the homepage.'), site_url() ) ); + + wp_die( sprintf(__('You have been added to this site. Please visit the homepage or login using your username and password.'), site_url(), admin_url() ), __('Success') ); } function add_existing_user_to_blog( $details = false ) { if ( is_array( $details ) ) { - add_user_to_blog( '', $details[ 'user_id' ], $details[ 'role' ] ); - do_action( 'added_existing_user', $details[ 'user_id' ] ); + $result = add_user_to_blog( '', $details[ 'user_id' ], $details[ 'role' ] ); + do_action( 'added_existing_user', $details[ 'user_id' ], $result ); } + return $result; } function add_new_user_to_blog( $user_id, $email, $meta ) {