BP_Core_Follow_Following_Widget::widget( $args,  $instance )

Displays the widget.

Description

Source

File: bp-core/classes/class-bp-core-follow-following-widget.php

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
function widget( $args, $instance ) {
    // do not do anything if user isn't logged in
    if ( ! is_user_logged_in() )
        return;
 
    if ( empty( $instance['max_users'] ) ) {
        $instance['max_users'] = 15;
    }
 
    // logged-in user isn't following anyone, so stop!
    if ( ! $following = bp_get_following_ids( array( 'user_id' => bp_loggedin_user_id() ) ) ) {
        return false;
    }
     
    $following_ids = bp_get_following_ids( array( 'user_id' => bp_loggedin_user_id() ) );
    $following_array = explode(",", $following_ids);
    $following_count = '<span class="widget-num-count">' . count($following_array) . '</span>';
    $following_count_number = count($following_array);
 
    // show the users the logged-in user is following
    if ( bp_has_members( array(
        'include'         => $following,
        'max'             => $instance['max_users'],
        'populate_extras' => false,
    ) ) ) {
        do_action( 'bp_before_following_widget' );
 
        echo $args['before_widget'];
        echo $args['before_title']
           . $instance['title']
           . $following_count
           . $args['after_title'];
?>
 
        <div class="avatar-block">
            <?php while ( bp_members() ) : bp_the_member(); ?>
                <div class="item-avatar">
                    <a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_avatar() ?></a>
                </div>
            <?php endwhile; ?>
        </div>
        <?php if ( $following_count_number> $instance['max_users'] ) { ?>
            <div class="more-block"><a href="<?php bp_members_directory_permalink(); ?>" class="count-more">More<i class="bb-icon-angle-right"></i></a></div>
        <?php } ?>
 
        <?php echo $args['after_widget']; ?>
 
        <?php do_action( 'bp_after_following_widget' ); ?>
 
<?php
    }
}

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.