How are roles stored in the database?

I know roles are defined http://codex.wordpress.org/Roles_and_Capabilities but how are they stored in the database? For instance, how is "Super Admin" stored i.e. 'super_admin'?

Answers 1

  • The core functions:

    • is_super_admin(),
    • grant_super_admin(),
    • revoke_super_admin()

    fetch the super admins data from the wp_sitemeta table with:

    $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
    

    It's stored as a serialized array of user logins, for each site, like:

    a:1:{i:0;s:6:"louiev";}
    

    It's possible to override it with the global $site_admins array.

    On the other hand, the general user roles (admin, editor, author, ...) are stored as serialized arrays, for each user, like:

    a:1:{s:13:"administrator";b:1;}
    

    in the wp_usermeta table under the wp_capabilities meta key and/or the wp_{$blog_id}_capabilities meta keys.

    Note that the wp_ prefix might be different on your install.


Related Questions