Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
plugins-topic
Mentions plugin: customise the private message text
Avatar
Blaise
Member
Pro Subscribers
sp_UserOfflineSmall Offline
Apr 26, 2016 - 4:14 am

 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!

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Apr 26, 2016 - 7:40 am

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...

andy-signature.png
YELLOW
SWORDFISH
Avatar
Blaise
Member
Pro Subscribers
sp_UserOfflineSmall Offline
Apr 26, 2016 - 8:01 am

Sure. 

I want to replace

 mentioned you in the forum post

with

t'a mentionné dans le fil

Thanks.

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Apr 26, 2016 - 12:19 pm

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.

andy-signature.png
YELLOW
SWORDFISH
Avatar
Blaise
Member
Pro Subscribers
sp_UserOfflineSmall Offline
Apr 27, 2016 - 3:13 am

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 );
}
Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Apr 27, 2016 - 3:46 am

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.

andy-signature.png
YELLOW
SWORDFISH
Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 619
Members: 17362
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10127
Posts: 79625