Hide Sort Settings interface for certain administrator role users

Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInPrint this page

The Sort Settings interface is available by default only to administrator role users. There are situations when sort settings need to be available only for certain users. The apto/wp-admin/reorder-interface/view-settings-capability filter help on that matter.

The following example hide the sort settings interface if logged-in user is not ID 1 or 2 or 3. This can be extended to check against username, user meta data etc. If not match it should return a capability that current user does not support.

add_filter('apto/wp-admin/reorder-interface/view-settings-capability', 'view_settings_capability');
    function  view_settings_capability($capability)
        {
            $user_ID = get_current_user_id();
            
            if(!in_array($user_ID, array(1, 2, 3)))
                $capability =   '_sort_capability_';
            
            return $capability;   
        }