WordPress.org

Ready to get started?Download WordPress

Forums

User Role Editor
[resolved] How do I figure out how to add a plugin's capability? (14 posts)

  1. Jason Koning
    Member
    Posted 1 year ago #

    Hi there,
    I'd like to add the Redirection plugin to the Editor role, & I have no idea where/how to find out what the string would be for this.
    For example, one of the TablePress one's is;

    tablepress_edit_tables

    Can you give me any pointers where I might look?
    Many thanks,
    Jas

    http://wordpress.org/extend/plugins/user-role-editor/

  2. Vladimir Garagulya
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Jason,

    Send here the link to that plugin. I will look on it.

    Regards,
    Vladimir.

  3. Jason Koning
    Member
    Posted 1 year ago #

    Hi Vladimir,
    The plugin I'm referring to is;
    http://wordpress.org/extend/plugins/redirection/
    Many thanks,
    Jas

  4. Vladimir Garagulya
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Jason,

    Redirection plugin uses 'Administrator' role to define access level to its menu. You can see it at line #120 of file redirection.php

    function admin_menu() {
      	add_management_page( __( "Redirection", 'redirection' ), __( "Redirection", 'redirection' ), "administrator", basename( __FILE__ ), array( &$this, "admin_screen" ) );
    	}

    Change 'administrator' there to the 'editor' and all your editors will have access to this plugin. Just be aware, that you lose this modification with every plugin update. Other way to achieve this is a plugin like the 'Admin Menu Editor', which is capable to modify admin menu permission on the fly according to your settings.

    Regards,
    Vladimir.

  5. Jason Koning
    Member
    Posted 1 year ago #

    Hi Vladimir,
    The 'Admin Menu Editor' looks like a great option - thanks heaps for your help!
    Jas

  6. Josh Fialkoff
    Member
    Posted 1 year ago #

    How can this be done without editing the plugin file? I would like to make sure that the plugin can be updated by a non-technical user who doesn't know how to edit plugin files.

  7. Vladimir Garagulya
    Member
    Plugin Author

    Posted 1 year ago #

    Look on a plugin like the 'Admin Menu Editor', which is capable to modify admin menu permission on the fly according to your settings. Create your own custom capability with User Role Editor, assign it to the role or selected user. Then change selected menu item capability to your custom created one using Admin Menu Editor.

  8. Josh Fialkoff
    Member
    Posted 1 year ago #

    Thanks!
    I am using User Role Editor.
    I see how to make a new Capability, but I do not see how to edit the functionality of that capability.
    I am looking at your post: http://shinephp.com/user-role-editor-wordpress-plugin/#faq
    Thanks again for your help.
    -Josh

  9. Vladimir Garagulya
    Member
    Plugin Author

    Posted 1 year ago #

    It's the subject of some coding.
    Search for 'current_user_can' at the post you mentioned above.

  10. Josh Fialkoff
    Member
    Posted 1 year ago #

    Thanks!
    I added this, but it is not working:

    //Giving Editors Access to Redirection plugin
    function admin_menu() {
      	add_management_page( __( "Redirection", 'redirection' ), __( "Redirection", 'redirection' ), "editor", basename( __FILE__ ), array( &$this, "admin_screen" ) );
    	}
    
    //Add Redirection capability through User Role Editor plugin
     if (!current_user_can('Redirection')) {
       echo "You don't have permission for it!";
       return;
     }
  11. Vladimir Garagulya
    Member
    Plugin Author

    Posted 1 year ago #

    Sorry, It can not work at all.

    function admin_menu() is a method of class at the plugin, which permission you wish to modify.
    You can not just take out method from the class, put it somewhere else and wait that it will work.
    'this' at array( &$this, "admin_screen" ) is the reference to the plugin PHP object. Your theme functions.php know nothing about it.

    Code fragment from my post is useful if you place it to your own plugin or prevent user from use some functionality. In this case it is useless.

    Please think, if it could be possible to achieve your goal just placing 3-5 lines of code to the functions.php, why I didn't share this information with you?
    Because of I with my knowledge of PHP and WordPress API do not know how to do it without modifying plugin code directly or use other plugin, created especially for that.
    Thanks for your interest and using User Role Editor.

  12. Josh Fialkoff
    Member
    Posted 1 year ago #

    Thanks. That makes sense. ;-)
    So there is not an easy way to achieve this goal?

  13. Vladimir Garagulya
    Member
    Plugin Author

    Posted 1 year ago #

    Yes, without plugin code modification - No. Excuse me for the wordplay ;).

  14. Josh Fialkoff
    Member
    Posted 1 year ago #

    That's okay. Your English is much better than my Russian! Thanks for your help.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.