Skip to content

Commit

Permalink
When a user is removed from the Readers list for a paper, force unfol…
Browse files Browse the repository at this point in the history
…low.

See #7.
  • Loading branch information
boonebgorges committed Nov 8, 2015
1 parent aa06c87 commit 0abf23b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions includes/class-cacsp-paper.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@ public function remove_reader( $user_id ) {

$this->reader_ids = null;

if ( true === $removed ) {
/**
* Fires when a reader has been removed from a paper.
*
* @param CACSP_Paper $paper Paper object.
* @param int $user_id ID of the user removed.
*/
do_action( 'cacsp_removed_reader_from_paper', $this, $user_id );
}

return $removed;
}

Expand Down
21 changes: 21 additions & 0 deletions includes/hooks-buddypress-follow.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

add_action( 'bp_activity_post_type_published', 'cacsp_auto_follow_on_new_paper', 10, 3 );
//add_action( 'cacsp_added_reader_to_paper', 'cacsp_auto_follow_for_new_reader', 10, 2 );
add_action( 'cacsp_removed_reader_from_paper', 'cacsp_unfollow_for_removed_reader', 10, 2 );

/**
* Automatically provision users to follow their own written paper.
Expand Down Expand Up @@ -70,6 +71,26 @@ function cacsp_auto_follow_for_new_reader( $paper, $user_id ) {
) );
}

/**
* Unfollow a user from a paper when the user is removed from the Readers list.
*
* @since 1.0.0
*
* @param CACSP_Paper $paper
* @param int $user_id
*/
function cacsp_unfollow_for_removed_reader( $paper, $user_id ) {
if ( empty( $user_id ) ) {
return;
}

bp_follow_stop_following( array(
'leader_id' => cacsp_follow_get_activity_id( $paper->id ),
'follower_id' => $user_id,
'follow_type' => 'cacsp_paper'
) );
}

/** NOTIFICATIONS ********************************************************/

add_filter( 'cacsp_custom_notification_format', 'cacsp_follow_format_notifications', 10, 2 );
Expand Down

0 comments on commit 0abf23b

Please sign in to comment.