bp_nouveau_get_members_buttons( $args )
Get the action buttons for the displayed user profile
Description
Return
(array)
Source
File: bp-templates/bp-nouveau/includes/members/template-tags.php
function bp_nouveau_get_members_buttons( $args ) { $buttons = array(); $type = ( ! empty( $args['type'] ) ) ? $args['type'] : ''; // @todo Not really sure why BP Legacy needed to do this... if ( 'profile' === $type && is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { return $buttons; } $user_id = bp_displayed_user_id(); if ( 'loop' === $type || 'friendship_request' === $type ) { $user_id = bp_get_member_user_id(); } elseif ( 'group_member' === $type ) { $user_id = bp_get_group_member_id(); } if ( ! $user_id ) { return $buttons; } /* * If the 'container' is set to 'ul' * set a var $parent_element to li * otherwise simply pass any value found in args * or set var false. */ $parent_element = false; if ( ! empty( $args['container'] ) && 'ul' === $args['container'] ) { $parent_element = 'li'; } elseif ( ! empty( $args['parent_element'] ) ) { $parent_element = $args['parent_element']; } /* * 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) * Or 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 = 'button'; $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']; } $bp_force_friendship_to_message = bp_force_friendship_to_message(); if ( bp_is_active( 'friends' ) ) { // It's the member's connection requests screen if ( 'friendship_request' === $type ) { $buttons = array( 'accept_friendship' => array( 'id' => 'accept_friendship', 'position' => 5, 'component' => 'friends', 'must_be_logged_in' => true, 'parent_element' => $parent_element, 'link_text' => __( 'Accept', 'buddyboss' ), 'parent_attr' => array( 'id' => '', 'class' => $parent_class , ), 'button_element' => $button_element, 'button_attr' => array( 'class' => 'button accept', 'rel' => '', ), ), 'reject_friendship' => array( 'id' => 'reject_friendship', 'position' => 15, 'component' => 'friends', 'must_be_logged_in' => true, 'parent_element' => $parent_element, 'link_text' => __( 'Ignore', 'buddyboss' ), 'parent_attr' => array( 'id' => '', 'class' => $parent_class, ), 'button_element' => $button_element, 'button_attr' => array ( 'class' => 'button reject', 'rel' => '', ), ), ); // If button element set add nonce link to data attr if ( 'button' === $button_element ) { $buttons['accept_friendship']['button_attr']['data-bp-nonce'] = bp_get_friend_accept_request_link(); $buttons['reject_friendship']['button_attr']['data-bp-nonce'] = bp_get_friend_reject_request_link(); } else { $buttons['accept_friendship']['button_attr']['href'] = bp_get_friend_accept_request_link(); $buttons['reject_friendship']['button_attr']['href'] = bp_get_friend_reject_request_link(); } // It's any other members screen } else { /* * This filter workaround is waiting for a core adaptation * so that we can directly get the friends button arguments * instead of the button. * * See https://buddypress.trac.wordpress.org/ticket/7126 */ add_filter( 'bp_get_add_friend_button', 'bp_nouveau_members_catch_button_args', 100, 1 ); bp_get_add_friend_button( $user_id ); remove_filter( 'bp_get_add_friend_button', 'bp_nouveau_members_catch_button_args', 100, 1 ); if ( ! empty( bp_nouveau()->members->button_args ) ) { $button_args = bp_nouveau()->members->button_args; $buttons['member_friendship'] = array( 'id' => 'member_friendship', '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, 'link_text' => $button_args['link_text'], 'parent_attr' => array( 'id' => $button_args['wrapper_id'], 'class' => $parent_class . ' ' . $button_args['wrapper_class'], ), 'button_element' => $button_element, 'button_attr' => array( 'id' => $button_args['link_id'], 'class' => $button_args['link_class'], 'rel' => $button_args['link_rel'], 'title' => '', ), ); if ( ! empty( $button_args['button_attr'] ) ) { foreach ( $button_args['button_attr'] as $title => $value ) { $buttons['member_friendship']['button_attr'][$title] = $value; } } // If button element set add nonce link to data attr if ( 'button' === $button_element && 'awaiting_response' !== $button_args['id'] ) { $buttons['member_friendship']['button_attr']['data-bp-nonce'] = $button_args['link_href']; } else { $buttons['member_friendship']['button_element'] = 'a'; $buttons['member_friendship']['button_attr']['href'] = $button_args['link_href']; } unset( bp_nouveau()->members->button_args ); } } } if ( bp_is_active( 'activity' ) && bp_is_activity_follow_active() ) { // add follow button /* * This filter workaround is waiting for a core adaptation * so that we can directly get the follow button arguments * instead of the button. * * See https://buddypress.trac.wordpress.org/ticket/7126 */ add_filter( 'bp_get_add_follow_button', 'bp_nouveau_members_catch_button_args', 100, 1 ); bp_get_add_follow_button( $user_id, bp_loggedin_user_id() ); remove_filter( 'bp_get_add_follow_button', 'bp_nouveau_members_catch_button_args', 100, 1 ); if ( ! empty( bp_nouveau()->members->button_args ) ) { $button_args = bp_nouveau()->members->button_args; $buttons['member_follow'] = array( 'id' => 'member_follow', 'position' => 10, 'component' => $button_args['component'], 'must_be_logged_in' => $button_args['must_be_logged_in'], 'block_self' => $button_args['block_self'], 'parent_element' => $parent_element, 'link_text' => $button_args['link_text'], 'parent_attr' => array( 'id' => $button_args['wrapper_id'], 'class' => $parent_class . ' ' . $button_args['wrapper_class'], ), 'button_element' => $button_element, 'button_attr' => array( 'id' => $button_args['link_id'], 'class' => $button_args['link_class'], 'rel' => $button_args['link_rel'], 'title' => '', ), ); if ( ! empty( $button_args['button_attr'] ) ) { foreach ( $button_args['button_attr'] as $title => $value ) { $buttons['member_follow']['button_attr'][$title] = $value; } } // If button element set add nonce link to data attr if ( 'button' === $button_element ) { $buttons['member_follow']['button_attr']['data-bp-nonce'] = $button_args['link_href']; } else { $buttons['member_follow']['button_element'] = 'a'; $buttons['member_follow']['button_attr']['href'] = $button_args['link_href']; } unset( bp_nouveau()->members->button_args ); } } // Only add The public and private messages when not in a loop //if ( 'profile' === $type ) { if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() ) { /* * This filter workaround is waiting for a core adaptation * so that we can directly get the public message button arguments * instead of the button. * * See https://buddypress.trac.wordpress.org/ticket/7126 */ if ( ! empty( bp_nouveau()->members->button_args ) ) { $button_args = bp_nouveau()->members->button_args; /* * This button should remain as an anchor link. * Hardcode the use of anchor elements if button arg passed in for other elements. */ $buttons['public_message'] = array( 'id' => $button_args['id'], 'position' => 15, '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' => 'a', 'link_text' => $button_args['link_text'], 'parent_attr' => array( 'id' => $button_args['wrapper_id'], 'class' => $parent_class, ), 'button_attr' => array( 'href' => $button_args['link_href'], 'id' => '', 'class' => $button_args['link_class'], ), ); unset( bp_nouveau()->members->button_args ); } } if ( ( bp_is_active( 'messages' ) && ! $bp_force_friendship_to_message ) || ( $bp_force_friendship_to_message && bp_is_active( 'friends' ) && friends_check_friendship( bp_loggedin_user_id(), $user_id ) ) ) { /** * This filter workaround is waiting for a core adaptation * so that we can directly get the private messages button arguments * instead of the button. * @see https://buddypress.trac.wordpress.org/ticket/7126 */ add_filter( 'bp_get_send_message_button_args', 'bp_nouveau_members_catch_button_args', 100, 1 ); bp_get_send_message_button(); remove_filter( 'bp_get_send_message_button_args', 'bp_nouveau_members_catch_button_args', 100, 1 ); if ( ! empty( bp_nouveau()->members->button_args ) ) { $button_args = bp_nouveau()->members->button_args; /* * This button should remain as an anchor link. * Hardcode the use of anchor elements if button arg passed in for other elements. */ $buttons['private_message'] = array( 'id' => $button_args['id'], 'position' => 25, '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' => 'a', 'link_text' => $button_args['link_text'], 'parent_attr' => array( 'id' => $button_args['wrapper_id'], 'class' => $parent_class, ), 'button_attr' => array( 'href' => wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() ) . 'compose/?r=' . bp_core_get_username( $user_id ) ), 'id' => false, 'class' => $button_args['link_class'], 'rel' => '', 'title' => '', ), ); unset( bp_nouveau()->members->button_args ); } } /* * This filter workaround is waiting for a core adaptation * so that we can directly get the follow button arguments * instead of the button. * * See https://buddypress.trac.wordpress.org/ticket/7126 */ add_filter( 'bp_get_add_switch_button', 'bp_nouveau_members_catch_button_args', 100, 1 ); bp_get_add_switch_button( $user_id ); remove_filter( 'bp_get_add_switch_button', 'bp_nouveau_members_catch_button_args', 100, 1 ); if ( ! empty( bp_nouveau()->members->button_args ) ) { $button_args = bp_nouveau()->members->button_args; $buttons['member_switch'] = array( 'id' => 'member_switch', 'position' => 30, 'component' => $button_args['component'], 'must_be_logged_in' => $button_args['must_be_logged_in'], 'block_self' => $button_args['block_self'], 'parent_element' => $parent_element, 'link_href' => $button_args['link_href'], 'link_text' => $button_args['link_text'], 'parent_attr' => array( 'id' => $button_args['wrapper_id'], 'class' => $parent_class . ' ' . $button_args['wrapper_class'], ), 'button_element' => 'a', 'button_attr' => array( 'id' => $button_args['link_id'], 'class' => $button_args['link_class'], 'rel' => $button_args['link_rel'], 'title' => '', ), ); if ( ! empty( $button_args['button_attr'] ) ) { foreach ( $button_args['button_attr'] as $title => $value ) { $buttons['member_switch']['button_attr'][ $title ] = $value; } } // If button element set add nonce link to data attr if ( 'button' === $button_element ) { $buttons['member_switch']['button_attr']['data-bp-nonce'] = $button_args['link_href']; } else { $buttons['member_switch']['button_element'] = 'a'; $buttons['member_switch']['button_attr']['href'] = $button_args['link_href']; } unset( bp_nouveau()->members->button_args ); } //} /** * 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 $user_id The displayed user ID. * @param string $type Whether we're displaying a members loop or a user's page */ $buttons_group = apply_filters( 'bp_nouveau_get_members_buttons', $buttons, $user_id, $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()->members->member_buttons ) || ! is_a( bp_nouveau()->members->member_buttons, 'BP_Buttons_Group' ) ) { $sort = true; bp_nouveau()->members->member_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()->members->member_buttons->update( $buttons_group ); } $return = bp_nouveau()->members->member_buttons->get( $sort ); if ( ! $return ) { return array(); } /** * Leave a chance to adjust the $return * * @since BuddyPress 3.0.0 * * @param array $return The list of buttons ordered. * @param int $user_id The displayed user ID. * @param string $type Whether we're displaying a members loop or a user's page */ do_action_ref_array( 'bp_nouveau_return_members_buttons', array( &$return, $user_id, $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.