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

---

# maybe_add_existing_user_to_blog()

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/maybe_add_existing_user_to_blog/?output_format=md#description)
 * [Source](https://developer.wordpress.org/reference/functions/maybe_add_existing_user_to_blog/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/maybe_add_existing_user_to_blog/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/maybe_add_existing_user_to_blog/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/maybe_add_existing_user_to_blog/?output_format=md#user-contributed-notes)

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

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

## 󠀁[Description](https://developer.wordpress.org/reference/functions/maybe_add_existing_user_to_blog/?output_format=md#description)󠁿

This will only work when the user’s details are saved as an option keyed as ‘new_user_{
key}’, where ‘{key}’ is a hash generated for the user to be added, as when a user
is invited through the regular WP Add User interface.

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

    ```php
    function maybe_add_existing_user_to_blog() {
    	if ( ! str_contains( $_SERVER['REQUEST_URI'], '/newbloguser/' ) ) {
    		return;
    	}

    	$parts = explode( '/', $_SERVER['REQUEST_URI'] );
    	$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(
    			/* translators: 1: Home URL, 2: Admin URL. */
    			__( 'You have been added to this site. Please visit the <a href="%1$s">homepage</a> or <a href="%2$s">log in</a> using your username and password.' ),
    			home_url(),
    			admin_url()
    		),
    		__( 'WordPress &rsaquo; Success' ),
    		array( 'response' => 200 )
    	);
    }
    ```

[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#L2222)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/ms-functions.php#L2222-L2259)

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

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

Removes an option by name. Prevents removal of protected WordPress options.

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

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/) .

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

Retrieves the translation of $text.

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

Kills WordPress execution and displays HTML page with an error message.

  | 
| [admin_url()](https://developer.wordpress.org/reference/functions/admin_url/)`wp-includes/link-template.php` |

Retrieves the URL to the admin area for the current site.

  | 
| [home_url()](https://developer.wordpress.org/reference/functions/home_url/)`wp-includes/link-template.php` |

Retrieves the URL for the current site where the front end is accessible.

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

Retrieves an option value based on an option name.

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

Checks whether the given variable is a WordPress Error.

  |

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

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/maybe_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/maybe_add_existing_user_to_blog/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/maybe_add_existing_user_to_blog/?output_format=md#comment-content-5750)
 2.   [Wayne](https://profiles.wordpress.org/waynep16/)  [  4 years ago  ](https://developer.wordpress.org/reference/functions/maybe_add_existing_user_to_blog/#comment-5750)
 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%2Fmaybe_add_existing_user_to_blog%2F%23comment-5750)
    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%2Fmaybe_add_existing_user_to_blog%2F%23comment-5750)
 4. “newbloguser” seems very out of touch now considering WordPress has massively evolved
    to not be just a “blog” yet more of a website builder platform.
 5.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fmaybe_add_existing_user_to_blog%2F%3Freplytocom%3D5750%23feedback-editor-5750)

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