-
-
Save Pebblo/8994a0ea19c63d9776e6048333225f08 to your computer and use it in GitHub Desktop.
Example of a custom functions plugin that currently has a string translation function within it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Event Espresso Custom Functions Plugin | |
Description: Add custom functions for Event Espresso to this plugin. | |
/* Begin Adding Functions Below This Line; Do not include an opening PHP tag as this sample code already includes one! */ | |
function tw_ee_mycustom_filter_gettext( $translated, $original, $domain ) { | |
// This is an array of original strings | |
// and what they should be replaced with | |
$strings = array( | |
'The event you have selected requires logging in before you can register. You can %sregister for an account here%s if you don\'t have a login.' => 'The event you have selected requires logging in before you can register. <strong>New Users</strong> you can %sregister for an account here%s if you don\'t have a login. <h3>Returning Users</h3>', | |
// 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', 'tw_ee_mycustom_filter_gettext', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment