Function and usage of maybe_add_existing_user_to_blog() in wordpress


Answers ( 1 )


    The maybe_add_existing_user_to_blog() function in WordPress is designed for adding a new user to a blog, particularly in a multisite environment where a user might need access to multiple blogs within the network. Here's a detailed explanation of its function and sample usage:




    • This function is used to add a new user to a specific blog on a WordPress multisite network.
    • It operates by accessing a special URL of the format /newbloguser/{key}/, where {key} is a unique hash generated for the user who is to be added.
    • The process starts when the user's details are saved as an option in the WordPress database. The option's name is new_user_{key}, with {key} being the aforementioned hash.
    • The {key} is typically generated when a user is invited through the regular WordPress "Add User" interface. This is often part of the user invitation and registration process in a multisite setup.

    Sample Usage Scenario:

    1. Inviting a User: A site admin on a WordPress multisite network invites a new user to join a specific blog within the network. During this process, WordPress generates a unique hash ({key}) and saves the user's details with this key.

    2. User Accepts Invitation: The invited user receives an email with a link to accept the invitation. This link includes the special URL /newbloguser/{key}/.

    3. Function Activation: When the user visits the link, the maybe_add_existing_user_to_blog() function is triggered. The function looks for the saved option new_user_{key} in the database.

    4. Adding the User: If the details corresponding to the {key} are found, the function proceeds to add this user to the specific blog on the multisite network.

    5. Finalization: After the user is successfully added, they are typically redirected to the dashboard of the blog they've been added to, or they receive a confirmation message.

    Important Notes:

    • This function is specifically useful in a WordPress multisite environment.
    • It’s a part of WordPress's internal handling of user invitations and registrations, and is not typically used directly by theme or plugin developers.
    • Understanding this function is more relevant for developers looking into the WordPress core or those developing custom solutions for user management in a multisite setup.


    The maybe_add_existing_user_to_blog() function plays a crucial role in managing user access across different blogs within a WordPress multisite network. It ensures a seamless and secure process for inviting and adding users to specific blogs.

Leave an answer