diff --git a/includes/bp-rbe-extend-bbpress.php b/includes/bp-rbe-extend-bbpress.php index f4559b1..649728b 100644 --- a/includes/bp-rbe-extend-bbpress.php +++ b/includes/bp-rbe-extend-bbpress.php @@ -93,8 +93,8 @@ private function custom_hooks() { add_action( 'bbp_new_topic_post_extras', array( $this, 'clear_global_cache' ) ); add_action( 'bbp_new_reply_post_extras', array( $this, 'clear_global_cache' ) ); - // BPMFP support. - add_action( 'bpmfp_before_send', array( $this, 'bpmfp_support' ) ); + // New GES support. + add_filter( 'bp_ass_send_activity_notification_for_user', array( $this, 'ges_support' ), 9999, 2 ); } /** @@ -1307,35 +1307,65 @@ public function get_forum_encoded_email_address() { } /** - * Add support for the BP Multiple Forum Post plugin. + * Add support for the BP Group Email Subscription plugin. + * + * This is the new way to add support for GES 3.6+. * * @since 1.0-RC4 * - * @param BP_Activity_Activity $activity + * @param bool $retval Whether GES should send the current email. + * @param BP_Activity_Activity $activity Activity object GES is using. */ - public function bpmfp_support( $activity ) { - // Temporarily save activity object so we can reference it in the bpmfp_support() method. + public function ges_support( $retval, $activity ) { + if ( false === $retval ) { + return $retval; + } + + /* + * Temporarily save activity object so we can reference it in the + * ges_extend_listener() method. + */ $this->temp_activity = $activity; // Extend RBE's listener to add RBE support. - add_action( 'bp_rbe_extend_listener', array( $this, 'bpmfp_extend_listener' ) ); + add_action( 'bp_rbe_extend_listener', array( $this, 'ges_extend_listener' ) ); + + return $retval; } /** - * Register support for BPMFP with RBE. + * Register support for GES with RBE. * - * Since BPMFP works by delaying email sending to remove duplicate emails - * {@see bpmfp_interrupt_original_activity_notification()}, we must tell RBE - * about this on the 'bp_rbe_extend_listener' hook. + * Since other GES plugins like BP Multiple Forum Post works by delaying GES + * email sending to remove duplicate emails {@see bpmfp_interrupt_original_activity_notification()}, + * we need to let RBE's listener know about it. * * @since 1.0-RC4 * * @param BP_Reply_By_Email $rbe */ - public function bpmfp_extend_listener( $rbe ) { + public function ges_extend_listener( $rbe ) { + // We've already done this, so stop! + // @todo Remove this once we're ready to drop extend_activity_listener(). + if ( isset( $rbe->listener ) && $this->id === $rbe->listener->component ) { + return; + } + + // If activity type does not match our bbPress types, stop now! + if ( $this->temp_activity->type != $this->activity_type && $this->temp_activity->type != 'bbp_topic_create' ) { + return; + } + $rbe->listener->component = $this->id; $rbe->listener->item_id = $this->temp_activity->item_id; $rbe->listener->secondary_item_id = $this->temp_activity->secondary_item_id; + $rbe->listener->reply_to_id = $this->temp_activity->secondary_item_id; $rbe->listener->user_id = $this->temp_activity->user_id; + + // If activity type is a bbPress reply, we need to grab the topic ID manually. + if ( $this->temp_activity->type === $this->activity_type ) { + $rbe->listener->secondary_item_id = bbp_get_reply_topic_id( $this->temp_activity->secondary_item_id ); + $rbe->listener->reply_to_id = get_post_field( 'post_parent', $this->temp_activity->secondary_item_id ); + } } }