Change WordPress user roles and capabilities Forums Bug Reports ure_manage_options tied to Administrator visibility

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #4961
    tanner
    Participant

    It seems if I remove the ure_manage_options capability from a Role, that Role is unable to see any Administrator Users in the Users list and unable to assign anyone to the Administrator Role.

    #4968
    Vladimir
    Keymaster

    Right. I explained that URE hides ‘administrator’ role and users with ‘administrator’ role by default from any user without ‘administrator’ role at your previous topic. More – URE hides all users with administrator role from any other user with ‘administrator’ role. This protection measure does not take effect for the WordPress built-in superadmin with ID=1.

    User with ‘ure_manage_options’ capability is a superadmin for User Role Editor. So admin protection does not applied for such user too.

    If you wish to switch this logic off use URE’s custom filter ‘ure_supress_administrators_protection’.

    
    add_filter('ure_supress_administrators_protection', 'switch_off_ure_administrators_protection', 10, 1);
    function switch_off_ure_administrators_protection($supress_protection) {
    
        $supress_protection = true;
        
        return $supress_protection;
    }
    

    Similar topic was discussed at this thread.

    #4973
    tanner
    Participant

    More – URE hides all users with administrator role from any other user with ‘administrator’ role.

    By default, without URE, an administrator user can see all other administrator users. So why is URE blocking the view of other administrator users if they do not have ure_manage_options capability? ure_manage_options is specific to URE.

    #4976
    tanner
    Participant

    I’ve just tried adding

    add_filter('ure_supress_administrators_protection', 'switch_off_ure_administrators_protection', 10, 1);
    function switch_off_ure_administrators_protection($supress_protection) {
    
        $supress_protection = true;
        
        return $supress_protection;
    }

    to the functions.php file for testing gbt it crashes the site.

    #4977
    Vladimir
    Keymaster

    Error messages from the server logs will be useful in this case.
    I made another test – code works without error. You can send your own functions.php to support [at-sign] role-editor.com. I will look what may be wrong with your version.

    #4982
    tanner
    Participant

    Got this to work. It had to do with my use of is_plugin_active. Not sure why that was erroring out but opted in to using if ( defined('URE_VERSION')) instead

    #4985
    Vladimir
    Keymaster

    OK.

    wp-admin/includes/plugin.php may be not loaded at the point you tried to call is_plugin_active(), if you called it beyond function, hooked to the action.

    #5000
    tanner
    Participant

    Not sure if you can help me here, I’ve been getting a ton of PHP warnings:

    [01-Jul-2018 21:54:09 UTC] PHP Warning:  in_array() expects parameter 2 to be array, null given in .../wp-content/mu-plugins/ure-assist/ure-assist.php on line 26
    [01-Jul-2018 21:54:09 UTC] PHP Notice:  Undefined variable: user in .../wp-content/mu-plugins/ure-assist/ure-assist.php on line 26
    [01-Jul-2018 21:54:09 UTC] PHP Notice:  Trying to get property of non-object in .../wp-content/mu-plugins/ure-assist/ure-assist.php on line 26

    This is my MU plugin..

    <?php
    
    if ( is_admin() ) {
        add_action('plugins_loaded', 'ure_loaded');
        function ure_loaded() {
    
            if ( defined('URE_VERSION') ) {
              global $pagenow;
              $user = wp_get_current_user();
    
              if (!in_array('webmaster', $user->roles)){
                
                add_filter('ure_show_additional_capabilities_section', 'ure_show_additional_capabilities_section');
                add_filter('ure_bulk_grant_roles',  'ure_show_additional_capabilities_section');
                 
                function ure_show_additional_capabilities_section($show) {
                    if (in_array('admin', $user->roles) || in_array('administrator', $user->roles)) {
                        $show = false;
                    }
    
                    return $show; 
                }
    
                if ($pagenow == 'users.php') {
                  add_action('admin_enqueue_scripts', 'load_admin_style');
                  function load_admin_style() {
                    wp_register_style('ure-styles', plugins_url( '/css/admin.css', __FILE__ ) );
                    wp_enqueue_style('ure-styles');
                  }
                }
              } elseif (in_array('webmaster', $user->roles)) {
                add_filter('ure_supress_administrators_protection', 'remove_ure_administrator_protection', 10, 1);
                function remove_ure_administrator_protection($supress_protection) {
    
                    $supress_protection = true;
                    
                    return $supress_protection;
                }
    
              }
    
            }
        }
    }

    Any ideas?

    #5001
    Vladimir
    Keymaster

    Variable $user is not defined inside function ure_show_additional_capabilities_section().
    This version will fix the issue:

    
                    function ure_show_additional_capabilities_section($show) {
                        $user = wp_get_current_user();
                        if (in_array('admin', $user->roles) || in_array('administrator', $user->roles)) {
                            $show = false;
                        }
    
                        return $show;
                    }
    
Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.