WordPress.org

Ready to get started?Download WordPress

Forums

WordPress 2.5 Share users table (27 posts)

  1. denadai2
    Member
    Posted 6 years ago #

    How can i share user between 2 or more blogs in this way?

    http://wordpress.org/support/topic/116181?replies=17

    (this was for 2.x.x)

    thx

  2. kevinstory
    Member
    Posted 6 years ago #

    I am interested in how to do this as well. Thanks!

  3. sroyalty
    Member
    Posted 6 years ago #

    So far it is partly like the 2.3 mod. Below is how my 2.5 shares. Now, this is for the same access across all shared blogs. I have not set it up to give unique access per blog.

    wp-config.php in the 2nd, 3rd, etc (not first install though).
    Before the line with define('ABSPATH', dirname(__FILE__).'/');

    // Let's add the code for sharing a user db table within the wordpress database.
    // Remember, all blogs must be installed to the same database, with unique prefix's.
    // These entries point to the single blog's userbase to share.
    define('CUSTOM_USER_TABLE', 'wp_users');
    // Uncomment this to use the same usermeta globally for roles.
    define('CUSTOM_USER_META_TABLE', 'wp_usermeta');

    Then I made the following change to wp-includes/wp-capabilities.php
    Find the line:
    $this->cap_key = $wpdb->prefix . 'capabilities';
    Change it too:
    $this->cap_key = ‘wp_capabilities’;

  4. Khairil Zhafri
    Member
    Posted 6 years ago #

    I am getting this error:

    Fatal error: Cannot access empty property in /home/poppacket/domains/domain2.com/public_html/wp-includes/capabilities.php on line 169

  5. Khairil Zhafri
    Member
    Posted 6 years ago #

    1. Upgrade to 2.6.

    2. Make sure all WordPress instances on the same database.

    3. Say the primary blog have table prefix set to wp_ and the secondary ones with wp2_ wp3_ etc. Add the following in wp-config.php of the secondary installations:

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

    Very neat with v 2.6!

  6. harringtonjw
    Member
    Posted 5 years ago #

    I have added the two lines shown above and get the following error:

    You do not have sufficient permissions to access this page

    Is there anything else I need alter in the user table?

  7. MarsChelios
    Member
    Posted 5 years ago #

    Just upgraded to 1.6.1 and decided to add another blog to a subdomain but wanted users spread over both blogs. Took a while but figured it out with some help from a guy named ringmaster (http://trac.wordpress.org/ticket/2378).

    The problem appears to be a difference of opinion between users and WP programmers. Most users seem to think that a user should share the capabilities between blogs if they share the same database, where the programmers want the flexibility to allow users different caps between sites.

    harringtonjw, in short our problem is even though we have successfully shared the databases, with poppackets code, your users caps are not brought over and you dont have admin rights.

    To share user caps, you need to create another define in wp-config, I called mine CUSTOM_CAPABILITES_PREFIX and set it to the prefix of your master db.

    Now, in wp-includes/capabilities.php scroll down to WP_User and where it is has:

    $this->cap_key = $wpdb->prefix . 'capabilities';

    Replace it with this:

    if (defined ('CUSTOM_CAPABILITES_PREFIX')) {
      $this->cap_key = CUSTOM_CAPABILITES_PREFIX . 'capabilities';
    }
    else {
      $this->cap_key = $wpdb->prefix . 'capabilities';
    }

    After this, you should be able to log in to your new site with your master password successfully.

  8. ron_g
    Member
    Posted 5 years ago #

    The code worked for me perfectly but I am still running into the problem that users have to log in at each separate blog. Is there any way around this? Thanks.

  9. michuk
    Member
    Posted 5 years ago #

    I have two blogs, one on WP 2.6.1, one on 2.4.*. I'd like to share the user data between those. Unfortunately when I'm applying these tips, it all works on the new blog (on 2.6.1) but on the old one I cannot login anymore with my credentials. Is this due to same database changes? Where are the caps held in the database? Do you know of any fix for that exept upgrading to 2.6.1 on all blogs (can't do it for multiple reasons now).

  10. MarsChelios
    Member
    Posted 5 years ago #

    ron_g: I ran into this too and couldn't really figure out a good way around it. From what I understand, it's how sessions are supposed to work between domains, even if they are subdomains. I wonder if it could be possible to modify the login code to log the user into both domains? Something to look into...

    michuk: I would upgrade to the same version, I'm sure it's possible, but there's no telling what other problems you would run into with the differences.

  11. zodiaco
    Member
    Posted 5 years ago #

    I installed 2 worpress with different prefix:
    blog_ (for my blog)
    &
    portal_ (for the portal)

    I did all what you guys said here and sees work good but... good not mean perfect. When I try to log in to the Portal I couldn't have access to the Blog admin panel (wp-admin). But when I log in to the Blog and check my Portal I could see the link that show the online/offline status said I am logged in and not logged out :S. Maybe I need to edit something from the wp-admin directory but I have no idea where I am novice in this and I need help so if you know could you tell me :<? Send me a e-mail to: zodiaco@hacrak.co.cc

    Thank you.

  12. Neil T
    Member
    Posted 5 years ago #

    Hi All

    Thank you for all you comments here as they do help me to understand what wp is doing and how to update it.

    I've followed the steps above but still get the 'You do not have sufficient permissions to access this page.' on site number 2 !

    I've added the following to the wp-config file from poppacket

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

    As per MarsChelios comments I have also added

    define('CUSTOM_CAPABILITIES_PREFIX', 'wp_');

    and in capabilities.php I have changed

    $this->cap_key = $wpdb->prefix . 'capabilities';

    to

    if (defined ('CUSTOM_CAPABILITES_PREFIX')) {
    $this->cap_key = CUSTOM_CAPABILITES_PREFIX . 'capabilities';
    }
    else {
    $this->cap_key = $wpdb->prefix . 'capabilities';
    }

    but still I get 'You do not have sufficient permissions to access this page.' Can someone please tell me what I'm doing wrong here ?

    In addition I want to share all the tables from my main site (excluding options) on site 2. I know I may have duplicate content issues on the search engines but I'm not that bothered about that.

    Please help if you can, thanks

  13. peterassmann
    Member
    Posted 5 years ago #

    Actually I have the same problem. Tried with the code of Neil T and I doesnt work still, having the same error. "You do not have sufficient permissions to access this page." hope you'll be able to help us. :(

  14. taffeljohan
    Member
    Posted 5 years ago #

    Neil T and peterassman: There is a typo in the code.

    CUSTOM_CAPABILITES_PREFIX should be CUSTOM_CAPABILITIES_PREFIX.

  15. taffeljohan
    Member
    Posted 5 years ago #

    @Neil T

    I'm sick in bed and amusing myself by answering forum questions today.

    With regard to your question about using the same tables in a second blog. You could just change the table prefix in the init action, while preserving the options. Put something like this in a plugin:

    function table_prefix_switch() {
        global $wpdb;
        $options = $wpdb->options; //Save the site 2 options table
        $wpdb->set_prefix('wp_'); //The prefix to site 1
        $wpdb->options = $options; //Put the options table back
    }
    
    add_action('init', 'table_prefix_switch');

    I haven't tested this, but have used $wpdb->set_prefix() often for various hacks and switching blogs this way works well.

  16. Neil T
    Member
    Posted 5 years ago #

    @taffeljohan

    You my friend, are an absolute genius !

    I put that code in a plugin file, uploaded, activated and hey presto..........My 500 + articles from my other site appeared.

    Love it, thanks and get well soon :-)

  17. taffeljohan
    Member
    Posted 5 years ago #

    Glad I could help.

  18. wolthers
    Member
    Posted 5 years ago #

    Hello everyone. This helped me alot. I messed up when copypasting some of the code so i thought i'd make a clean version without typos. Here it is:

    In ALL of my installs:
    in wp-config.php:
    added just above /* That's all, stop editing! Happy blogging. */:
    define('CUSTOM_CAPABILITIES_PREFIX', 'wp_');

    in wp-includes/capabilities.php:
    replaced:
    $this->cap_key = $wpdb->prefix . 'capabilities';
    with:

    if (defined ('CUSTOM_CAPABILITIES_PREFIX')) {
    	$this->cap_key = CUSTOM_CAPABILITIES_PREFIX . 'capabilities';
    	}
    	else {	$this->cap_key = $wpdb->prefix . 'capabilities';
    	}

    In all installs EXCEPT the original:
    in wp-config.php:
    added just above /* That's all, stop editing! Happy blogging. */:

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

    AND replaced:
    $table_prefix = 'wp_';
    with
    $table_prefix = 'anyotherprefix_' //the prefix has to be unique for each installation

  19. wolthers
    Member
    Posted 5 years ago #

    With this, although I can use the same users on all my installs flawlessly, I have to log in each time i enter a new blog. Does anyone know how to share the cookies so you stay logged in?

    // Michael

  20. taffeljohan
    Member
    Posted 5 years ago #

  21. Huda
    Member
    Posted 5 years ago #

    I hate to edit the core files everytime I upgrade. Should we enroll this lines to the wordpress trac? Any tickets already?

    if (defined ('CUSTOM_CAPABILITIES_PREFIX')) {
    	$this->cap_key = CUSTOM_CAPABILITIES_PREFIX . 'capabilities';
    	}
    	else {	$this->cap_key = $wpdb->prefix . 'capabilities';
    	}
  22. taffeljohan
    Member
    Posted 5 years ago #

    @hudatoriq: There are trac tickets here and here. The conclusion was that this is 'broken' on purpose to give you the ability to assign user capabilities on a per-blog basis even when the user tables are shared (something I am learning to appreciate as the number of blogs comprising the site I build and maintain grows). But allowing for definition of CUSTOM_CAPABILITIES_PREFIX in wp-config.php sounds to me like a good idea. Trac it!

  23. Huda
    Member
    Posted 5 years ago #

    This is a good idea, but it's not mine :-). If this is going to be added in Trac, I prefer to let the one who brought this idea to take the credit :-).

    But if others don't have time to file the ticket, I can help. I think I'll wait 1-2 weeks. If there is no one to do it, I'll file it with links to this & some other related threads.

    This won't make it into 2.7 anyway..

  24. Neil T
    Member
    Posted 5 years ago #

    Hi All

    As usual I've been impatient and jumped staright in to uploading 2.7 to all my blogs and now none of them work. They used to all share the same tables except the options table.

    Does anyone know how to make this work in 2.7 ?

    Thanks

  25. Huda
    Member
    Posted 5 years ago #

    @Neil T

    Not sure. But they should work fine. I share user & usermeta table and they work in 2.7.
    Have you upgraded both site's database?
    Have you hack the capabilities.php again after the upgrade? It's overrided so you have to modify the lines again.

  26. safapombo
    Member
    Posted 5 years ago #

    Hi all,

    I have 3 WordPress Installations on my website, two blogs and one news. I am sharing the users table but don't know how to make them work with a single login. I see it can be achieved for 2.6, could it be done in 2.7? Would it be the same steps as described here?

    Thanks!

  27. J. Hai
    Member
    Posted 5 years ago #

    Two questions:

    Following the instructions here, I too was able to share the user tables between multiple WordPress 2.7 installs. However, when writing a post in any of the non-primary blogs, the shared users don't appear in the Author drop-down box. What am I missing here?

    Also, when registering a new user from a non-primary blog, by default that user's data gets entered into the non-primary blog's user table. Is there any way to make it so that new users registered on any blog get entered into the shared user table?

    Thanks in advance for any input.

Topic Closed

This topic has been closed to new replies.

About this Topic