BP_Groups_Widget::widget( array $args, array $instance )

Extends our front-end output method.

Description

Parameters

$args

(Required) Array of arguments for the widget.

$instance

(Required) Widget instance data.

Source

File: bp-groups/classes/class-bp-groups-widget.php

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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
public function widget( $args, $instance ) {
    global $groups_template;
 
    /**
     * Filters the user ID to use with the widget instance.
     *
     * @since BuddyPress 1.5.0
     *
     * @param string $value Empty user ID.
     */
    $user_id = apply_filters( 'bp_group_widget_user_id', '0' );
 
    extract( $args );
 
    if ( empty( $instance['group_default'] ) ) {
        $instance['group_default'] = 'popular';
    }
 
    if ( empty( $instance['title'] ) ) {
        $instance['title'] = __( 'Groups', 'buddyboss' );
    }
 
    /**
     * Filters the title of the Groups widget.
     *
     * @since BuddyPress 1.8.0
     * @since BuddyPress 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter.
     *
     * @param string $title    The widget title.
     * @param array  $instance The settings for the particular instance of the widget.
     * @param string $id_base  Root ID for all widgets of this type.
     */
    $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
 
    /**
     * Filters the separator of the group widget links.
     *
     * @since BuddyPress 2.4.0
     *
     * @param string $separator Separator string. Default '|'.
     */
    $separator = apply_filters( 'bp_groups_widget_separator', '|' );
 
    echo $before_widget;
 
    $title = ! empty( $instance['link_title'] ) ? '<a href="' . bp_get_groups_directory_permalink() . '">' . $title . '</a>' : $title;
 
    echo $before_title . $title . $after_title;
 
    $max_groups = ! empty( $instance['max_groups'] ) ? (int) $instance['max_groups'] : 5;
 
    $group_args = array(
        'user_id'         => $user_id,
        'type'            => $instance['group_default'],
        'per_page'        => $max_groups,
        'max'             => $max_groups,
    );
 
    // Back up the global.
    $old_groups_template = $groups_template;
 
    ?>
 
    <?php if ( bp_has_groups( $group_args ) ) : ?>
        <div class="item-options" id="groups-list-options">
            <a href="<?php bp_groups_directory_permalink(); ?>" id="newest-groups"<?php if ( $instance['group_default'] == 'newest' ) : ?> class="selected"<?php endif; ?>><?php _e("Newest", 'buddyboss') ?></a>
            <span class="bp-separator" role="separator"><?php echo esc_html( $separator ); ?></span>
            <a href="<?php bp_groups_directory_permalink(); ?>" id="recently-active-groups"<?php if ( $instance['group_default'] == 'active' ) : ?> class="selected"<?php endif; ?>><?php _e("Active", 'buddyboss') ?></a>
            <span class="bp-separator" role="separator"><?php echo esc_html( $separator ); ?></span>
            <a href="<?php bp_groups_directory_permalink(); ?>" id="popular-groups" <?php if ( $instance['group_default'] == 'popular' ) : ?> class="selected"<?php endif; ?>><?php _e("Popular", 'buddyboss') ?></a>
        </div>
 
        <ul id="groups-list" class="item-list" aria-live="polite" aria-relevant="all" aria-atomic="true">
            <?php while ( bp_groups() ) : bp_the_group(); ?>
                <li <?php bp_group_class(); ?>>
                    <div class="item-avatar">
                        <a href="<?php bp_group_permalink() ?>"><?php bp_group_avatar_thumb() ?></a>
                    </div>
 
                    <div class="item">
                        <div class="item-title"><?php bp_group_link(); ?></div>
                        <div class="item-meta">
                            <span class="activity">
                            <?php
                                if ( 'newest' == $instance['group_default'] ) {
                                    printf( __( 'created %s', 'buddyboss' ), bp_get_group_date_created() );
                                } elseif ( 'popular' == $instance['group_default'] ) {
                                    bp_group_member_count();
                                } else {
                                    printf( __( 'active %s', 'buddyboss' ), bp_get_group_last_active() );
                                }
                            ?>
                            </span>
                        </div>
                    </div>
                </li>
 
            <?php endwhile; ?>
        </ul>
        <?php wp_nonce_field( 'groups_widget_groups_list', '_wpnonce-groups' ); ?>
        <input type="hidden" name="groups_widget_max" id="groups_widget_max" value="<?php echo esc_attr( $max_groups ); ?>" />
         
        <div class="more-block"><a href="<?php bp_groups_directory_permalink(); ?>" class="count-more">More<i class="bb-icon-angle-right"></i></a></div>
 
    <?php else: ?>
 
        <div class="widget-error">
            <?php _e('There are no groups to display.', 'buddyboss') ?>
        </div>
 
    <?php endif; ?>
 
    <?php echo $after_widget;
 
    // Restore the global.
    $groups_template = $old_groups_template;
}

Changelog

Changelog
Version Description
BuddyPress 1.0.3 Introduced.

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.