• Resolved zilveer

    (@zilveer)


    Hello,
    is it possible anyhow to hide this plugin for different user roles then admins?

    I could find any capability for this, perhaps I am blind I dont know:)

    Thanks for helping me out!
    regards Zilveer

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Kuba Mikita

    (@kubitomakita)

    Hi @zilveer,

    you can hide it with custom post type capability type.

    Here’s the filter: https://github.com/Kubitomakita/Notification/blob/dev/inc/Notifications.php#L77

    But I don’t feel like I’m the right person to help with capabilities. In a few years of my career, I didn’t manage to do it correctly and in a way which would satisfy me 🙂

    So basically when you will use this filter and provide some other capability name you would need to add all default capabilities to your admin user. Reference: https://codex.wordpress.org/Function_Reference/register_post_type#Arguments (capability_type argument)

    Thread Starter zilveer

    (@zilveer)

    @kubitomakita thanks for replying so quick.

    I cannot find any capability which is created by the plugin? What is its name?

    I use “Role Editor” to manage capabilities and roles.

    It is quite easy, just create a capability, for. i.e “notification_view”, use the following code

    if( !(current_user_can('manage_options') || current_user_can('notification_view'))){
            wp_die('Access Denied');
        }
    //rest of the code for attaching the Notification to the menu"
    

    When this done then I can use “notification_view” capability to check whether or not a user /role should be able to see the menu for Notications 🙂

    EDIT: If I found the capability name I could manage to solve it myself.. but I cannot find any capability for the plugin Notifications :/

    • This reply was modified 7 years ago by zilveer.
    • This reply was modified 7 years ago by zilveer. Reason: edit code
    • This reply was modified 7 years ago by zilveer.
    Plugin Author Kuba Mikita

    (@kubitomakita)

    This wouldn’t work this way @zilveer.

    You can try to add any custom capability and check on admin_init if users have it. If not then die(), but it would not hide the menu.

    Ideal way to achieve this is to use the 7 capabilities WordPress is creating by default (see the reference argument linked above). And Notification use the post capability type by default.

    So any person which can add/edit posts can see the Notifications menu.

    Thread Starter zilveer

    (@zilveer)

    I would add an capability and make sure that the capability is always set to true for the logged in user to get access to the plugin.
    in this way a user role could have an capability added to its role whether or not he/she should be able to add notifications or not.

    as now it is added to default post capabilities, meaning that anyone who can create a post is able to add notifications which is (for me anyway) lack of security.

    I would appreciate if there was a solution on this part soon 🙂

    And once again thanks for your quick replies and your time for this poject! You are doing this awesome!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Capabilities?’ is closed to new replies.