BuddyBoss Home – Web Support Forums Themes OneSocial theme Show just VENDORS on members page

Viewing 12 posts - 1 through 12 (of 12 total)
  • Question

    #69330
    @conscious-crafties

    Hello,

    Is there a way for me to only display Vendors on my community page here:

    Conscious Crafties Community

    It currently shows customers and other roles, but our community is based around sick and disabled people who love to craft and I’m not sure if our customers are also sick and disabled.

    Many thanks,

    Karen

    Answers

    #69346

    Anonymous
    @

    Hi @conscious-crafties

    You can use some custom codes to hide customers and subscribers

    https://gist.github.com/sbrajesh/2142009

    Regards
    Varun Dubey

    #69529
    @omarobaid

    Hi @conscious-crafties,

    Did you manage to do this?

    I have tried to put the code, below, together but it is not working

    add_action(‘bp_ajax_querystring’,’bpdev_exclude_users’,20,2);
    function bpdev_exclude_users($qs=false,$object=false){
    //list of users to exclude

    if($object!=’members’)//hide for members only
    return $qs;

    $excluded_user=join(‘,’,bpdev_get_subscriber_user_ids(),bpdev_get_customer_user_ids());//comma separated ids of users whom you want to exclude

    $args=wp_parse_args($qs);

    //check if we are searching for friends list etc?, do not exclude in this case
    if(!empty($args[‘user_id’]))
    return $qs;

    if(!empty($args[‘exclude’]))
    $args[‘exclude’]=$args[‘exclude’].’,’.$excluded_user;
    else
    $args[‘exclude’]=$excluded_user;

    $qs=build_query($args);

    return $qs;

    }

    function bpdev_get_user_ids(){
    $users = get_users( array( ‘role__in’ => [‘customer’, ‘subscriber’], ‘fields’ => ‘ID’ ) );
    return $users;
    }

    #69549
    @conscious-crafties

    Hi Omar, was a bit confused by the thread as they made corrections but didn’t put the new code in it’s entirety. I’m very nervous adding code.

    I think we need to change the last line:
    ‘There is a mistake on line 33. It should be return $subscribers not return $users’

    I also wasn’t sure whether to create a copy of custom_buddypress/bp-functions.php somewhere so it doesn’t get overwritten when we have updates.

    Tagging @vapvarun as maybe he can help 🙂

    Karen

    #69689

    Anonymous
    @

    Hi @conscious-crafties @omarobaid
    Following should work fine

    
    add_action('bp_ajax_querystring','bpdev_exclude_users',20,2);
    function bpdev_exclude_users($qs=false,$object=false){
        //list of users to exclude
         
        if($object!='members')//hide for members only
            return $qs;
            
        $excluded_user=join(',',bpdev_get_subscriber_user_ids());//comma separated ids of users whom you want to exclude
      
        
        $args=wp_parse_args($qs);
        
        //check if we are searching for friends list etc?, do not exclude in this case
        if(!empty($args['user_id']))
            return $qs;
        
        if(!empty($args['exclude']))
            $args['exclude']=$args['exclude'].','.$excluded_user;
        else 
            $args['exclude']=$excluded_user;
          
        $qs=build_query($args);
       
       
       return $qs;
        
    }
    
    function bpdev_get_user_ids(){
      $users = get_users( array( 'role__in' => ['customer', 'subscriber'], 'fields' => 'ID' ) );
      return $users;
    }
    
    

    Regards
    Varun Dubey

    #69701
    @omarobaid

    Hi @vapvarun,

    Thnanks for looking into this, but it removes everyone and it shows a blank page.

    #69790
    @conscious-crafties

    Hello,

    Is this where we insert the code @vapvarun:
    custom_buddypress/bp-functions.php

    Worried about adding this now re Omar’s comment above.

    Thank you,

    Karen

    #69792
    @omarobaid

    Hi @conscious-crafties,

    You would actually need to create a new file called bp-custom.php and insert the above code in it.

    You would need to put the file here wp-content/plugins

    But it didn’t work for me as it removed everyone not just customers.

    Let me know if you have a breakthrough

    #69963
    @rummelhoff

    This works better:

    <?php
    
    add_filter( 'bp_after_has_members_parse_args', 'buddydev_exclude_users_by_role' );
    
    function buddydev_exclude_users_by_role( $args ) {
        //do not exclude in admin
        if( is_admin() && ! defined( 'DOING_AJAX' ) ) {
            return $args;
        }
    
        $excluded = isset( $args['exclude'] )? $args['exclude'] : array();
    
        if( !is_array( $excluded ) ) {
            $excluded = explode(',', $excluded );
        }
    
        $role = 'customer';//change to the role to be excluded
        $user_ids =  get_users( array( 'role' => $role ,'fields'=>'ID') );
    
        $excluded = array_merge( $excluded, $user_ids );
    
        $args['exclude'] = $excluded;
    
        return $args;
    }
    #69965
    @omarobaid

    Fantastic, thank you very much, It works perfectly.

    Do you now how to remove admin as well?

    #70213

    Alyssa
    Participant
    @alyssa-buddyboss

    @omarobaid

    <?php
    
    add_filter( 'bp_after_has_members_parse_args', 'buddydev_exclude_users_by_role' );
    
    function buddydev_exclude_users_by_role( $args ) {
        //do not exclude in admin
        if( is_admin() && ! defined( 'DOING_AJAX' ) ) {
            return $args;
        }
    
        $excluded = isset( $args['exclude'] )? $args['exclude'] : array();
    
        if( !is_array( $excluded ) ) {
            $excluded = explode(',', $excluded );
        }
    
        //change 'role' to the role to be excluded
        $user_ids_customer 	=  get_users( array( 'role' => 'customer' 	,'fields'=>'ID') );
        $user_ids_admin 	=  get_users( array( 'role' => 'admin' 		,'fields'=>'ID') );
    
        $excluded = array_merge( $excluded, $user_ids_customer, $user_ids_admin );
    
        $args['exclude'] = $excluded;
    
        return $args;
    }
    #70260

    Alyssa
    Participant
    @alyssa-buddyboss

    This topic has not been active for quite some time and will now be closed.

    Please simply open a new ticket (linking to this one if necessary) if you experience any further trouble, and I’d be happy to investigate further.

    Thanks!

Viewing 12 posts - 1 through 12 (of 12 total)
  • The question ‘Show just VENDORS on members page’ is closed to new replies.