Title: Undefined variable: $role
Last modified: February 28, 2017

---

# Undefined variable: $role

 *  Resolved [Howdy_McGee](https://wordpress.org/support/users/howdy_mcgee/)
 * (@howdy_mcgee)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/undefined-variable-role/)
 * Not sure when this came up or how it came up but it did. I have this error popping
   up a few times:
 * `PHP Notice: Undefined variable: role in /wp-content/plugins/editor-menu-and-
   widget-access/admin/menus.php on line 13`
 * If for whatever reason ( in theory every user should have roles ) this conditional
   is false:
 * `if ( ! empty( $user->roles ) && is_array( $user->roles ) )`
 * It throws an error. One solution to this would be to just declare $role at above
   the conditional at the top of the function as `$role = false` since it’s checking
   against specific roles. Just a thought, otherwise is a great plugin!

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

 *  Plugin Author [GuyPrimavera](https://wordpress.org/support/users/guyprimavera/)
 * (@guyprimavera)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/undefined-variable-role/#post-8857789)
 * Hi Howdy McGee,
 * Thanks a lot for the detailed feedback, it’s really useful!
 * As luck would have it, I’m getting ready to release an update for this plugin
   later today, so I’ll check that issue out right now before releasing v2.1.
 * Thanks!
 * Guy.
 *  Plugin Author [GuyPrimavera](https://wordpress.org/support/users/guyprimavera/)
 * (@guyprimavera)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/undefined-variable-role/#post-8858661)
 * Hey Mr McGee,
 * I’ve just released a new version of this plugin that should sort the issue. Let
   me know if it happens again, though.
 * [P.S. I left a little note in the code for you.](https://designbymito.com/misc/howdy.jpg)
 * Thanks.
 *  Thread Starter [Howdy_McGee](https://wordpress.org/support/users/howdy_mcgee/)
 * (@howdy_mcgee)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/undefined-variable-role/#post-8858702)
 * Haha thanks! I’ve run into an issue with the update though:
 * `PHP Fatal error: Uncaught Error: Call to a member function remove_cap() on null
   in /wp-content/plugins/editor-menu-and-widget-access/admin/caps.php:38`
 * This is mostly for people not running WooCommerce, the `shop_manager` role won’t
   exist and will thus return [NULL](https://codex.wordpress.org/Function_Reference/get_role).
 * I’ll have to deactivate it for the time being on my site but am confident you’ll
   hotfix it soon!
    -  This reply was modified 9 years, 3 months ago by [Howdy_McGee](https://wordpress.org/support/users/howdy_mcgee/).
 *  [scodal](https://wordpress.org/support/users/scodal/)
 * (@scodal)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/undefined-variable-role/#post-8858778)
 * Just want to add that I’m also suddenly getting the remove_cap() error mentioned
   above. Had to temporarily disable the plugin.
 * I write custom themes, so it’s unlikely that I’m using the same theme as Howdy_McGee
 *  Thread Starter [Howdy_McGee](https://wordpress.org/support/users/howdy_mcgee/)
 * (@howdy_mcgee)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/undefined-variable-role/#post-8858796)
 * [@scodal](https://wordpress.org/support/users/scodal/) If you really need the
   plugin working, you can navigate to
 * `/wp-content/plugins/editor-menu-and-widget-access/admin/caps.php`
 * And replace `$shop_man->remove_cap( $cap );` with:
 *     ```
       if( ! empty( $shop_man ) ) {
       	$shop_man->remove_cap( $cap );
       }
       ```
   
 * Located on line 38. That seems to be the only issue holding up the plugin.
 *  Plugin Author [GuyPrimavera](https://wordpress.org/support/users/guyprimavera/)
 * (@guyprimavera)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/undefined-variable-role/#post-8858813)
 * Thanks McGee, yeah I just noticed the error here too. For now I’ve released a
   temporary v2.2 version to put it back to similar to before, and I’ll get it sorted
   shortly.
 * Thanks!
 *  Plugin Author [GuyPrimavera](https://wordpress.org/support/users/guyprimavera/)
 * (@guyprimavera)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/undefined-variable-role/#post-8858969)
 * Hi guys, I’ve just released v2.3 which should resolve everything, but please 
   let me know if there are any issues. I’ve tested it in 10 different WP installs,
   with and without WooCommerce, so hopefully it’s all good now.
 * Mr McGee, thanks a lot for your help in finding the problem! 🙂
    -  This reply was modified 9 years, 3 months ago by [GuyPrimavera](https://wordpress.org/support/users/guyprimavera/).
 *  Thread Starter [Howdy_McGee](https://wordpress.org/support/users/howdy_mcgee/)
 * (@howdy_mcgee)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/undefined-variable-role/#post-8859004)
 * Just updated to the latest version, everything looks good, no errors in my logs.
   Thanks for the quick turnaround on this!
 * Cheers
 *  [scodal](https://wordpress.org/support/users/scodal/)
 * (@scodal)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/undefined-variable-role/#post-8937545)
 * Wonderful, I’ve updated this plugins in one of my WP installs and everything 
   looks fine so far. Have more WP installs with this plugin to run the update tomorrow.
   I’ll report back. Thanks so much for your hard work and awesome plugin!

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

The topic ‘Undefined variable: $role’ is closed to new replies.

 * ![](https://ps.w.org/editor-menu-and-widget-access/assets/icon-256x256.png?rev
   =1200053)
 * [Editor Menu and Widget Access](https://wordpress.org/plugins/editor-menu-and-widget-access/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/editor-menu-and-widget-access/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/editor-menu-and-widget-access/)
 * [Active Topics](https://wordpress.org/support/plugin/editor-menu-and-widget-access/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/editor-menu-and-widget-access/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/editor-menu-and-widget-access/reviews/)

 * 9 replies
 * 3 participants
 * Last reply from: [scodal](https://wordpress.org/support/users/scodal/)
 * Last activity: [9 years, 3 months ago](https://wordpress.org/support/topic/undefined-variable-role/#post-8937545)
 * Status: resolved