maybe_add_existing_user_to_blog

The timeline below displays how wordpress function maybe_add_existing_user_to_blog has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Adds a new user to a blog by visiting /newbloguser/{key}/.
 *
 * 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.
 *
 * @since MU (3.0.0)
 */
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));
}

WordPress Version: 6.1

/**
 * Adds a new user to a blog by visiting /newbloguser/{key}/.
 *
 * 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.
 *
 * @since MU (3.0.0)
 */
function maybe_add_existing_user_to_blog()
{
    if (false === strpos($_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));
}

WordPress Version: 5.6

/**
 * Add a new user to a blog by visiting /newbloguser/{key}/.
 *
 * 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.
 *
 * @since MU (3.0.0)
 */
function maybe_add_existing_user_to_blog()
{
    if (false === strpos($_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));
}

WordPress Version: 5.5

/**
 * Add a new user to a blog by visiting /newbloguser/{key}/.
 *
 * 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.
 *
 * @since MU (3.0.0)
 */
function maybe_add_existing_user_to_blog()
{
    if (false === strpos($_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. Back 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));
}

WordPress Version: 5.4

/**
 * Add a new user to a blog by visiting /newbloguser/{key}/.
 *
 * 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.
 *
 * @since MU (3.0.0)
 */
function maybe_add_existing_user_to_blog()
{
    if (false === strpos($_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. Back 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));
}

WordPress Version: 5.3

/**
 * Add a new user to a blog by visiting /newbloguser/{key}/.
 *
 * 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.
 *
 * @since MU (3.0.0)
 */
function maybe_add_existing_user_to_blog()
{
    if (false === strpos($_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. Back 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));
}

WordPress Version: 5.1

/**
 * Add a new user to a blog by visiting /newbloguser/{key}/.
 *
 * 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.
 *
 * @since MU (3.0.0)
 */
function maybe_add_existing_user_to_blog()
{
    if (false === strpos($_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(__('An error occurred adding you to this site. Back to the <a href="%s">homepage</a>.'), home_url()));
    }
    wp_die(sprintf(__('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));
}

WordPress Version: 4.9

/**
 * Add a new user to a blog by visiting /newbloguser/{key}/.
 *
 * 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.
 *
 * @since MU (3.0.0)
 */
function maybe_add_existing_user_to_blog()
{
    if (false === strpos($_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(__('An error occurred adding you to this site. Back to the <a href="%s">homepage</a>.'), home_url()));
    }
    wp_die(sprintf(__('You have been added to this site. Please visit the <a href="%s">homepage</a> or <a href="%s">log in</a> using your username and password.'), home_url(), admin_url()), __('WordPress &rsaquo; Success'), array('response' => 200));
}

WordPress Version: 4.3

/**
 * Add a new user to a blog by visiting /newbloguser/username/.
 *
 * This will only work when the user's details are saved as an option
 * keyed as 'new_user_x', where 'x' is the username of the user to be
 * added, as when a user is invited through the regular WP Add User interface.
 *
 * @since MU
 */
function maybe_add_existing_user_to_blog()
{
    if (false === strpos($_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(__('An error occurred adding you to this site. Back to the <a href="%s">homepage</a>.'), home_url()));
    }
    wp_die(sprintf(__('You have been added to this site. Please visit the <a href="%s">homepage</a> or <a href="%s">log in</a> using your username and password.'), home_url(), admin_url()), __('WordPress &rsaquo; Success'), array('response' => 200));
}

WordPress Version: 4.2

/**
 * Add a new user to a blog by visiting /newbloguser/username/.
 *
 * This will only work when the user's details are saved as an option
 * keyed as 'new_user_x', where 'x' is the username of the user to be
 * added, as when a user is invited through the regular WP Add User interface.
 *
 * @since MU
 */
function maybe_add_existing_user_to_blog()
{
    if (false === strpos($_SERVER['REQUEST_URI'], '/newbloguser/')) {
        return false;
    }
    $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(__('An error occurred adding you to this site. Back to the <a href="%s">homepage</a>.'), home_url()));
    }
    wp_die(sprintf(__('You have been added to this site. Please visit the <a href="%s">homepage</a> or <a href="%s">log in</a> using your username and password.'), home_url(), admin_url()), __('WordPress &rsaquo; Success'), array('response' => 200));
}

WordPress Version: 4.1

/**
 * Add a new user to a blog by visiting /newbloguser/username/.
 *
 * This will only work when the user's details are saved as an option
 * keyed as 'new_user_x', where 'x' is the username of the user to be
 * added, as when a user is invited through the regular WP Add User interface.
 *
 * @since MU
 */
function maybe_add_existing_user_to_blog()
{
    if (false === strpos($_SERVER['REQUEST_URI'], '/newbloguser/')) {
        return false;
    }
    $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(__('An error occurred adding you to this site. Back to the <a href="%s">homepage</a>.'), home_url()));
    }
    wp_die(sprintf(__('You have been added to this site. Please visit the <a href="%s">homepage</a> or <a href="%s">log in</a> using your username and password.'), home_url(), admin_url()), __('WordPress &rsaquo; Success'));
}

WordPress Version: 3.7

/**
 * Add a new user to a blog by visiting /newbloguser/username/.
 *
 * This will only work when the user's details are saved as an option
 * keyed as 'new_user_x', where 'x' is the username of the user to be
 * added, as when a user is invited through the regular WP Add User interface.
 *
 * @since MU
 * @uses add_existing_user_to_blog()
 */
function maybe_add_existing_user_to_blog()
{
    if (false === strpos($_SERVER['REQUEST_URI'], '/newbloguser/')) {
        return false;
    }
    $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(__('An error occurred adding you to this site. Back to the <a href="%s">homepage</a>.'), home_url()));
    }
    wp_die(sprintf(__('You have been added to this site. Please visit the <a href="%s">homepage</a> or <a href="%s">log in</a> using your username and password.'), home_url(), admin_url()), __('WordPress &rsaquo; Success'));
}