#4968 closed enhancement (wontfix)
Returned button after ajax action , addremove_friend & joinleave_group
| Reported by: |
|
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
@
13 years ago
- Component changed from All Components to Theme
- Keywords needs-patch added
- Milestone changed from Awaiting Review to 1.8
Note: See
TracTickets for help on using
tickets.
Looks reasonable. If someone can put the above into a patch, we'll do it for BP 1.8