bp_nouveau_ajax_button( $output = '',  $button = null,  $before = '',  $after = '',  $r = array() )

Output ajax button for action (e.g. request connection with member, join group, leave group, follow member, etc.)

Description

Return

(string)

Source

File: bp-templates/bp-nouveau/includes/functions.php

176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
function bp_nouveau_ajax_button( $output = '', $button = null, $before = '', $after = '', $r = array() ) {
    if ( empty( $button->component ) ) {
        return $output;
    }
 
    // Custom data attribute.
    $r['button_attr']['data-bp-btn-action'] = $button->id;
 
    $reset_ids = array(
        'member_friendship' => true,
        'member_follow'     => true,
        'group_membership'  => true,
    );
 
    if ( ! empty( $reset_ids[ $button->id ] ) )  {
        $parse_class = array_map( 'sanitize_html_class', explode( ' ', $r['button_attr']['class'] ) );
        if ( false === $parse_class ) {
            return $output;
        }
 
        $find_id = array_intersect( $parse_class, array(
            'pending_friend',
            'is_friend',
            'not_friends',
            'leave-group',
            'join-group',
            'accept-invite',
            'membership-requested',
            'request-membership',
            'not_following',
            'following',
        ) );
 
        if ( 1 !== count( $find_id ) ) {
            return $output;
        }
 
        $data_attribute = reset( $find_id );
        if ( 'pending_friend' === $data_attribute ) {
            $data_attribute = str_replace( '_friend', '', $data_attribute );
        } elseif ( 'group_membership' === $button->id ) {
            $data_attribute = str_replace( '-', '_', $data_attribute );
        }
 
        $r['button_attr']['data-bp-btn-action'] = $data_attribute;
    }
 
    // Re-render the button with our custom data attribute.
    $output = new BP_Core_HTML_Element( array(
        'element'    => $r['button_element'],
        'attr'       => $r['button_attr'],
        'inner_html' => ! empty( $r['link_text'] ) ? $r['link_text'] : ''
    ) );
    $output = $output->contents();
 
    // Add span bp-screen-reader-text class
    return $before . $output . $after;
}

Changelog

Changelog
Version Description
BuddyPress 3.0.0 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.