The MU forums have moved to WordPress.org

capabilities explanation (11 posts)

  1. jdwilbur
    Member
    Posted 12 years ago #

    Can someone please tell me how to parse the value for wp_capabilities? I've looked all around and been unable to pull out any explanation of this line:

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

  2. kingler
    Member
    Posted 12 years ago #

    Check out the normal WP codex:
    http://codex.wordpress.org/Roles_and_Capabilities

  3. jdwilbur
    Member
    Posted 12 years ago #

    Thanks kingler, but I already read that (and several threads on the wpmu forum dealing with capabilities). None of them help me understand what that string translates into for the system.

    I get how roles and capabilities work, but not how this string communicates that information inside Wordpress.

  4. andrea_r
    Moderator
    Posted 12 years ago #

    More than it being an expression that communicates various values to the database? :)

    you're in there pretty deep; I'm wondering what you need it for.

  5. kingler
    Member
    Posted 12 years ago #

    oh, i missed your point here.

    You can check an user's roles and capacities in the WordPress system by using the following function:

    current_user_can('manage_options')

    Note here 'manage_options' is just one of the capacities. You can also use 'edit_post', and others.

    Also, the roles and capacities are checked by WP internally, when you use add_option_page() and add_submenu_page() functions to add a specific menu page in the backend. The capacity is specified as a parameter.

    Hope it helps.

  6. jdwilbur
    Member
    Posted 12 years ago #

    I think I'm looking more for an explanation of the full string in its various parts. As to why... sort of because I can understand everything else, but this string is thwarting me, so I'm beating my head against the wall. I probably didn't need to know that the s:13 in

    s:13:"administrator";

    just relates to the number of characters in the following word ("administrator"). You can see that if you look at other strings - they'll have something like s:5:"admin", or s:10:"subscriber".

    I still don't know what a:1 refers to, or b:1, but I'm getting the feeling that there is no documentation on it (at all) because most people don't think it's important - just something in WP that we users don't need to concern ourselves with.

  7. andrea_r
    Moderator
    Posted 12 years ago #

    But that sort of thing isn't WP-specific. It's part of database theroy, SQL etc...

    So it's not documented or mention because "most" users don't go digging in the db at that deep of a level.

  8. kingler
    Member
    Posted 12 years ago #

    Oh, you are just too curious about things I guess :)

    Anyway, this is a PHP-thing to encode array into a text string. Check the detail of this function:

    http://php.net/serialize

    a:1 here means following is an array with 1 element.

  9. drmike
    Member
    Posted 12 years ago #

    What's the b stand for then? Gotta admit that I don't understand this either. Have to work this out with the multi sites as you have to copy it over when you add them in.

  10. jdwilbur
    Member
    Posted 12 years ago #

    kingler: perfect. Thanks so much. This is exactly the explanation I was looking for.

    andrea_r: not so much database theory here, as just php language specifics. Makes sense in the end.

    drmike: (from the serialize php page), b = Boolean.

    Boolean
    b:value; (does not store "true" or "false", does store '1' or '0')

    I think we'll notice that all "b:"'s are followed by 1 or 0.

  11. drmike
    Member
    Posted 12 years ago #

    OK, that makes sense. Thanks

About this Topic