WordPress.org

Ready to get started?Download WordPress

Forums

Sharing user accounts between seperate blogs in the same database (17 posts)

  1. Varsity
    Member
    Posted 8 years ago #

    I've just read this useful thread from last year. It's sort of what I want to do, but not quite: I'm trying to create an internal blog only available to registered users. This means sharing registered user info between each set of tables. Looking at this bug ticket it is possible, but I can't find any details on how to do it.

    Any help appreciated!

  2. Austin Matzko
    Member
    Posted 8 years ago #

    Assuming you've installed your internal blog with different table prefixes in the same database as your public blog (say 'wp_internal_' for the internal, and just 'wp_' for the public), then you can add these lines to your internal blog's wp-config.php file:

    define('CUSTOM_USER_TABLE','wp_users');
    define('CUSTOM_USER_META_TABLE','wp_usermeta');

    Those lines need to appear before require_once(ABSPATH.'wp-settings.php');

  3. Austin Matzko
    Member
    Posted 8 years ago #

    I forgot to mention that if you want users to stay logged in across the two blogs, you should add the following two lines:

    define('USER_COOKIE', 'wordpressuser_'. [public site's cookie hash]);
    define('PASS_COOKIE', 'wordpresspass_'. [public site's cookie hash]);

    You can see the public site's cookie hash in your cookies, or render it with the following, where "siteurl" is the value under Options > General > "WordPress address (URI):"

    the cookie hash = md5(siteurl);

    so you'd have something like

    $public_cookiehash = md5('http://www.example.com');
    define('USER_COOKIE', 'wordpressuser_'. $public_cookiehash);
    define('PASS_COOKIE', 'wordpresspass_'. $public_cookiehash);

  4. Varsity
    Member
    Posted 8 years ago #

    Thanks, that's just what I need. Where does the cookie code go - before require_once like the user tables lines?

    Something else just came into my mind: can I use the same FTP files from both blogs? I can't think of anything that would prevent that, except for wp-config.

  5. Austin Matzko
    Member
    Posted 8 years ago #

    Thanks, that's just what I need. Where does the cookie code go - before require_once like the user tables lines?

    Yeah, just put it after the other stuff I mentioned earlier.

    can I use the same FTP files from both blogs?

    You mean the WordPress installation files? Sure. You are installing the internal blog in a separate directory, right?

  6. Varsity
    Member
    Posted 8 years ago #

    That's what I'm asking - can the two blogs use the same wp-content, wp-admin, etc. folders on the server? You seem to suggest that it can't though.

  7. Austin Matzko
    Member
    Posted 8 years ago #

    Right, they can't use the same files on the same server. But because you said "FTP files" I thought you were asking if you could reuse the WP files in the installation zip file, which of course you can. But your two blogs will need to be in separate directories.

  8. Varsity
    Member
    Posted 8 years ago #

    I'm getting an error stating that I already have WP installed. True enough, but not not terribly useful in this situation! I've set up the login details correctly, and I am using a unique table prefix (unless somebody I can't see on the DB has chosen ninja_ too).

    Any ideas?

  9. Austin Matzko
    Member
    Posted 8 years ago #

    Install the internal blog before adding the changes I mentioned above, then put them in.

  10. Varsity
    Member
    Posted 8 years ago #

    OK, I'm up and running! Slight hitch with permissions, as the admin account from the parent blog wasn't an admin in the new one, but logging into WP's default account before inserting the wp-config code sorted that out easily enough.

    Thanks for the help!

  11. Varsity
    Member
    Posted 8 years ago #

    Actually, one last glitch. If you log in to the sub-blog, you aren't logged in to the main site. I would expect logins from either location to apply to both blogs. Any way to close that loophole?

  12. Austin Matzko
    Member
    Posted 8 years ago #

    You did the cookie settings as I suggested above?

    If you log out of both, then log into the main blog, can you access the sub-blog?

  13. Varsity
    Member
    Posted 8 years ago #

    Yes, it's in there and works as you describe. It's just that while logins on the main site work for the sub-blog, the opposite isn't true.

  14. Austin Matzko
    Member
    Posted 8 years ago #

    My bad. Try adding this after the other stuff above:

    define('COOKIE_DOMAIN','');

    or it might need to be

    define('COOKIE_DOMAIN','/');

  15. Pixelstyle
    Member
    Posted 8 years ago #

    Hi, i'm trying to realise the same thing, and after following the instructions above it works partially.

    If I login on the first blog (who's user tables are shared) everything works fine. When I go to the second blog I'm already logged in.
    So far so good.

    But logging out doesn't work since I get a message that I'm not allowed to access blogname/wp-admin/profile.php
    I can enter the admin, but only the first page.

    This seems to be a problem with wp_usermeta, but I did define that one as well as wp_users.

    Can anyone help me with this?

  16. dh
    Member
    Posted 7 years ago #

    $public_cookiehash = md5('http://www.example.com');
    define('USER_COOKIE', 'wordpressuser_'. $public_cookiehash);
    define('PASS_COOKIE', 'wordpresspass_'. $public_cookiehash);

    I'm trying to do the same thing. The above code works for the second blog, or 1st child blog (if you want to call it that) fine, but doesn't work when I've put it in the wp-config files of other additional blogs. Any ideas?

  17. dh
    Member
    Posted 7 years ago #

    anoyone any ideas

Topic Closed

This topic has been closed to new replies.

About this Topic