Skip to:
Content

BuddyPress.org

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#5019 closed defect (bug) (fixed)

Fire 'friends_friendship_deleted' hook after delete friendship.

Reported by: mukkundthanki Owned by: boonebgorges
Milestone: 1.8 Priority: low
Severity: minor Version: 1.7
Component: Friends Keywords: 2nd-opinion
Cc:

Description

In function 'friends_remove_friend', we fire 'friends_friendship_deleted' hook and then we delete friendship and then update friends total.

Actually I need friends total after friendship deleted. I can hook my function to 'friends_friendship_deleted' but total updates after it. My suggestion is

if ( $friendship->delete() ) {
	friends_update_friend_totals( $initiator_userid, $friend_userid, 'remove' );

	do_action( 'friends_friendship_deleted', $friendship_id, $initiator_userid, $friend_userid );

	return true;
}

Change History (6)

#1 @boonebgorges
7 years ago

  • Keywords 2nd-opinion added
  • Milestone changed from Awaiting Review to 1.8
  • Priority changed from normal to low
  • Severity changed from normal to minor

Ugh, you are right, this looks like a mistake.

If we move it as you suggest, it's possible that we'll break plugins that are using the hook and depending on its odd behavior. However, I think it's pretty unlikely that we'd break them in a serious way - if anything, we may *fix* them in some cases. So I lean toward moving it as mukkundthanki suggests, but I'd like feedback from another dev before going forward.

#2 @mukkundthanki
7 years ago

you are right on that, and i guess my suggestion is also improper because it will be useless of $friendship_id in hook which actually deleted. so, hook is right as its right now.we can make use of friendship details before its delete, but can we make one more hook which fire after successful deletion of friendship ?? like this

do_action( 'friends_friendship_deleted_success', $initiator_userid, $friend_userid );

so, we can make use of 'friends_update_friend_totals' function.

#3 follow-up: @boonebgorges
7 years ago

  • Owner set to boonebgorges
  • Resolution set to fixed
  • Status changed from new to closed

In 7108:

Introduce friends_friendship_post_delete hook

The existing hook friends_friendship_deleted hook actually fires before the
friendship count is deleted in the database. This causes problems for plugins
that want to access the updated user friend counts, and other info that is
changed at the time of delete.

Fixes #5019

Props mukkundthanki

#4 in reply to: ↑ 3 @mukkundthanki
7 years ago

Replying to boonebgorges:

In 7108:

Introduce friends_friendship_post_delete hook

The existing hook friends_friendship_deleted hook actually fires before the
friendship count is deleted in the database. This causes problems for plugins
that want to access the updated user friend counts, and other info that is
changed at the time of delete.

Fixes #5019

Props mukkundthanki

I don't think hook will work after return true statement. we should put it right before return true. It will work fine there because condition let it run if friendship is successfully deleted.

Thanks

#5 @boonebgorges
7 years ago

In 7110:

Move friends_friendship_post_delete hook to somewhere it'll actually work

See #5019

Props mukkundthanki. Antiprops boonebgorges

#6 @boonebgorges
7 years ago

Oops, I'm a moron. Thanks :)

Note: See TracTickets for help on using tickets.