Viewing 15 replies - 1 through 15 (of 23 total)
  • Plugin Author Vladimir Garagulya

    (@shinephp)

    In order to add new capability, open “User Role Editor”, click “Add Capability” button, input capability ID and it will be added.
    But in order new capability start to work in should be used by theme or plugin. For example, somewhere in the code should be the fragment similar to

    if ( !current_user_can('new_added_capability') )  {
        echo 'You have no enough permissions';
        die;
    }

    or menu items definition code, like add_menu_page() or add_submenu_page(), where user capability is one of parameters.
    https://codex.www.ads-software.com/Function_Reference/add_menu_page

    If plugin uses some custom capability, it adds that capability automatically and you should see it at the “User Role Editor”. If you are not sure what capability plugin uses, you may read plugin source code and check what capability it uses for its menus.
    Other way to see capabilities used to protect plugin menu items is User Role Editor Pro (https://role-editor.com) admin menu blocking module, look on example with WooCommerce plugin at the screenshot attached.
    https://role-editor.com/downloads/support/ure-plugin-menu-capabilities.png

    Thread Starter gnosis_wp

    (@gnosis_wordpress)

    where is the capability ID obtained?

    Plugin Author Vladimir Garagulya

    (@shinephp)

    When you wish to know what capabilities are used by some plugin you may:
    1) find that in plugin documentation (if available);
    2) analyze plugin source code – i mentioned already the key words to pay attention: curren_user_can(), add_menu_page(), add_submenu_page()
    3) User Role Editor Pro may show what capability was assigned to protect what menu item.

    Thread Starter gnosis_wp

    (@gnosis_wordpress)

    I see add_menu_page:
    function add_plugin_page(){
    add_menu_page( ‘Announcement Bar’, ‘Announcement Bar’, ‘manage_options’, ‘announcement-bar’, array( $this, ‘create_admin_page’), plugins_url( ‘announcement-bar/themify/img/favicon.png’ ) );

    add_menu_page(‘themify’, $theme->display(‘Name’), ‘manage_options’, ‘themify’, ‘themify_page’, get_template_directory_uri().’/themify/img/favicon.png’, 50);

    and add_submenu_page:
    add_submenu_page(‘themify’, $theme->display(‘Name’), __(‘Settings’, ‘themify’), ‘manage_options’, ‘themify’, ‘themify_page’);
    add_submenu_page(‘themify’, $theme->display(‘Name’), __(‘Documentation’, ‘themify’), ‘manage_options’, ‘themify_docs’,

    So i assume, the capability is manage options and themify docs?

    Plugin Author Vladimir Garagulya

    (@shinephp)

    The capability is ‘manage_options’ in all cases.

    i am using Expire Users plugin to set expiry for my clients sites subscriber. i am seeing it find for administrator but i have another user role admin where i want to see those functionality but its just showing titles and when i click edit nothing happenes. can you let me know what capability i need to add as there are more than 10 files in expire users plugin and i dont know how to apply above method.

    check screenshot for what it should look like and how its looking now.

    it looks like this
    https://s12.postimg.org/5roqptwjx/for_limited_access_user.png

    what capability i should add so it will look like below,
    https://s21.postimg.org/7wesnkskn/this_is_how_admin_sees.png

    Plugin Author Vladimir Garagulya

    (@shinephp)

    I can not repeat the situation from your screenshots.
    Limited user with ‘read’, ‘list_users’, ‘edit_users’ capabilities sees at other user profiles all the same options from ‘Expire Users’ as the administrator does.
    It is confirmed by source code:

    function current_expire_user_can( $cap ) {
    		switch ( $cap ) {
    			case 'expire_users_edit':
    				return current_user_can( 'add_users' ) || current_user_can( 'create_users' ) || current_user_can( 'edit_users' ) || current_user_can( 'manage_network_users' ) ? true : false;
    		}
    		return false;
    	}

    This function is used to check if show full version or the limited one:

    $can_edit_profile_expiry = $this->current_expire_user_can( 'expire_users_edit' );

    thanks a lot vladimir for your quick response. actually i also tried assigning all the capabilities including the once you mentioned above but no luck . so i think i must need to add new capability. if you can help me with that please.

    Plugin Author Vladimir Garagulya

    (@shinephp)

    Plugin does not use any new capability.
    Did you tried to deactivate temporarily all other plugins (on case there is a conflict with some code)?
    Is it WordPress multi-site? What version of WordPress do you use?

    nope wordpress is not multisite. i am using 3.9.2 and i tried deactivating other plugins as well but didnt worked out. ??

    Plugin Author Vladimir Garagulya

    (@shinephp)

    SO you still never say where the ID actually is. Is this ID a number or text. Give me an example of what the ID should be for the example gnosis_wp gave above.

    Many thanks,
    Houston

    Plugin Author Vladimir Garagulya

    (@shinephp)

    To @htown: Example is there. My answer for the @gnosis_wp
    https://www.ads-software.com/support/topic/user-role-editorhow-to-add-a-capability-not-listed?replies=13#post-5668847
    contains the answer for his example: ‘manage_options’.
    Functions calls which you may check for what capability is in use for the plugin are listed above. Every function parameters are described at WordPress Codex, like this:
    https://codex.www.ads-software.com/Function_Reference/add_submenu_page

    I guess I am still really confused where to find this ID in a specific plugin. I am using one called Tabulizer. When i go to that plugin and edit it, there are lots of files. I have no idea which one to check to look for this information. Surely there is a better way. Is this where I am supposed to go and look for this evasive ID?

    So in the end, in gnosis_wp example, this is what would go in the add capability field?
    https://grab.by/DDMg

    Many thanks,
    Houston

    Plugin Author Vladimir Garagulya

    (@shinephp)

    General way with source code reading:
    1) extract plugin files to the local disk
    2) use any search tool to find files with name of listed menu functions (add_submenu, etc.) inside.
    3) Look on the code at those files for the capability parameter at plugin menu items creation functions call.

    I did not find a Tabulizer plugin in WP repository.

    One of more easy ways – use Admin access add-on to the Pro version of User Role Editor:
    https://www.role-editor.com/block-wordpress-admin-menu-items/

    gnosis_wp example: almost right, except ‘manage_options’ is a WP built-in capability. There is no need to add it manually, as it exists already.

Viewing 15 replies - 1 through 15 (of 23 total)
  • The topic ‘User Role Editor=>how to add a capability not listed?’ is closed to new replies.