Skip to:

Opened 10 years ago

Closed 6 years ago

#5954 closed enhancement (maybelater)

Privacy option for @mentions

Reported by: dtc7240's profile dtc7240 Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Activity Keywords: 2nd-opinion, trac-tidy-2018


One downside to @mentions is that other users can force things to show up on your "mentions" tab (or your "Wall" using some plugins), and you can't do anything to remove them. This could especially be a problem when using a "Wall" implementation.

Here is some code to add a button that allows users to remove themselves from any activity in which they were @mentioned.

First, add the button in perhaps bp-activity/bp-activity-actions.php:

 * Add "Remove Me" button to remove @mentions
function bp_remove_mentions() {
	if ( bp_activity_user_is_mentioned() ) {
		$activity_id = bp_get_activity_id();
		<a data-id="<?php echo $activity_id ?>" class="remove-at-mention button bp-secondary-action">Remove Me</a>
		<?php wp_nonce_field('remove_atme','_remove_at_mention_nonce');
add_action('bp_activity_entry_meta', 'bp_remove_mentions');

Second, add the appropriate javascript to perhaps bp-activity/js/mentions.js:

	/* When the 'Remove Me' button is clicked to remove an @mentioned user from an activity */
	jq('body').on('click', '.remove-at-mention', function(event) {
		// Stick an are you sure box with explanation here
		if ( ! confirm('This will remove your tag from this activity and remove this activity from your wall (unless you are also the author).\n\nWould you like to continue?') ) {
			return false;

		var target = jq(;
		var activity_id ='id');
		var nonce ='#_remove_at_mention_nonce').val();
		var activity = jq('li#activity-' + activity_id );
			url: ajaxurl,
			type: "POST",
			global: false,
			data: {
				action: 'remove_at_mention',
				'cookie': bp_get_cookies(),
				'id': activity_id,
				'_remove_at_mention_nonce': nonce
			success: function(response) {
				var myprofile = false;
				var atmention = response;
				if ( response.substring(0,2) == 'my' ) {
					myprofile = true;
					atmention = response.substring(2);
				if ( myprofile && document.URL == BuddyBossOptions.user_profile ) {
					// Slide up activity
				} else {
					// Remove @mention text from activity
					activity.find('.activity-inner p a').each( function() {
						if ( jq(this).html() == atmention ) {
			error: function(err) {

This would require a more generic BuddyPress representation of the logged in user's profile base (.../members/scott/) where I've used an easy to find variable provided by the BuddyBoss theme.

Third, add the Ajax code in perhaps bp-activity/bp-activity-ajax.php:

 * Remove a user's @mention name from an activity
function bp_ajax_remove_at_mention() {

	// Check the nonce
	if ( !isset($_POST['_remove_at_mention_nonce']) || !wp_verify_nonce($_POST['_remove_at_mention_nonce'], 'remove_atme') ) {
	// Gather data
	$replacement_text = '<i>{@Mention Removed}</i>';
	$activity_id = $_POST['id'];
	$user_id = bp_loggedin_user_id();
	$user_atmention = '@' . bp_activity_get_user_mentionname( $user_id );
	// Remove from content
	$activity_lookup = bp_activity_get( array('in'=>$activity_id) );
	$activity = $activity_lookup['activities'][0];
	$content = $activity->content;
	$start_pos_of_atmention = strpos( $content, $user_atmention );
	$end_anchor_tag = strpos( $content, '>', $start_pos_of_atmention );
	$begin_anchor_tag = strrpos( substr( $content, 0, $start_pos_of_atmention ), '<a' );
	$new_content = substr_replace( $content, $replacement_text, $begin_anchor_tag, $end_anchor_tag - $begin_anchor_tag + 1 );
	$activity->content = $new_content;
	$success = bp_activity_add( $activity );

	// Return appropriate values
	if ( $success ) {
		if ( bp_is_my_profile() ) {
			echo 'my' . $user_atmention;
		} else {
			echo $user_atmention;
	} else return false;


add_action( 'wp_ajax_remove_at_mention', 'bp_ajax_remove_at_mention' );


Change History (5)

#1 @DJPaul
9 years ago

  • Keywords has-patch removed
  • Milestone changed from Awaiting Review to Future Release
  • Summary changed from Add a button for users to remove themselves from @mentions to privacy options for @mentions

Hi @dtc7240,

Thanks very much for creating your first trac ticket :) and for the code. I'm sure it'll be helpful.

What BuddyPress ought to have for this kind of thing is an option in some imaginary privacy settings field like "don't allow people to send me @mentions". We're far away from this becoming a reality unfortunately, but we'll keep this ticket open so we are sure to not miss this situation once we get there in a future release.

#2 @dtc7240
9 years ago

Hi @DjPaul,

I know it's been six months, but I just inadvertently stumbled upon this old ticket that I created and forgot about. It's actually not my first trac ticket, but thanks for the welcome! I had a couple some time before this that have since become part of the code base, and I've got a couple of new ones out there now (which is how I stumbled upon this one).

This is actually a valuable little functional addition that has been running flawlessly on our site ( for some time.

I think it's very valuable to allow users to still accept @mentions (not disable them completely via settings), but remove themselves from ones they don't wish to be part of (or see somewhere on their profile). Therefore, it works quite well, and I'd love to see it get a little love in the BuddyPress community (although I already have it running).

Think there is any chance of taking another look at it?


P.S. What we REALLY NEED (from an SQL perspective) is a much better way of storing @mentions than digging through comment fields in the database!!

#3 @slaFFik
7 years ago

  • Keywords 2nd-opinion added
  • Summary changed from privacy options for @mentions to Privacy option for @mentions

What about creating a /members/slaffik/settings/privacy tab with proper templates and hooks with this 1 (or perhaps some more easy to implement) option to disable mentions?

That will become a starting point for other developers. And we in future could step by step increase the number of options there (perhaps by getting feedback from the community).

It will be a part of Settings component. We will need to use filters in Activity component (in this ticket example) to prevent sending notification and email to a mentioned person. So when Settings componebt deactivated - nothing will be broken.

#4 @DJPaul
6 years ago

  • Keywords trac-tidy-2018 added

We're closing this ticket because it has not received any contribution or comments for at least two years. We have decided that it is better to close tickets that are good ideas, which have not gotten (or are unlikely to get) contributions, rather than keep things open indefinitely. This will help us share a more realistic roadmap for BuddyPress with you.

Everyone very much appreciates the time and effort that you spent sharing your idea with us. On behalf of the entire BuddyPress team, thank you.

If you feel strongly that this enhancement should still be added to BuddyPress, and you are able to contribute effort towards it, we encourage you to re-open the ticket, or start a discussion about it in our Slack channel. Please consider that time has proven that good ideas without contributions do not get built.

For more information, see
or find us on Slack, in the #buddypress channel:

#5 @DJPaul
6 years ago

  • Milestone Awaiting Contributions deleted
  • Resolution set to maybelater
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.