Tushar Imran
Tushar Imran

Reputation: 41

how to update WordPress role capability value

How do I update WordPress user role capability value through the database? i want to add custom capability like as post_limit, then update those post limit value

Below is a screenshot showing the wp_user_roles options;

screenshot wp_user_roles => value (i want to update this unserialized value)

Note: i want to update existing capability value not add_role or remove_role

Upvotes: 0

Views: 1355

Answers (1)

Andrew Schultz
Andrew Schultz

Reputation: 4243

You can create new roles using the command add_role.

add_role( 'custom_role', 'Custom Subscriber', array( 'read' => true, 'level_0' => true ) );

To modify an existing role you would need to remove it first and then add it back in.

 remove_role( 'custom_role' );
 add_role( 'custom_role', 'Custom Subscriber', array( 'read' => true, 'level_0' => true ) );

Be aware that modifying the capabilities array and re-executing add_role() will not necessarily update the role with the new capabilities list. The add_role() function short-circuits if the role already exists in the database.

Upvotes: 1

Related Questions