Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am new to wordpress, in table wp_usermeta I notice that we have a row

meta_key                meta_value
wp_capabilities       a:1:{s:13:"administrator";b:1;}

First, what's the meaning of meta_value a:1:{s:13:"administrator";b:1;} , where can I found the exactly explanation of this filed ? Or I what to know all about the role user Capabilities , where can I get these information.

Second, how can I create new roles via wordpress's API by code

Thanks in advanced.

share|improve this question

4 Answers 4

up vote 1 down vote accepted

The wp_capabilities saves the value as serilized array, you can try it in your php or for this example here: http://blog.tanist.co.uk/files/unserialize/.

The Code:

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

Is:

Array
(
   [administrator] => 1
)

Meaning the user is an administrator.

You can add new roles to the database by running the function add_role, and only run it once!

share|improve this answer

meta_value is column to store value of meta field. Each meta_field contains key and value.

I think this Codex article about roles and capabilities should help you: http://codex.wordpress.org/Roles_and_Capabilities

To add custom roles you should use add_role function (http://codex.wordpress.org/Function_Reference/add_role)

And sample of using it from Codex:

$result = add_role('basic_contributor', 'Basic Contributor', array(
    'read' => true, // True allows that capability
    'edit_posts' => true,
    'delete_posts' => false, // Use false to explicitly deny
));
if (null !== $result) {
    echo 'Yay!  New role created!';
} else {
    echo 'Oh... the basic_contributor role already exists.';
}
share|improve this answer

In addition to @Krysiek's answer, you should know that the data stored in the meta tables, including user metadata, is often serialized. If you'd like to know what the data actually represents, you can use the PHP function unserialize to determine it's value. For example, running the value a:1:{s:13:"administrator";b:1;} through unserialize (and then var_dump-ing the results) products this:

array(1) {
    ["administrator"]=>
    bool(true)
}

You will find the same sorts of entries in the options table as well as the post_meta table.

However, you should avoid writing to these tables directly. There are WordPress functions that allow you to store and access data about users. For example, to read data from the user meta table, you should use get_user_meta and to write you should use the WordPress function update_user_meta. Similar functions exist for post_meta and options tables.

share|improve this answer

In wp_usermeta table we can save the extra information related to a user while we creating a new user or we update a profile of existing user.

In wp_usermeta table there is a column name meta_key where we can save the value through which we can get or update the value of that field for example

Role is like access policy given to a user that he has only that much of access in the website.You can add, remove a role.

Capabilities is like adding features or restricting a role. For example there are 2 role 'gold-role', 'platinum-role'. We are restrict 'gold-role' that he can onlu add post but not publish the post but to 'platinum-role' we adding a feature that he can publish a post. We can also add or remove capability related to a role. You can also add restriction on metaboxes of posts.

For more information follow Role and Capabilities

You can add a role and set its capabilities via wordpress API or You can use plugins to do this. In my opinion Advanced Access Manager is best plugin for handling of Role and Capabilities.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.