Skip to:
Content

BuddyPress.org

Opened 12 years ago

Closed 7 years ago

Last modified 7 years ago

#4968 closed enhancement (wontfix)

Returned button after ajax action , addremove_friend & joinleave_group

Reported by: megainfo's profile megainfo Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Templates Keywords: needs-patch
Cc:

Description

The Ajax response for addremove_friend & joinleave_group is a simple html code of buttons.

The html returned code of buttons must use the two functions bp_get_add_friend_button and bp_get_group_join_button.

this is sample update of bp_dtheme_ajax_addremove_friend() function :

/**
 * Friend/un-friend a user via a POST request.
 *
 * @return string HTML
 * @since BuddyPress (1.x)
 */
function bp_dtheme_ajax_addremove_friend() {
	// Bail if not a POST action
	if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
		return;

	// Cast fid as an integer
	$friend_id = (int) $_POST['fid'];

	// Trying to cancel friendship
	if ( 'is_friend' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $friend_id ) ) {
		check_ajax_referer( 'friends_remove_friend' );

		if ( ! friends_remove_friend( bp_loggedin_user_id(), $friend_id ) ) {

			echo __( 'Friendship could not be canceled.', 'buddypress' );
		} else {
			echo bp_get_add_friend_button( $friend_id, 'is_friend' );
		}

	// Trying to request friendship
	} elseif ( 'not_friends' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $friend_id ) ) {
		check_ajax_referer( 'friends_add_friend' );

		if ( ! friends_add_friend( bp_loggedin_user_id(), $friend_id ) ) {
			echo __(' Friendship could not be requested.', 'buddypress' );
		} else {
			echo bp_get_add_friend_button($friend_id, 'not_friends' );
		}

	// Trying to cancel pending request
	} elseif ( 'pending' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $friend_id ) ) {
		check_ajax_referer( 'friends_withdraw_friendship' );

		if ( friends_withdraw_friendship( bp_loggedin_user_id(), $friend_id ) ) {
			echo bp_get_add_friend_button($friend_id, 'pending' );
		} else {
			echo __("Friendship request could not be cancelled.", 'buddypress');
		}

	// Request already pending
	} else {
		echo __( 'Request Pending', 'buddypress' );
	}

	exit;
}

Change History (5)

#1 @DJPaul
12 years ago

  • Component changed from All Components to Theme
  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 1.8

Looks reasonable. If someone can put the above into a patch, we'll do it for BP 1.8

#2 @boonebgorges
12 years ago

  • Milestone changed from 1.8 to Future Release

#3 @DJPaul
8 years ago

  • Component changed from Appearance - Template Parts to Templates

#4 @DJPaul
7 years ago

  • Milestone Future Release deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Closing most tickets related to BP-Default and BP-Legacy, since the upcoming BP-Nouveau template pack (planned for 3.0) will make these redundant.

#5 @DJPaul
7 years ago

Closing most tickets related to BP-Default and BP-Legacy, since the upcoming BP-Nouveau template pack (planned for 3.0) will make these redundant.

Note: See TracTickets for help on using tickets.