add_existing_user_to_blog example



    // Adding an existing user to this blog.     $new_user_email = array();
    $redirect       = 'user-new.php';
    $username       = $user_details->user_login;
    $user_id        = $user_details->ID;
    if ( null != $username && array_key_exists( $blog_idget_blogs_of_user( $user_id ) ) ) {
        $redirect = add_query_arg( array( 'update' => 'addexisting' ), 'user-new.php' );
    } else {
        if ( isset( $_POST['noconfirmation'] ) && current_user_can( 'manage_network_users' ) ) {
            $result = add_existing_user_to_blog(
                array(
                    'user_id' => $user_id,
                    'role'    => $_REQUEST['role'],
                )
            );

            if ( ! is_wp_error( $result ) ) {
                $redirect = add_query_arg(
                    array(
                        'update'  => 'addnoconfirmation',
                        'user_id' => $user_id,
                    ),
$key   = array_pop( $parts );

    if ( '' === $key ) {
        $key = array_pop( $parts );
    }

    $details = get_option( 'new_user_' . $key );
    if ( ! empty( $details ) ) {
        delete_option( 'new_user_' . $key );
    }

    if ( empty( $details ) || is_wp_error( add_existing_user_to_blog( $details ) ) ) {
        wp_die(
            sprintf(
                /* translators: %s: Home URL. */
                __( 'An error occurred adding you to this site. Go to the <a href="%s">homepage</a>.' ),
                home_url()
            )
        );
    }

    wp_die(
        sprintf(
            
Home | Imprint | This part of the site doesn't use cookies.