Skip to:
Content
Pages
Categories
Search
Top
Bottom

Member Total when excluding subscribers


  • Pamela
    Participant

    @infoknutsford-softwarecouk

    I have this code in functions.php to exclude subscribers

    
    
    add_action('bp_ajax_querystring','bpdev_exclude_users', 20, 2 );
    
    function bpdev_exclude_users($qs=false,$object=false){
    	global $bp;
    	global $members_template;
     	if ($object != 'members') {		
     		return $qs;
    	}
    	
    	$subscribers = get_users('role=subscriber');
    		
    	$exclude = "";
    	foreach ($subscribers as $subscriber) {
    		if (trim($exclude) != "") {
    			$exclude = $exclude . ",";
    		}
    		$exclude = $exclude . $subscriber -> ID;		
    	}
    	
    	$args['exclude'] = $exclude; 	
     	$qs = build_query($args);
     return $qs;
     
    }
    
    

    The problem is that the pagination now doesn’t work on the members page. The total includes the subscribers which I presume is also why the pagination page links don’t work. How do I change the total number of members for the pagination so that it works. Thanks

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

  • shanebp
    Moderator

    @shanebp

    Try using the bp_pre_user_query_construct hook
    codex example


    Pamela
    Participant

    @infoknutsford-softwarecouk

    I have now added my own to functions.php which shows the correct counts but the links still don’t work and I have no idea why. When you click on them it always come up with page 1

    
    function members_pagination_count() {
    		echo get_members_pagination_count();
    	}
    	
    	function get_members_pagination_count() {
    		global $members_template;
    		global $count_of_excluded_members;
    		if ( empty( $members_template->type ) )
    			$members_template->type = '';
    		$page_arg = "upage";
    		$page_number = 1;
    		$per_page = 20;
    		$pag_page = !empty( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[$page_arg] ) : (int) $page_number;
    		$pag_num  = !empty( $_REQUEST['num'] )   ? intval( $_REQUEST['num'] )   : (int) $per_page;
    		$start_num = intval( ( $pag_page - 1 ) * $pag_num ) + 1;
    		$from_num  = bp_core_number_format( $start_num );
    		$to_num    = bp_core_number_format( ( $start_num + ( $pag_num - 1 ) > ($members_template->total_member_count - $count_of_excluded_members) ) ? ($members_template->total_member_count - $count_of_excluded_members) : $start_num + ( $pag_num - 1 ) );		
    		$total     = bp_core_number_format( $members_template->total_member_count - $count_of_excluded_members );
    
    		if ( 'active' == $members_template->type )
    			$pag = sprintf( _n( 'Viewing member %1$s to %2$s (of %3$s active member)', 'Viewing member %1$s to %2$s (of %3$s active members)', $total, 'buddypress' ), $from_num, $to_num, $total );
    		else if ( 'popular' == $members_template->type )
    			$pag = sprintf( _n( 'Viewing member %1$s to %2$s (of %3$s member with friends)', 'Viewing member %1$s to %2$s (of %3$s members with friends)', $total, 'buddypress' ), $from_num, $to_num, $total );
    		else if ( 'online' == $members_template->type )
    			$pag = sprintf( _n( 'Viewing member %1$s to %2$s (of %3$s member online)', 'Viewing member %1$s to %2$s (of %3$s members online)', $total, 'buddypress' ), $from_num, $to_num, $total );
    		else
    			$pag = sprintf( _n( 'Viewing member %1$s to %2$s (of %3$s member)', 'Viewing member %1$s to %2$s (of %3$s members)', $total, 'buddypress' ), $from_num, $to_num, $total );
    
    		return apply_filters( 'members_pagination_count', $pag );
    	}
    	
    	function members_pagination_links() {
    		echo get_members_pagination_links();
    	}
    	
    	function get_members_pagination_links() {
    		global $members_template;
    		$page_arg = "upage";
    		$page_number = 1;
    		$per_page = 20;
    		$pag_page = !empty( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[$page_arg] ) : (int) $page_number;
    		
    		$pag_num  = !empty( $_REQUEST['num'] )   ? intval( $_REQUEST['num'] )   : (int) $per_page;
    		$pag_links = paginate_links( array(
    				'base'      => add_query_arg( $page_arg, '%#%' ),
    				'format'    => '',
    				'total'     => ceil( ((int) $members_template->total_member_count - (int)$count_of_excluded_members) / (int) $pag_num ),
    				'current'   => (int) $pag_page,
    				'prev_text' => _x( '←', 'Member pagination previous text', 'buddypress' ),
    				'next_text' => _x( '→', 'Member pagination next text', 'buddypress' ),
    				'mid_size'   => 1
    			) );
    
    		return apply_filters( 'get_members_pagination_links', $pag_links );
    	}
    

    This is the page

    http://www.ibsregister.com/members/

    They look OK and I haven’t seen any JavaScript errors


    Pamela
    Participant

    @infoknutsford-softwarecouk

    OOps it is now working. I had missed out $args = wp_parse_args($qs); when doing the exclude for the subscriber role

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Member Total when excluding subscribers’ is closed to new replies.
Skip to toolbar