Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Automatically login user across multisite

You can add each user automatically to each blog in your network. As example the follow simple function to add a user id to a blog id. If you loop about all sites and add the user to each blog with a role.

function join_site( $user_id = 0, $blog_id = 0, $role="editor" ) {

    if ( 0 === $user_id )
        return false;

    if ( 0 === $blog_id )
        return false;

    if ( ! is_user_logged_in() )
        return false;

    if ( ! is_user_member_of_blog( $user_id, $blog_id ) )
        add_user_to_blog( $blog_id, $current_user->ID, $role );
}

You can run this function on the register of a user or also on the login. On the register is smaller in the performance, only one request after register, not each login. But the function checks, if the user a part of the plugin, with the help of is_user_member_of_blog().

The benefit is, that each user is a real part of the blog, maybe with different roles. The result is, that you have all possibilities, also for other plugin to run functions the users.

For the login you should set the constant to define always the same cookie.

define( 'COOKIE_DOMAIN', '' );

That give the users the possibility to login in each site of the network, if the user is added to the site. For more in this context see this q/a.

Related Posts:

  1. Is there a is_user_logged_in() for multisite?
  2. Unable to login to new custom domain on multisite?
  3. share login/logout sessions across two installs?
  4. How to Login Once to an Entire WP Multisite Network
  5. Multisite – Redirect All Users to Subsite Home Page on Subsite Login
  6. WordPress Multisite Login Access
  7. Subdomain login problems
  8. WordPress Multisite local: wp-login.php refreshes on login Chrome Browser
  9. ‘Remote Login’ with MultiSite Domain Mapping still forcing users to login to all blogs individually?
  10. How to stay logged in on a multisite with different domains?
  11. Login on Multiple Sub-Domains without Multisite
  12. Fresh Multisite Install – Can’t Log In
  13. Auto Redirect after login
  14. WordPress MultiSite login to the respective site
  15. How to fix blocked cookies error that doesn’t let me log into wp-admin?
  16. Good way to block users within a multisite setup without deleting them?
  17. How can you override the is_multisite check in wp-login.php for individual login/registration?
  18. How to write RewriteRule for login in multisite
  19. Multisite Login problem
  20. Https and Http Login Issue on WordPress Multisite
  21. Different Domains in Multisite Setup
  22. Multisite infinite redirect loop
  23. Disable site visiting and user logins excepting for a specific user
  24. Infamous admin login redirect
  25. Is there something I need to know in order to use WordPress on foreign (Swedish) TLDs?
  26. Restrict users of site 1 to login in site 2 in wordpress multisite
  27. Unable to execute Ajax request, status code 400
  28. How to display custom logo on WordPress login page
  29. Moving from a non WordPress site to a WordPress Site – Login between both sites
  30. WordPress Multisite: Login to all subsites at once
  31. Multisite – site user limited only for this site
  32. Unable to sign in to network after moveing address but able to login into child sites
  33. User not staying logged into one of sub sites in multisite after SSL
  34. Single sign on to sub-sites in Multisite Network
  35. WordPress automatic Login on other page?
  36. how to make a cronjob run, when user needs to be logged in
  37. WordPress Network with SSL for multiple domains
  38. Why does this multisite redirection loop vanish when I add “www.”?
  39. One login for 3 WordPress installations with combined user table doesn’t work
  40. Multisite: Redirect Subsite Administrator to Subsite Home Page, Bypassing Dashboard
  41. Admin user getting redirected to /wp-admin/user
  42. How to login a user with wp_set_auth_cookie on a specific blog within a multisite environment
  43. Is it possible to create a login for restricted visibility?
  44. How do I combine wp_redirect and add_filter?
  45. Some Subdomains on a Multisite Install Not Found
  46. Common login for websites belonging in different networks
  47. Best Way to Setup a Network of WP Sites?
  48. WordPress Multisite restict user access
  49. Error Message when logging into WordPress on Xampp
  50. WordPress MU: Cookie error when trying to login on network WP instance
  51. something in database is causing me to not be able to log into network admin of multisite
  52. How to add Custom Blog Options to new blog setup form?
  53. How can I trust switch_to_blog()?
  54. Remove the blog slug from WordPress Multisite root node
  55. I want to develop locally with Multisite, then migrate each site to separate remote WP installs
  56. Overriding the default WP Multisite notification e-mail
  57. Changing subdir multisite install to subdir core directory structure
  58. Odd Script File Trying to be Loaded
  59. Multiple sites (separate domains) running from one WordPress site
  60. How does WordPress tell which post is from which site in a multisite setup?
  61. How do I use different domain for subdomains in WP Multisite?
  62. How to remove nodes site wide from the toolbar on multisite install
  63. Limit multisite/network site names to a property of the user
  64. How to set Active plugins as the default screen?
  65. Global searchin multisite but only with one subsite
  66. Hosting a seperate wordpress project on localhost
  67. Removing a wordpress multisite installation and preserving the database before migrate to nginx
  68. Add additional non-rewrite .htaccess directives on multisites via mod_rewrite_rules filter
  69. get_post_type_object() does not work with switch_to_blog()
  70. How to change the parent Domain Name in Multisites Project?
  71. WordPress MultiSite Theme
  72. How to run a WordPress site across multiple ccTLDs?
  73. Why is MySQL receiving such a large serialized object?
  74. How can I remove the folder from a Multisite URL?
  75. WP Multisite login not working on one subsite. Possibly cookies/ history issue?
  76. How to get blog_id of an MU site when running a custom function on the parent site
  77. WordPress multisite domain
  78. Using Same User Database on Subdomain
  79. Permission warning in wordpress multisite
  80. Static directories in a WordPress multisite network
  81. Trying to Decide Between Reverse-proxy and Multisite
  82. Remember language choice on multisite website
  83. wp-cli core install –skip-email and –skip-config flags not working on MAMP unknown parameter
  84. Multisite network subdomains doesn’t work
  85. MULTISITE: Password issue and Error Cant access site
  86. Accessing WP multisite via IP instead of domain
  87. Running hosted multisite version of wordpress
  88. How to implement this subdirectory mapping in multisite?
  89. WordPress MU with subdomain
  90. How do i get custom metabox data from each multisite blog?
  91. Multisite login and redirect to users main blog,
  92. Parse shortcodes from another site in WP Multisite
  93. Custom pages on all multisite network, to NOT show in wp-admin at all
  94. Install WordPress MU outside htdocs
  95. WordPress Multisite platform for different city for single db
  96. Not being allowed to use some terms in Add New Site in WordPress
  97. How to redirect root blog to a specific one in multilang WP?
  98. WordPress Network / Multisite login to one site allow access to all
  99. Export/Import Blog Post from and to sites with different themes?
  100. WordPress multisite with different sites for every language. How can I set the site based on the users browser location or language?
Categories multisite Tags login, multisite
Custom Post Type slug same as page name
Add Minimum Dimensions Text to Featured Image

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress