Support » Plugins » Hacks » Clarifications on WP Multisite – Question on the database logical structure

  • Resolved Reyboz


    Hello hackers!

    Can i ask you a small question about the database logical structure of a WordPress enabled with Multisite?

    According to the official documentation (Multisite_Table_Details) for each blog registered in a WordPress Multisite Network, in the database are generated only:

    1. wp_{blog_id}_commentmeta
    2. wp_{blog_id}_comments
    3. wp_{blog_id}_links
    4. wp_{blog_id}_options
    5. wp_{blog_id}_postmeta
    6. wp_{blog_id}_posts
    7. wp_{blog_id}_terms
    8. wp_{blog_id}_term_relationships
    9. wp_{blog_id}_term_taxonomy

    …OK but, where are the users?

    Obviously in the main wp_users! You will say.

    But if all multisite’s users are registered in wp_users, there must be a reference table that link users to their own blog, so to their blog_id, and I supposed that the only place where there could be something like this, could be…

    …the field mail of the table wp_registration_log (!?!)

    I sincerely wish it were not so.

    Especially considering that in the official documentation there’s nothing written about a logical foreign key in the field of ‘wp_registration_log’ table that links to the wp_users (Table:_wp_registration_log).

    I remind you the structure of this table:


    ID	bigint(20) unsigned	 	PRI	NULL	auto_increment
    email	varchar(255)	NO
    IP	varchar(30)	NO
    blog_id	bigint(20) unsigned	 	PRI	0	FK->wp_blogs.blog_id

    (Note email, and blog_id).

    I’m right? The email field in the table wp_registration_log is the logical foreign key that (linking to the field user_email in the table wp_users) links the user to his blog?

    If so, it would not seem to be a very smart solution.

    Am I wrong?

    Tha(in advance)nks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz


    No, that would not be a smart solution. Fortunately, that’s not how it works. There is no logical link between the blog tables and the blog’s users. The blog does not directly know who its users are. We identify a user of a blog by the fact the usermeta has recorded particular capabilities for the blog. The only way a user is tied to a blog is by running a query on the usermeta table for capabilities.

    Take a look at the source for get_blogs_of_user(), if you understand PHP. At the bottom of the definition we see a foreach loop stepping through all the usermeta keys of the user, looking for keys that look something like wp_2_capabilities and extracting the “2” or whatever ID to assemble the blog IDs of the user. Seems rather crude, but if there were a direct relationship like you are looking for, this technique would not be necessary,

    Certainly looking at get_blogs_of_user() is all very clear. Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Clarifications on WP Multisite – Question on the database logical structure’ is closed to new replies.