Last active
August 30, 2022 07:17
-
-
Save GeoffEW/0e6fe4cf5fb894f034caa9bd7887b6bf to your computer and use it in GitHub Desktop.
RSVP control of strings
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 | |
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