Support » Plugin: Editor Menu and Widget Access » Undefined variable: $role

  • Resolved Howdy_McGee

    (@howdy_mcgee)


    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

    (@guyprimavera)

    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

    (@guyprimavera)

    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.

    Thanks.

    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.

    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 2 years, 3 months ago by  Howdy_McGee.

    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

    @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

    (@guyprimavera)

    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

    (@guyprimavera)

    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 2 years, 3 months ago by  GuyPrimavera.

    Just updated to the latest version, everything looks good, no errors in my logs. Thanks for the quick turnaround on this!

    Cheers

    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.