Title: add_existing_user_to_blog
Published: April 25, 2014
Last modified: April 28, 2025

---

# add_existing_user_to_blog( array|false $details = false ): true|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿|void

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/add_existing_user_to_blog/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/add_existing_user_to_blog/?output_format=md#return)
 * [More Information](https://developer.wordpress.org/reference/functions/add_existing_user_to_blog/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/functions/add_existing_user_to_blog/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/add_existing_user_to_blog/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/add_existing_user_to_blog/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/add_existing_user_to_blog/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/add_existing_user_to_blog/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/add_existing_user_to_blog/?output_format=md#wp--skip-link--target)

Adds a user to a blog based on details from [maybe_add_existing_user_to_blog()](https://developer.wordpress.org/reference/functions/maybe_add_existing_user_to_blog/).

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/add_existing_user_to_blog/?output_format=md#parameters)󠁿

 `$details`array|falseoptional

User details. Must at least contain values for the keys listed below.

 * `user_id` int
 * The ID of the user being added to the current blog.
 * `role` string
 * The role to be assigned to the user.

Default:`false`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/add_existing_user_to_blog/?output_format=md#return)󠁿

 true|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)|void
True on success or a [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
object if the user doesn’t exist or could not be added. Void if $details array was
not provided.

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/add_existing_user_to_blog/?output_format=md#more-information)󠁿

This function is called by `maybe_add_existing_user_to_blog()` and should not be
called directly. This page is for informational purposes only. Use `add_user_to_blog()`.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/add_existing_user_to_blog/?output_format=md#source)󠁿

    ```php
    function add_existing_user_to_blog( $details = false ) {
    	if ( is_array( $details ) ) {
    		$blog_id = get_current_blog_id();
    		$result  = add_user_to_blog( $blog_id, $details['user_id'], $details['role'] );

    		/**
    		 * Fires immediately after an existing user is added to a site.
    		 *
    		 * @since MU (3.0.0)
    		 *
    		 * @param int           $user_id User ID.
    		 * @param true|WP_Error $result  True on success or a WP_Error object if the user doesn't exist
    		 *                               or could not be added.
    		 */
    		do_action( 'added_existing_user', $details['user_id'], $result );

    		return $result;
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/ms-functions.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/ms-functions.php#L2275)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/ms-functions.php#L2275-L2293)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/add_existing_user_to_blog/?output_format=md#hooks)󠁿

 [do_action( ‘added_existing_user’, int $user_id, true|WP_Error $result )](https://developer.wordpress.org/reference/hooks/added_existing_user/)

Fires immediately after an existing user is added to a site.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/add_existing_user_to_blog/?output_format=md#related)󠁿

| Uses | Description | 
| [add_user_to_blog()](https://developer.wordpress.org/reference/functions/add_user_to_blog/)`wp-includes/ms-functions.php` |

Adds a user to a blog, along with specifying the user’s role.

  | 
| [get_current_blog_id()](https://developer.wordpress.org/reference/functions/get_current_blog_id/)`wp-includes/load.php` |

Retrieves the current site ID.

  | 
| [do_action()](https://developer.wordpress.org/reference/functions/do_action/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to an action hook.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/add_existing_user_to_blog/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/add_existing_user_to_blog/?output_format=md#)

| Used by | Description | 
| [maybe_add_existing_user_to_blog()](https://developer.wordpress.org/reference/functions/maybe_add_existing_user_to_blog/)`wp-includes/ms-functions.php` |

Adds a new user to a blog by visiting /newbloguser/{key}/.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/add_existing_user_to_blog/?output_format=md#changelog)󠁿

| Version | Description | 
| [MU (3.0.0)](https://developer.wordpress.org/reference/since/mu.3.0.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/add_existing_user_to_blog/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 2 content](https://developer.wordpress.org/reference/functions/add_existing_user_to_blog/?output_format=md#comment-content-6815)
 2.    [Sakib MD Nazmush](https://profiles.wordpress.org/sakibsnaz/)  [  2 years ago  ](https://developer.wordpress.org/reference/functions/add_existing_user_to_blog/#comment-6815)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fadd_existing_user_to_blog%2F%23comment-6815)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fadd_existing_user_to_blog%2F%23comment-6815)
 4.  **function add_existing_user_to_blog($details = false)** defines a function where**
     add_existing_user_to_blog** is the function name. Here in **($details = false)**
     this part, **$details** is the parameter. Parameters are like placeholders for
     values that you can pass to the function when you call it. And **‘= false’**, 
     like the default value, means that if no values are provided for **$details**,
     then by default false will be worked.
 5.  **if (is_array($details))** this function first checks if the provided information
     is in the form of an array and the right format.
 6.  **$blog_id = [get_current_blog_id()](https://developer.wordpress.org/reference/functions/get_current_blog_id/)**
     in which blog page or post you’re currently working on. Here **$blog_id** is the
     variable, and **[get_current_blog_id()](https://developer.wordpress.org/reference/functions/get_current_blog_id/)**
     is the function name.
 7.  In the **$result** variable, the function named **add_user_to_blog** is called.
     Here, **$blog_id** represents the specific blog post to which a user is being 
     added, with the user identified by **$details[‘user_id’]**. Additionally, in **
     $details[‘role’]**, the permission level assigned to the user for the specific
     blog post is specified.
 8.  **do_action(‘added_existing_user’, $details[‘user_id’], $result)** here action
     name **‘added_existing_user’**. The parameter **$details[‘user_id’]** designates
     the user who was added. And the **$result** variable stores whether the user was
     successfully assigned or not.
 9.  In short, this function makes sure that when you want to add an existing user 
     to a particular blog, it verifies the information, adds the user, notifies the
     system to the addition, and then reports back to you on whether or not everything
     went according to plan. It functions similarly to a useful tool for WordPress 
     site user management.
 10.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fadd_existing_user_to_blog%2F%3Freplytocom%3D6815%23feedback-editor-6815)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fadd_existing_user_to_blog%2F)
before being able to contribute a note or feedback.