@atmojones
Spaces in front of the @mention? Are you sure you are entering the right username of the user?
Yeah its definitely the right username. Like I said, the @mention autosuggest works when writing the post and in the users activity feed the username is a working link. It’s just in the forum post that it doesn’t become a link. It’s very odd. I went in to the database and edited the post, just adding one space at a time, and whenever there was an even number of spaces the username doesn’t link in the forum.
@robkk
Can you point me to the function that converts @mentions to links. I feel like I can figure this out but I can’t find where it’s being converted.
Is it really just replace the underscores with spaces in this __@mention and it won’t work for you.
This is blowing my mind right now.
Did you do plugin and theme troubleshooting??
https://codex.bbpress.org/getting-started/troubleshooting/
So I made a clean install of WordPress and bbPress (and then after a few test posts I installed buddypress which didn’t change anything) and made 2 users. When I @mention a user in the forum it links correctly regardless of how many spaces I enter. HOWEVER, it does always strip the leading spaces down to 1 in the presentation of the post. If I click Edit on the post the original number of spaces can be seen. Is this intended behavior?
I’m going to make the changes to functions.php to enable the visual editor and to enable buddypress @mention suggestions in bbPress visual editor (like my production site) and see if the error reproduces.
Can you point me to the function that converts @mentions to links. I feel like I can figure this out but I can’t find where it’s being converted.
It is called bbp_make_mentions_clickable
and located line:424
of \includes\common\formatting.php
. The function is hooked in \includes\core\filters.php:248
I discovered why this is happening but I don’t know why the why is happening. Every 2nd space in the post is being replaced with a n-b-s-p-; thereby causing the character directly before the “@” to be a “;” whenever an even number of spaces is put in the post.
@robkk @elhardoum thanks for your help thus far, I will post another update when I know why spaces are being converted to nbsp.
I am using tinyMCE for forum posting. Perhaps it is part of the problem.
Testing one space @atmojones
Testing two spaces @atmojones
Testing three spaces @atmojones
Testing four spaces @atmojones
Testing five spaces @atmojones
Testing six spaces @atmojones
The resulting code from the above:
<p>Testing one space <a href="https://bbpress.org/forums/profile/atmojones/" rel="nofollow">@atmojones</a>
<br> Testing two spaces <a href="https://bbpress.org/forums/profile/atmojones/" rel="nofollow">@atmojones</a>
<br> Testing three spaces <a href="https://bbpress.org/forums/profile/atmojones/" rel="nofollow">@atmojones</a>
<br> Testing four spaces <a href="https://bbpress.org/forums/profile/atmojones/" rel="nofollow">@atmojones</a>
<br> Testing five spaces <a href="https://bbpress.org/forums/profile/atmojones/" rel="nofollow">@atmojones</a>
<br> Testing six spaces <a href="https://bbpress.org/forums/profile/atmojones/" rel="nofollow">@atmojones</a>
</p>
The above doesn’t really show the code, multiple spaces are stripped:
So the regex we use #([\s>])@([0-9a-zA-Z-_]+)#i
in bbp_make_mentions_clickable()
The ([\s>])
is checking for a whitespace character before the @
symbol
The code here below is from using TinyMCE and as you noted @atmojones there’s some non-breaking spaces html entities for the instances when an an even number of spaces preceede the @
symbol:
The root cause is every second space is swapped out with nbsp;
which makes sense from a HTML perspective, where this takes place I’m not so sure of, it’s either in TinyMCE directly, or WordPress via wp_spaces_regexp()
in wptexturize()
(I think it’s the former)
The workaround for bbPress and I suspect BuddyPress also, would be to check for both ([\s>])
and nbsp;
preceding the @
symbol
Here’s the results of swapping ([\s>])
for ([\s>;])
(Adding a check for just the semi-colon):
I’ll include the above in ticket #2963
Thanks for identifying the cause @atmojones, made tracking this down much quicker 🙂
I’m going to make the changes to functions.php to enable the visual editor and to enable buddypress @mention suggestions in bbPress visual editor (like my production site) and see if the error reproduces.
^ @atmojones, how did you enable @mentions within the visual/tinyMCE editor for bbPress?
Hmmm @slomeli79 it’s been awhile since I worked on this. I see this code in my functions.php file but I hesitate to think the solution was this simple. Try it out, and if it doesn’t work I’ll check the rest of my code.
function custom_bbpress_maybe_load_mentions_scripts( $retval = false ) {
return true;
}
add_filter( 'bp_activity_maybe_load_mentions_scripts', 'custom_bbpress_maybe_load_mentions_scripts' );