Results 1 to 5 of 5

Thread: Custom Capabilities - How??

  1. #1
    leewillis77 is offline Hello World
    Join Date
    Oct 2010
    Posts
    22

    Icon5 Custom Capabilities - How??

    I have a plugin that offers certain bits of functionality. For most sites this should be restricted to only some users.

    Currently, my plugin limits the functionality to administrators using:

    Code:
    if (current_user_can('manage_options')) {
    Ideally I'd like to leave this as a default (It works for most people). However I'd really like to have a custom capability so that people can assign this to users (Or roles) that they want to be able to use the functionality.

    I've read a few articles, but none of them really seem to explain this.

    Currently, I'm thinking of using something like this:

    Code:
    if (current_user_can('manage_options') || current_use_can('do_my_plugin_stuff') ) {
    So that the standard case works, but also people would be able to assign the capability 'do_my_plugin_stuff' to roles they want to be able to do stuff.

    Is that it? Do I need to register the capability as well? How do people actually assign this capability - do they need to use something like the "Role Manager" plugin?

  2. #2
    Jeffro's Avatar
    Jeffro is offline WPTavern Forum Admin
    Join Date
    Jan 2009
    Location
    Ohio
    Posts
    2,359

    Default

    I would take a look at http://wordpress.org/extend/plugins/members/ because I think it enables you to create news roles and assign them.

  3. #3
    leewillis77 is offline Hello World
    Join Date
    Oct 2010
    Posts
    22

    Default

    Thanks - I'll take a look...

  4. #4
    greenshady's Avatar
    greenshady is offline Here For The Peanuts
    Join Date
    Jan 2009
    Posts
    170

    Default

    You can also apply filters to this to allow it to be changed:

    PHP Code:
    current_user_canapply_filters'my_plugin_capability_check''manage_options' ) ) 
    Or, you can set a custom capability to the administrator role on the plugin activation hook and just a check like:

    PHP Code:
    current_user_can'do_cool_stuff' 
    Users would still need a plugin like "Members" to assign this cap to others though.

  5. #5
    leewillis77 is offline Hello World
    Join Date
    Oct 2010
    Posts
    22

    Default

    Perfect, tested out some of these with the members plugin and everything works just great!

    Thanks for all the advice everyone!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •