CMS4biz
CMS4biz

Reputation: 19

How to define custom capabilities in wordpress for custom plugin

I create own plugins with their own tables and actions. In these plugins I didn't make use of custom plugins.

However I want to define custom capabilities and roles. I want to base them on the action(url parameter).

Is this possible?

Upvotes: 1

Views: 2432

Answers (2)

Eduardo Aqui
Eduardo Aqui

Reputation: 1

Based on the other answers, I think what you wanna do is to "hook" your custom capability with some actions performed by the user. Example: you create and assign a new capability: "create_events", so your user will be able to create events.

You can create all logic in order to create Events and write a simple check on the user's capability to allow this actions or not. This is useful if you want to show some data or not.

Example:

if (current_user_can("create_events")){
  
  //Do something

}

Upvotes: 0

user7236046
user7236046

Reputation:

Take a look at the Roles & Capabilities in WordPress for a bit more information on what already exists and what they are used for.

Capabilities in WordPress are very basic because when you add a capability to a user, it doesn't actually do anything. It's when you add features that rely on the capability that it starts to have authority on the site.

The add_cap documentation will give you some extra info, however this is how you can add a custom capability to the author role as an example:

$role = get_role( 'author' );
$role->add_cap( 'my_custom_cap' ); 

That's all there is to it. To remove a capability, use remove_cap instead of the add_cap above and it'll remove it properly from the role for you.

Upvotes: 2

Related Questions