Skip to:
Content
Pages
Categories
Search
Top
Bottom

Exclude certain member role from member list and non logged in users


  • emptypack
    Participant

    @emptypack

    Hello, I wanted to ask, how can I exclude certain member role from showing on member list and be redirected to “wp-login” when non logged visitors try to access their profile.

      For first task, I use this code to exclude certain user ID from beeing in member list (but this code need modification to accept certain role and don’t show those member just for non logged visitors)

      function bpdev_exclude_users($qs=false,$object=false){
          
          $excluded_user='1'; // Id's to remove, separated by comma
      	
          if($object != 'members' && $object != 'friends')// hide admin to members & friends 
          return $qs;
      	
          $args=wp_parse_args($qs);
      
          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;
      	
      }
      add_action('bp_ajax_querystring','bpdev_exclude_users',20,2);
      
      // once admin is removed, we must recount the members !
      function bpfr_hide_get_total_filter($count){
          return $count-1;
      }
      add_filter('bp_get_total_member_count','bpfr_hide_get_total_filter');
      For second task, I use this code but I dont know how to select certain member role{

      function nonreg_visitor_redirect() {
      global $bp;
      if ( bp_is_user() && !is_super_admin() ) {
      if(!is_user_logged_in()) { //just a visitor and not logged in
      wp_redirect( get_option('siteurl') . '/wp-login.php' );
      }
      }
      }
      add_filter('get_header','nonreg_visitor_redirect',1);
  • You must be logged in to reply to this topic.
Skip to toolbar