Skip to:
Content
Pages
Categories
Search
Top
Bottom

Disallow mention notifications/emails from user A to user B?


  • FTLRalph
    Participant

    @ftlralph

    Trying to modify a block plugin for my website.

    All is going well, but the “block” can be bypassed if the blocked user simply @-mentions the blocker-user. The blocker-user will then receive a notification/email from the “blocked” user.

    So I’m trying to catch the notification/email prior to anything being sent. Then I’d compare user IDs and cancel it.

    What function(s) should I be looking at?

    I found this in bp-activity-notifcations.php but unsure if this is what I’m looking for, unless it is? Is this early enough to prevent the email too?

    /**
     * Notify a member when their nicename is mentioned in an activity stream item.
     *
     * Hooked to the 'bp_activity_sent_mention_email' action, we piggy back off the
     * existing email code for now, since it does the heavy lifting for us. In the
     * future when we separate emails from Notifications, this will need its own
     * 'bp_activity_at_name_send_emails' equivalent helper function.
     *
     * @since 1.9.0
     *
     * @param object $activity           Activity object.
     * @param string $subject (not used) Notification subject.
     * @param string $message (not used) Notification message.
     * @param string $content (not used) Notification content.
     * @param int    $receiver_user_id   ID of user receiving notification.
     */
    function bp_activity_at_mention_add_notification( $activity, $subject, $message, $content, $receiver_user_id ) {
    	bp_notifications_add_notification( array(
    			'user_id'           => $receiver_user_id,
    			'item_id'           => $activity->id,
    			'secondary_item_id' => $activity->user_id,
    			'component_name'    => buddypress()->activity->id,
    			'component_action'  => 'new_at_mention',
    			'date_notified'     => bp_core_current_time(),
    			'is_new'            => 1,
    	) );
    }
    add_action( 'bp_activity_sent_mention_email', 'bp_activity_at_mention_add_notification', 10, 5 );
Viewing 2 replies - 1 through 2 (of 2 total)

  • FTLRalph
    Participant

    @ftlralph

    And like most cases I figured it out after posting the question

    public function should_send_mention_notificaton($value, $usernames, $user_id, $activity)
    {
    	// Return false if activity author is blocked by user_id
    	global $wpdb;
    	
    	$id_maybe_blocked = $activity->user_id;
    	$blocked_ids = $wpdb->get_col( "SELECT target_id FROM {$wpdb->base_prefix}bp_block_member WHERE user_id = '$user_id' ");
    	if (in_array($id_maybe_blocked, $blocked_ids) == true)
    		return false;
    	return true;
    }
    add_filter( 'bp_activity_at_name_do_notifications', 'should_send_mention_notificaton', 1, 4);

    shanebp
    Moderator

    @shanebp

    Please do not post code for premium plugins on these forums.
    While I appreciate the clarity of your question and the draft solution – it is not appropriate in this setting.
    You should contact the plugin creator directly.
    Closing this and will contact you privately.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Disallow mention notifications/emails from user A to user B?’ is closed to new replies.
Skip to toolbar