Title: User roles returning empty
Last modified: September 14, 2022

---

# User roles returning empty

 *  Resolved [rthaena](https://wordpress.org/support/users/rthaena/)
 * (@rthaena)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/user-roles-returning-empty/)
 * After the plugin update to version 5.0.9, there’s been an issue related to the
   user role array which comes from the ‘wp_get_current_user()’ function. I am getting
   an empty array of user roles which is causing an error on my website.
    This issue
   does not occur while using the plugin version 4.12.2. Would you be able to provide
   some additional information on why this might be happening?
 * The below are the partial snippets of when I var_dump() the ‘wp_get_current_user()’.
 * Newer version of the plugin (5.0.9)
 *     ```
        public $caps =>
         array(2) {
           'administrator' =>
           bool(true)
           'business_owner' =>
           bool(true)
         }
         public $cap_key =>
         string(15) "wp_capabilities"
         public $roles =>
         array(0) {
         }
         public $allcaps =>
         array(2) {
           'administrator' =>
           bool(true)
           'business_owner' =>
           bool(true)
         }
       ```
   
 * Older version of the plugin (4.12.2):
 *     ```
        public $caps =>
         array(2) {
           'administrator' =>
           bool(true)
           'business_owner' =>
           bool(true)
         }
         public $cap_key =>
         string(15) "wp_capabilities"
         public $roles =>
         array(2) {
           [0] =>
           string(13) "administrator"
           [1] =>
           string(14) "business_owner"
         }
       ```
   
    -  This topic was modified 3 years, 8 months ago by [rthaena](https://wordpress.org/support/users/rthaena/).

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Gerard Blanco](https://wordpress.org/support/users/sixaxis/)
 * (@sixaxis)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/user-roles-returning-empty/#post-16008080)
 * Hi [@rthaena](https://wordpress.org/support/users/rthaena/),
 * Thank you for your message, I’m sorry to hear about this issue! 🙁
 * The best way to solve this is to find if there is a possible conflict between
   ShortPixel and other plugins.
 * Could you please run a quick test? Please do the following:
 * – Deactivate all plugins except ShortPixel.
    – Activate all plugins, one by one.–
   After each single activation, check if the issue still happens. This will help
   you identify what plugin causes this (if it is indeed another plugin).
 * If that doesn’t help, please let us know.
 * Thank you,
 *  Thread Starter [rthaena](https://wordpress.org/support/users/rthaena/)
 * (@rthaena)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/user-roles-returning-empty/#post-16009893)
 * Hi,
 * Thank you for your response.
 * I have already run those tests and also tried downgrading the WordPress core 
   version, but none of those tests worked. Also, there is only one other plugin
   on the website which is the Classic Editor plugin so I think that the possibility
   of the issue coming from any conflicts between plugins is unlikely.
 * Only when I upgrade the ShortPixel plugin, I notice the function returns an empty
   array of $roles.
 * Please let me know if I can provide any more information or help with further
   testing. Thank you!
    -  This reply was modified 3 years, 8 months ago by [rthaena](https://wordpress.org/support/users/rthaena/).
 *  [Gerard Blanco](https://wordpress.org/support/users/sixaxis/)
 * (@sixaxis)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/user-roles-returning-empty/#post-16020305)
 * Hi [@rthaena](https://wordpress.org/support/users/rthaena/),
 * Unfortunately we are unable to reproduce the issue. In general, ShortPixel doesn’t
   do much with the user roles, only checks permissions on a few things. But we 
   never change them or hook into any user filters.
 * I can see that one of the roles is “business_owner”, which is not a standard 
   WordPress role, so we think that your installation must have something hardcoded
   altering those results?
 * I therefore have a few more questions, that maybe will help you find out where
   the issue is:
    - Where or when are you calling the `wp_get_current_user()` function?
    - What’s the code you are using?
    - Are you calling it early in the init process
    - Is the problem occurring on the frontend, backend, or both?
    - Is the same issue happening on a new test installation? You can test it on
      tastewp.com
 * Best,

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘User roles returning empty’ is closed to new replies.

 * ![](https://ps.w.org/shortpixel-image-optimiser/assets/icon-256x256.gif?rev=3245715)
 * [ShortPixel Image Optimizer - Optimize Images, Convert WebP & AVIF](https://wordpress.org/plugins/shortpixel-image-optimiser/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/shortpixel-image-optimiser/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/shortpixel-image-optimiser/)
 * [Active Topics](https://wordpress.org/support/plugin/shortpixel-image-optimiser/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/shortpixel-image-optimiser/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/shortpixel-image-optimiser/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Gerard Blanco](https://wordpress.org/support/users/sixaxis/)
 * Last activity: [3 years, 7 months ago](https://wordpress.org/support/topic/user-roles-returning-empty/#post-16020305)
 * Status: resolved