• Resolved rthaena

    (@rthaena)


    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 2 years, 6 months ago by rthaena.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Gerard Blanco

    (@sixaxis)

    Hi @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

    (@rthaena)

    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 2 years, 5 months ago by rthaena.
    Plugin Support Gerard Blanco

    (@sixaxis)

    Hi @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.