[buddypress-trac] [BuddyPress] #4968: Returned button after ajax action , addremove_friend & joinleave_group
buddypress-trac
noreply at wordpress.org
Tue Apr 30 14:05:18 UTC 2013
#4968: Returned button after ajax action , addremove_friend & joinleave_group
----------------------------+-----------------------------
Reporter: megainfo | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: All Components | Version:
Severity: normal | Keywords:
----------------------------+-----------------------------
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;
}
}}}
--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/4968>
BuddyPress <http://buddypress.org/>
BuddyPress
More information about the buddypress-trac
mailing list