bp_nouveau_get_groups_buttons( array $args = array() )
Get the action buttons for the current group in the loop, or the current displayed group.
Description
Parameters
- $args
-
(Optional) See bp_nouveau_wrapper() for the description of parameters.
Default value: array()
Source
File: bp-templates/bp-nouveau/includes/groups/template-tags.php
function bp_nouveau_get_groups_buttons( $args = array() ) { $type = ( ! empty( $args['type'] ) ) ? $args['type'] : 'group'; // @todo Not really sure why BP Legacy needed to do this... if ( 'group' === $type && is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { return; } $buttons = array(); if ( ( 'loop' === $type || 'invite' === $type ) && isset( $GLOBALS['groups_template']->group ) ) { $group = $GLOBALS['groups_template']->group; } else { $group = groups_get_current_group(); } if ( empty( $group->id ) ) { return $buttons; } /* * If the 'container' is set to 'ul' set $parent_element to li, * otherwise simply pass any value found in $args or set var false. */ if ( ! empty( $args['container'] ) && 'ul' === $args['container'] ) { $parent_element = 'li'; } elseif ( ! empty( $args['parent_element'] ) ) { $parent_element = $args['parent_element']; } else { $parent_element = false; } /* * If we have an arg value for $button_element passed through * use it to default all the $buttons['button_element'] values * otherwise default to 'a' (anchor) o override & hardcode the * 'element' string on $buttons array. * * Icons sets a class for icon display if not using the button element */ $icons = ''; if ( ! empty( $args['button_element'] ) ) { $button_element = $args['button_element'] ; } else { $button_element = 'a'; $icons = ' icons'; } // If we pass through parent classes add them to $button array $parent_class = ''; if ( ! empty( $args['parent_attr']['class'] ) ) { $parent_class = $args['parent_attr']['class']; } // Invite buttons on member's invites screen if ( 'invite' === $type ) { // Don't show button if not logged in or previously banned if ( ! is_user_logged_in() || bp_group_is_user_banned( $group ) || empty( $group->status ) ) { return $buttons; } // Setup Accept button attributes $buttons['accept_invite'] = array( 'id' => 'accept_invite', 'position' => 5, 'component' => 'groups', 'must_be_logged_in' => true, 'parent_element' => $parent_element, 'link_text' => esc_html__( 'Accept', 'buddyboss' ), 'button_element' => $button_element, 'parent_attr' => array( 'id' => '', 'class' => $parent_class . ' ' . 'accept', ), 'button_attr' => array( 'id' => '', 'class' => 'button accept group-button accept-invite', 'rel' => '', ), ); // If button element set add nonce link to data-attr attr if ( 'button' === $button_element ) { $buttons['accept_invite']['button_attr']['data-bp-nonce'] = esc_url( bp_get_group_accept_invite_link() ); } else { $buttons['accept_invite']['button_attr']['href'] = esc_url( bp_get_group_accept_invite_link() ); } // Setup Reject button attributes $buttons['reject_invite'] = array( 'id' => 'reject_invite', 'position' => 15, 'component' => 'groups', 'must_be_logged_in' => true, 'parent_element' => $parent_element, 'link_text' => __( 'Reject', 'buddyboss' ), 'parent_attr' => array( 'id' => '', 'class' => $parent_class . ' ' . 'reject', ), 'button_element' => $button_element, 'button_attr' => array( 'id' => '', 'class' => 'button reject group-button reject-invite', 'rel' => '', ), ); // If button element set add nonce link to formaction attr if ( 'button' === $button_element ) { $buttons['reject_invite']['button_attr']['data-bp-nonce'] = esc_url( bp_get_group_reject_invite_link() ); } else { $buttons['reject_invite']['button_attr']['href'] = esc_url( bp_get_group_reject_invite_link() ); } // Request button for the group's manage screen } elseif ( 'request' === $type ) { // Setup Accept button attributes $buttons['group_membership_accept'] = array( 'id' => 'group_membership_accept', 'position' => 5, 'component' => 'groups', 'must_be_logged_in' => true, 'parent_element' => $parent_element, 'link_text' => esc_html__( 'Accept', 'buddyboss' ), 'button_element' => $button_element, 'parent_attr' => array( 'id' => '', 'class' => $parent_class, ), 'button_attr' => array( 'id' => '', 'class' => 'button accept', 'rel' => '', ), ); // If button element set add nonce link to data-attr attr if ( 'button' === $button_element ) { $buttons['group_membership_accept']['button_attr']['data-bp-nonce'] = esc_url( bp_get_group_request_accept_link() ); } else { $buttons['group_membership_accept']['button_attr']['href'] = esc_url( bp_get_group_request_accept_link() ); } $buttons['group_membership_reject'] = array( 'id' => 'group_membership_reject', 'position' => 15, 'component' => 'groups', 'must_be_logged_in' => true, 'parent_element' => $parent_element, 'button_element' => $button_element, 'link_text' => __( 'Reject', 'buddyboss' ), 'parent_attr' => array( 'id' => '', 'class' => $parent_class, ), 'button_attr' => array( 'id' => '', 'class' => 'button reject', 'rel' => '', ), ); // If button element set add nonce link to data-attr attr if ( 'button' === $button_element ) { $buttons['group_membership_reject']['button_attr']['data-bp-nonce'] = esc_url( bp_get_group_request_reject_link() ); } else { $buttons['group_membership_reject']['button_attr']['href'] = esc_url( bp_get_group_request_reject_link() ); } /* * Manage group members for the group's manage screen. * The 'button_attr' keys 'href' & 'formaction' are set at the end of this array block */ } elseif ( 'manage_members' === $type && isset( $GLOBALS['members_template']->member->user_id ) ) { $user_id = $GLOBALS['members_template']->member->user_id; $buttons = array( 'unban_member' => array( 'id' => 'unban_member', 'position' => 5, 'component' => 'groups', 'must_be_logged_in' => true, 'parent_element' => $parent_element, 'button_element' => $button_element, 'link_text' => __( 'Remove Ban', 'buddyboss' ), 'parent_attr' => array( 'id' => '', 'class' => $parent_class, ), 'button_attr' => array( 'id' => '', 'class' => 'button confirm member-unban', 'rel' => '', 'title' => '', ), ), 'ban_member' => array( 'id' => 'ban_member', 'position' => 15, 'component' => 'groups', 'must_be_logged_in' => true, 'parent_element' => $parent_element, 'button_element' => $button_element, 'link_text' => __( 'Kick & Ban', 'buddyboss' ), 'parent_attr' => array( 'id' => '', 'class' => $parent_class, ), 'button_attr' => array( 'id' => '', 'class' => 'button confirm member-ban', 'rel' => '', 'title' => '', ), ), 'promote_mod' => array( 'id' => 'promote_mod', 'position' => 25, 'component' => 'groups', 'must_be_logged_in' => true, 'parent_element' => $parent_element, 'parent_attr' => array( 'id' => '', 'class' => $parent_class, ), 'button_element' => $button_element, 'button_attr' => array( 'id' => '', 'class' => 'button confirm member-promote-to-mod', 'rel' => '', 'title' => '', ), 'link_text' => sprintf( __( 'Promote to %s', 'buddyboss' ), get_group_role_label( $group->id, 'moderator_singular_label_name' ) ), ), 'promote_admin' => array( 'id' => 'promote_admin', 'position' => 35, 'component' => 'groups', 'must_be_logged_in' => true, 'parent_element' => $parent_element, 'button_element' => $button_element, 'link_text' => sprintf( __( 'Promote to co-%s', 'buddyboss' ), strtolower( get_group_role_label( $group->id, 'organizer_singular_label_name' ) ) ), 'parent_attr' => array( 'id' => '', 'class' => $parent_class, ), 'button_attr' => array( 'href' => esc_url( bp_get_group_member_promote_admin_link() ), 'id' => '', 'class' => 'button confirm member-promote-to-admin', 'rel' => '', 'title' => '', ), ), 'remove_member' => array( 'id' => 'remove_member', 'position' => 45, 'component' => 'groups', 'must_be_logged_in' => true, 'parent_element' => $parent_element, 'button_element' => $button_element, 'link_text' => __( 'Remove from group', 'buddyboss' ), 'parent_attr' => array( 'id' => '', 'class' => $parent_class, ), 'button_attr' => array( 'id' => '', 'class' => 'button confirm', 'rel' => '', 'title' => '', ), ), ); // If 'button' element is set add the nonce link to data-attr attr, else add it to the href. if ( 'button' === $button_element ) { $buttons['unban_member']['button_attr']['data-bp-nonce'] = bp_get_group_member_unban_link( $user_id ); $buttons['ban_member']['button_attr']['data-bp-nonce'] = bp_get_group_member_ban_link( $user_id ); $buttons['promote_mod']['button_attr']['data-bp-nonce'] = bp_get_group_member_promote_mod_link(); $buttons['promote_admin']['button_attr']['data-bp-nonce'] = bp_get_group_member_promote_admin_link(); $buttons['remove_member']['button_attr']['data-bp-nonce'] = bp_get_group_member_remove_link( $user_id ); } else { $buttons['unban_member']['button_attr']['href'] = bp_get_group_member_unban_link( $user_id ); $buttons['ban_member']['button_attr']['href'] = bp_get_group_member_ban_link( $user_id ); $buttons['promote_mod']['button_attr']['href'] = bp_get_group_member_promote_mod_link(); $buttons['promote_admin']['button_attr']['href'] = bp_get_group_member_promote_admin_link(); $buttons['remove_member']['button_attr']['href'] = bp_get_group_member_remove_link( $user_id ); } // Membership button on groups loop or single group's header } else { /* * This filter workaround is waiting for a core adaptation * so that we can directly get the groups button arguments * instead of the button. * * See https://buddypress.trac.wordpress.org/ticket/7126 */ add_filter( 'bp_get_group_join_button', 'bp_nouveau_groups_catch_button_args', 100, 1 ); bp_get_group_join_button( $group ); remove_filter( 'bp_get_group_join_button', 'bp_nouveau_groups_catch_button_args', 100, 1 ); if ( ! empty( bp_nouveau()->groups->button_args ) ) { $button_args = bp_nouveau()->groups->button_args; // If we pass through parent classes merge those into the existing ones if ( $parent_class ) { $parent_class .= ' ' . $button_args['wrapper_class']; } // The join or leave group header button should default to 'button' // Reverse the earler button var to set default as 'button' not 'a' if ( empty( $args['button_element'] ) ) { $button_element = 'button'; } $buttons['group_membership'] = array( 'id' => 'group_membership', 'position' => 5, 'component' => $button_args['component'], 'must_be_logged_in' => $button_args['must_be_logged_in'], 'block_self' => $button_args['block_self'], 'parent_element' => $parent_element, 'button_element' => $button_element, 'link_text' => $button_args['link_text'], 'parent_attr' => array( 'id' => $button_args['wrapper_id'], 'class' => $parent_class, ), 'button_attr' => array( 'id' => ! empty( $button_args['link_id'] ) ? $button_args['link_id'] : '', 'class' => $button_args['link_class'] . ' button', 'rel' => ! empty( $button_args['link_rel'] ) ? $button_args['link_rel'] : '', 'title' => '', ), ); if ( ! empty( $button_args['button_attr'] ) ) { foreach ( $button_args['button_attr'] as $title => $value ) { $buttons['group_membership']['button_attr'][$title] = $value; } } // If button element set add nonce 'href' link to data-attr attr. if ( 'button' === $button_element ) { $buttons['group_membership']['button_attr']['data-bp-nonce'] = $button_args['link_href']; } else { // Else this is an anchor so use an 'href' attr. $buttons['group_membership']['button_attr']['href'] = $button_args['link_href']; } unset( bp_nouveau()->groups->button_args ); } } // Exclude Kick & Ban button for the site admin. if ( 'manage_members' === $type && isset( $GLOBALS['members_template']->member->user_id ) ) { $user_id = $GLOBALS['members_template']->member->user_id; if ( user_can( $user_id, 'manage_options' ) ) { unset( $buttons['ban_member'] ); } } /** * Filter to add your buttons, use the position argument to choose where to insert it. * * @since BuddyPress 3.0.0 * * @param array $buttons The list of buttons. * @param int $group The current group object. * @param string $type Whether we're displaying a groups loop or a groups single item. */ $buttons_group = apply_filters( 'bp_nouveau_get_groups_buttons', $buttons, $group, $type ); if ( ! $buttons_group ) { return $buttons; } // It's the first entry of the loop, so build the Group and sort it if ( ! isset( bp_nouveau()->groups->group_buttons ) || ! is_a( bp_nouveau()->groups->group_buttons, 'BP_Buttons_Group' ) ) { $sort = true; bp_nouveau()->groups->group_buttons = new BP_Buttons_Group( $buttons_group ); // It's not the first entry, the order is set, we simply need to update the Buttons Group } else { $sort = false; bp_nouveau()->groups->group_buttons->update( $buttons_group ); } $return = bp_nouveau()->groups->group_buttons->get( $sort ); if ( ! $return ) { return array(); } // Remove buttons according to the user's membership type. if ( 'manage_members' === $type && isset( $GLOBALS['members_template'] ) ) { if ( bp_get_group_member_is_banned() ) { unset( $return['ban_member'], $return['promote_mod'], $return['promote_admin'] ); } else { unset( $return['unban_member'] ); } } /** * Leave a chance to adjust the $return * * @since BuddyPress 3.0.0 * * @param array $return The list of buttons. * @param int $group The current group object. * @parem string $type Whether we're displaying a groups loop or a groups single item. */ do_action_ref_array( 'bp_nouveau_return_groups_buttons', array( &$return, $group, $type ) ); return $return; }
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.