WooCommerce Hiding Admin Bar for bbPress Moderators
-
Hi,
After updating WooCommerce to the latest version (4.6.1), the plugin is now hiding the WordPress admin bar for bbPress moderators and keymasters. Making it harder for them to moderate the forums.The following code in my functions.php file used to resolve the issue, however it no longer works:
add_action('init', function(){ if(class_exists('WooCommerce') && function_exists('bbp_get_user_role') && is_user_logged_in()){ $current_user = wp_get_current_user(); $user_id = $current_user->ID; $bbp_get_user_role = bbp_get_user_role($user_id); if($bbp_get_user_role == 'bbp_keymaster' || $bbp_get_user_role == 'bbp_moderator'){ add_filter( 'woocommerce_prevent_admin_access', '__return_false' ); add_filter( 'woocommerce_disable_admin_bar', '__return_false' ); } } });
I posted this question to the WooCommerce forums and am also posting it here in case anyone else is having similar problems?
Any help or ideas greatly appreciated.
Thank you,
SamWordPress 5.5.1
bbPress 2.6.5
WooCommerce 4.6.1
-
ok, a couple of thoughts just looking at that code
The first would be to break it into a function, nested stuff can sometimes fail so
add_action('init', 'rew_check_bbpress_moderator') ; function rew_check_bbpress_moderator(){ if(class_exists('WooCommerce') && function_exists('bbp_get_user_role') && is_user_logged_in()){ $current_user = wp_get_current_user(); $user_id = $current_user->ID; $bbp_get_user_role = bbp_get_user_role($user_id); if($bbp_get_user_role == 'bbp_keymaster' || $bbp_get_user_role == 'bbp_moderator'){ add_filter( 'woocommerce_prevent_admin_access', '__return_false' ); add_filter( 'woocommerce_disable_admin_bar', '__return_false' ); } } }
Secondly I think woocommerce is all lower case so
if(class_exists('WooCommerce')
might need to read
if(class_exists('woocommerce')
Let us know if either of these help
Hi Robin, thank you for the code.
I replaced my existing code with what you pasted here, unfortunately it didn’t fix the issue.
Tried replacing the “WooCommerce” part with “woocommerce”, but still no luck.Thanks for the reply. If you have any other ideas, it would be greatly appreciated.
I’ll keep searching.Thanks again,
SamHere’s the website btw:
https://funkytime.tv/forums/ok, one I think for woocommerce to respond.
Okay, got the following solution from a friend and it seems to work!
Posting the updated code here incase others have the same problem:add_filter('woocommerce_disable_admin_bar', '_wc_disable_admin_bar', 10, 1); function _wc_disable_admin_bar($prevent_admin_access) { if (!current_user_can("keymaster") && !current_user_can("bbp_moderator") ) { return $prevent_admin_access; } return false; }
great – thanks for posting the solution – glad you are fixed
- You must be logged in to reply to this topic.