Search code examples
wordpressmultisitecodex

When Single User Logged In One Wordpress Site then user can automatically Logged-in other User's related site


I want Multisite Wordpress Network.In which when user login in one site then there are option for login in particulate this user's related sites.

And If User login in one site.(on subdomain) User also able to login there other sites. with some link or option. (on subdomain). all site are in same domain.

I Have Tried https://codex.wordpress.org/Create_A_Network. But this is not helpful for me. Because here only network admin can add theme/plugin. and only network admin can access all sites.

I have already tried this article "https://kinsta.com/blog/share-logins-wordpress/". But With this I am able to share same credential of user. Not any link or option for login in other site.


Solution

  • Solution :

    Our goal is to set up two WordPress websites which will share logins and the same users. Once a user has subscribed one

    website, she would be able to access the other website with the same role and capabilities.

    step 1: In order to share the same users and usermeta tables, WordPress installations must share the same database. add prefix of first wordpress installation first_ and second wordpress installation table second_. in same database.

    step 2: When the first WordPress website is up and running, we can edit its configuration file. Open /first/wp-config.php

    and add the following lines above the ‘stop editing’ comment:

     $table_prefix  = 'first_';
     define('WP_DEBUG', true);
     define( 'WP_DEBUG_LOG', true );
     define( 'WP_DEBUG_DISPLAY', false );
     @ini_set( 'display_errors', 0 );  
    
    // custom users and usermeta tables
    define( 'CUSTOM_USER_TABLE', $table_prefix . 'users' );
    define( 'CUSTOM_USER_META_TABLE', $table_prefix . 'usermeta' ); 
    
    /* That's all, stop editing! Happy blogging. */
    

    step 3: We are done with the first installation. Next we have to copy wp-config.php from the first installation folder and

    paste it into the root folder of the second installation. Be careful to change the $table_prefix value accordingly:

    open /second/wp-config.php.and add the following lines above the ‘stop editing’ comment:

     $table_prefix  = 'second_';
        define('WP_DEBUG', true);
        define( 'WP_DEBUG_LOG', true );
        define( 'WP_DEBUG_DISPLAY', false );
        @ini_set( 'display_errors', 0 );
    
          // custom users and usermeta tables
         define( 'CUSTOM_USER_TABLE', 'first_users' );
         define( 'CUSTOM_USER_META_TABLE', 'first_usermeta' );
    

    step 4: write in both wp-config.php for sharing cookies.

        //Share cookies
       define('COOKIE_DOMAIN', '.xyz.com');
       define('COOKIEHASH', 'aee53c017c29dc0d3ae37253fc8cbfd8');
    

    step 5: Open table "first_usermeta" and copy from column meta_key - first_capabilities and first_user_level to the second_capabilities and second_user_level.

    step 6: When running the second installation, we should set a non-existent email address for admin user as WordPress finds a number of existing users from first_users table.

    For more Detail https://kinsta.com/blog/share-logins-wordpress/.

    It's work for Me.