Support

Home Forums Event Espresso Premium Gettext not replacing the ticket details for non-logged-in users.

Gettext not replacing the ticket details for non-logged-in users.

Posted: November 26, 2019 at 2:13 am

Viewing 1 reply thread


deon@dieselbrook.co.za

November 26, 2019 at 2:13 am

Hi,

I am trying to replace the string in the ticket selector displayed to users that aren’t logged in, according to https://eventespresso.com/topic/replace-text-on-event-page-script-not-working/ and https://gist.github.com/Pebblo/a68e8a151bd1df0288c45ddff585c300. This used to work, but it doesn’t since I updated the plugin recently.

I read that you have to match the string exactly, otherwise it wont get replaced. I then found the string in getMembersOnlyTicketMessage in the EED_WP_Users_Ticket_Selector.module file, and copied and pasted directly from there. I’ve also tried to increase the priority on the hook, but it still doesn’t replace the string.

The code that I have:
function mycustom_filter_gettext( $translated, $original, $domain ) {
// This is an array of original strings
// and what they should be replaced with
$actual_link = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "{$_SERVER['HTTP_HOST']}/{$_SERVER['REQUEST_URI']}";
$strings = array(
"The %1$s%2$s%3$s%4$s is available to members only. %5$s" => "The %1$s%2$s%3$s%4$s <br/> is only available to registered users, please login for discount prices on events. Log in %5$s"
// 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', 99, 3 );


Tony

  • Support Staff

November 26, 2019 at 4:54 am

Hi there,

The above function throws an undefined variable notice each time it is run:

Notice: Undefined variable: s

Which is happening because the string is wrapped using double-quotes so PHP is trying to parse any variables within it.

You could switch out the string and using single queotes etc, however, there is a filter available to change the string which will parse faster than using gettext.

See here:

https://gist.github.com/Pebblo/783dc4f9f43b9780d860112817edfd6d#file-example-php

Build out your own string passed to sprintf and return the value.

Viewing 1 reply thread

The support post ‘Gettext not replacing the ticket details for non-logged-in users.’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso