Skip to:
Content
Pages
Categories
Search
Top
Bottom

WooCommerce Hiding Admin Bar for bbPress Moderators


  • samtime
    Participant

    @samtime

    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,
    Sam

    WordPress 5.5.1
    bbPress 2.6.5
    WooCommerce 4.6.1

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

  • Robin W
    Moderator

    @robin-w

    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


    samtime
    Participant

    @samtime

    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,
    Sam

    Here’s the website btw:
    https://funkytime.tv/forums/


    Robin W
    Moderator

    @robin-w

    ok, one I think for woocommerce to respond.


    samtime
    Participant

    @samtime

    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;
    }

    Robin W
    Moderator

    @robin-w

    great – thanks for posting the solution – glad you are fixed

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar