Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RSVP control of strings
<?php
function tribe_custom_theme_text ( $translation, $text, $domain ) {
$custom_text = array(
'Confirm RSVP' => 'Confirm Reservation',
'RSVP' => 'Reservation',
'Please fill in the RSVP confirmation name and email fields.' => 'Please fill in the Reservation confirmation name and email fields.',
'Send RSVP confirmation to:' => 'Send Reservation confirmation to:'
);
// If this text domain starts with "tribe-", "the-events-", or "event-" and we have replacement text
if( (strpos($domain, 'tribe-') === 0 || strpos($domain, 'the-events-') === 0 || strpos($domain, 'event-') === 0) && array_key_exists($translation, $custom_text) ) {
$translation = $custom_text[$translation];
}
return $translation;
}
add_filter('gettext', 'tribe_custom_theme_text', 20, 3);
function tribe_custom_theme_text_with_context ( $translation, $text, $context, $domain ) {
$custom_text = array(
'RSVP Now!' => 'Registration',
);
$custom_text_with_context = [
'form heading' => [
'RSVP' => 'Reservation'
],
];
// If this text domain starts with "tribe-", "the-events-", or "event-" and we have replacement text
if ( (strpos($domain, 'tribe-') === 0 || strpos($domain, 'the-events-') === 0 || strpos($domain, 'event-') === 0) ){
if ( array_key_exists($context, $custom_text_with_context) && array_key_exists($translation, $custom_text_with_context[$context]) ) {
$translation = $custom_text_with_context[$context][$translation];
}
}
if( (strpos($domain, 'tribe-') === 0 || strpos($domain, 'the-events-') === 0 || strpos($domain, 'event-') === 0) && array_key_exists($translation, $custom_text) ) {
$translation = $custom_text[$translation];
}
return $translation;
}
add_filter('gettext_with_context', 'tribe_custom_theme_text_with_context', 21, 4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment