Support

Home Forums Event Espresso Premium WP User – change "is available to members only." again

WP User – change "is available to members only." again

Posted: March 9, 2016 at 2:30 pm


Freddys

March 9, 2016 at 2:30 pm

https://eventespresso.com/topic/wp-user-change-is-available-to-members-only/

I had this issue before and tech support in the thread linked above gave me a function that changed the text I needed brilliantly.. but now I’m noticing that it no longer is working.

Is there an updated function that I can add to my site specific plugin so I can change the text for events?

Here is my current function:
function mycustom_filter_gettext( $translated, $original, $domain ) {

// This is an array of original strings
// and what they should be replaced with
$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 is only available to registered scholars. Please log in.’,
// 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;
}


Tony

  • Support Staff

March 10, 2016 at 1:03 am

Hi there,

When posting code we recommend using something like pastebin.com or creating a gist to add the code to and post the url here, the forum alters the formatting of your code, for example single quotes like ' become which won’t work when used within PHP.

It could be the forum altering the formatting here but if you notice in my example here:

https://eventespresso.com/topic/wp-user-change-is-available-to-members-only/#post-180663

The original string has 2 spaces after %1$s%2$s%3$s%4$s, your code above does not. The original string must match exactly so I suspect that is why your function is not working. If I copy my original function it works fine on my test sites.

Also, there should be one more line of code after that which would be:

add_filter( 'gettext', 'mycustom_filter_gettext', 10, 3 );

I’m guessing that is actually there you just didn’t include it but wanted to make sure as it will not work without it.


Freddys

March 14, 2016 at 11:04 am

Aha! I must have over-written the last line of code.. I added it back and it worked. Thank you again. You guys rock!
FXG


Tony

  • Support Staff

March 14, 2016 at 11:17 am

You’re most welcome 🙂

I’m glad it now works, please do let us know if you have any further problems.


Freddys

March 14, 2016 at 7:53 pm

I was just asked today to change the text where it reads: “Goes on Sale”.. to “Will be Available”
One can see the Goes on Sale text here for example:
http://carrickinstitute.com/events/907-908-washington-2016/

Can I please have a script to change that text as well please?
– Freddys


Tony

  • Support Staff

March 15, 2016 at 3:27 am

You can translate multiple strings within that same function, the strings are added to an array and the function loops over all of them, so it currently has:

$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  is only available to registered scholars. %5$s',
        // Add some more strings here
);

You can change that to:

$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  is only available to registered scholars. %5$s',
		'Goes On Sale' => 'Will be Available',
		// Add some more strings here
);

That will translate both the strings for you.


Freddys

March 15, 2016 at 8:58 am

Worked perfectly again. Thanks again for your help on this.. I’m PHP illiterate, so your help is very greatly appreciated!
FXG


Lorenzo Orlando Caum

  • Support Staff

March 15, 2016 at 9:45 am

Hi Freddys,

Did you have any other questions about changing the messaging/verbiage that is used in Event Espresso?

Thanks


Lorenzo


Freddys

March 15, 2016 at 11:34 am

Not right now.. but thank you for asking. You guys are the best!


Tony

  • Support Staff

March 15, 2016 at 11:40 am

Thank you 🙂

I’ll mark this thread resolved, please feel free to open up another if you have any further questions.

Have a great day.

The support post ‘WP User – change "is available to members only." again’ 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