Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Last active April 4, 2016 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pebblo/3f2b7ce0c935ab68836fdd1b73f53245 to your computer and use it in GitHub Desktop.
Save Pebblo/3f2b7ce0c935ab68836fdd1b73f53245 to your computer and use it in GitHub Desktop.
EE4 WP User integration add-on string translations
<?php
/*
Plugin Name: Site plugin for myexamplesite.com
Description: Site specific code for myexamplesite.com
*/
/* Begin Adding Functions Below This Line; Do not include an opening PHP tag as this sample code already includes one! */
//This function can be used for custom translations.
//The original string on the left, then the translation like this:
// 'original => 'translated',
function mycustom_filter_gettext( $translated, $original, $domain ) {
// This is an array of original strings
// and what they should be replaced with
$strings = array(
'You are only able to edit your information once you have %slogged in%s. If you recently registered, please check your email for your account information which will allow you to log in.' => 'Your custom string 1',
'If you did not receive any emails, please %sclick here%s to notify us and we will followup with you to get you setup.' => 'Your custom string 2',
// Add some more strings here
);
// See if the current string is in the $strings array
// If so, replace its translation
if ( isset( $strings[$original] ) ) {
// This accomplishes the same thing as __()
// but without running it through the filter again
$translations = get_translations_for_domain( $domain );
$translated = $translations->translate( $strings[$original] );
}
return $translated;
}
add_filter( 'gettext', 'mycustom_filter_gettext', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment