Skip to:
Content
Pages
Categories
Search
Top
Bottom

Widget build from scratch causes issues when displayed in front of other widgets


  • DurdenBlog
    Participant

    @durdenblog

    Hi all,

    I really need help. I can not find the bug by myself. I am creating a custom widget to be able to display on the homepage of my site the groups a user is a member of (whether the group is hidden or not).

    I managed to retrieve the groups and their avatar and then display them in the widget. Everything works well but as soon as I want to place it in front of others, there are display bugs. The other widgets fit in my widget!

    Here is the code I wrote in my functions.php :

    // Display groups a user is member of + linked
    function user_group_memberships( $user_id = null, $show_hidden = false ) {
    
    	$group_ids = groups_get_user_groups($user_id);
    	$i = 1;
    	$visible_group_ids = array();
    	
    	foreach($group_ids["groups"] as $group_id) { 
    		if (!$show_hidden) {
    			if(groups_get_group(array( 'group_id' => $group_id )) -> status !== 'hidden') {
    			$visible_group_ids[] = $group_id;
    			}
    		} else {
    		$visible_group_ids[] = $group_id;
    		}
    	}
    	
    	if (empty($visible_group_ids)) {
    		echo 'None';
    	} else {
    		echo '<ul id="" class="" aria-live="polite" aria-relevant="all" aria-atomic="true">';
    		foreach($visible_group_ids as $visible_group_id) {
    	
    			$avatar = bp_core_fetch_avatar( array(
    				'item_id' => $visible_group_id,
    				'object' => 'group',
    				'type' => $type,
    				'avatar_dir' => 'group-avatars',
    				'alt' => $alt,
    				'css_id' => $id,
    				'class' => 'avatar',
    				'width' => $width,
    				'height' => $height
    				));
    				?>
    				<li class="odd public is-member group-has-avatar">
    					<div class="item-avatar">
    						<a href="' <?php echo home_url() . '/groups/' . groups_get_group(array( 'group_id' => $visible_group_id )) -> slug ?>'"><?php echo $avatar ?></a>
    					</div>
    					<div class="item">
    						<div class="item-title">
    							<a href="' <?php echo home_url() . '/groups/' . groups_get_group(array( 'group_id' => $visible_group_id )) -> slug ?>'"><?php echo groups_get_group(array( 'group_id' => $visible_group_id )) -> name ?></a><?php echo (end($visible_group_ids) == $visible_group_id ? '' : ' ' )?>
    						</div>
    					</div>
    				</li>			
    			<?php if ($i++ == 3) break;
    		}
    		echo '</ul>';
    	}
    }

    And here the code I use in my Widget :
    return user_group_memberships(get_current_user_id(), true);

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