Support Forum

Mentions plugin: customise the private message text

BL Blaise
Blaise
Member

 Hi,

How do I modify the text that gets sent via private message when a user is “mentionned” thru the Mention plugin?

Reading the doc I found:

  • apply_filters(‘sph_mentions_pm_message’, $who.’ ‘.__(‘mentioned you in the forum post’, ‘sp-mentions’).’: ‘.$newpost[‘url’], $newpost, $user->ID);) – Allows modification of the message in a mentions notification when using the Private Messaging system before it is output/returned.

But I would love to see in the doc an example of how to use this.

Thanks!

5 Answers

New Answer

YS Yellow Swordfish
Yellow Swordfish
Member

It’s hard to make a useful example without knowing what someone wants to replace the default text with as the permutations and possibilities are extensive. So if you want to let us know that we can help out…

BL Blaise
Blaise
Member

Sure. 

I want to replace

 mentioned you in the forum post

with

t’a mentionné dans le fil

Thanks.

YS Yellow Swordfish
Yellow Swordfish
Member

You should really, of course,  use the proper translation engine for this which is the correct way of doing it but the following mght work – I have not tried it.

Create a new, empty file called sp-user-functions.php in your WordPress wp-content folder.

Copy and paste the following function (use the Raw Code button for this) into this new file – plain text – and save. Remember at the top of the file before the function must be an opening php tag. At the very bottom after the function a closing php tag. There must be NO empty lines or spaces before or after these tags and the code block.

add_filter( 'sph_mentions_pm_message', 'translate_mention_text', 1, 3 );
function translate_mention_text( $text, $newpost, $user ) {
    return str_replace( "mentioned you in the forum post", "t'a mentionné dans le fil", $text );
}

If this fails then it is most likely that apostrophe which may need escaping. You will need to test it.

BL Blaise
Blaise
Member

Thanks! I would never have found this.

I indeed had to escape the apostrophe, but also the French accents. So for future reference, this is what I have:

//Translates Simple Press Mentions module
add_filter( 'sph_mentions_pm_message', 'translate_mention_text', 1, 3 );
function translate_mention_text( $text, $newpost, $user ) {
 return str_replace( "mentioned you in the forum post", "t'a mentionné dans le fil", $text );
}

add_filter( 'sph_mentions_pm_title', 'translate_mention_title', 1, 3 );
function translate_mention_title( $text, $newpost, $user ) {
 return str_replace( "You were mentioned in a post", "Tu es mentionné dans un fil du forum", $text );
}
YS Yellow Swordfish
Yellow Swordfish
Member

Yes. I was a bit rushed when I posted so was unable to try it but I was pretty sure that would be the case. Glad you got it working, Also – by putting the code into that particular file it will be safe from all future updates.