latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

pro login widget

Home Forums Community Forum pro login widget

This topic contains 27 replies, has 3 voices. Last updated by  boudewijn lutgerink 4 years ago.

Topic Author Topic
Posted: Monday Dec 3rd, 2012 at 5:21 am #33280

I have been playing around wwith the pro login widget. Just one Q arises.
Is it possible to alter the text for “My Account” and “Edit My Profile”?

The site I have is international, based on a userfield determining the language I would like to display/hide certain possibilities on the site.

List Of Topic Replies

Viewing 25 replies - 1 through 25 (of 27 total)
Author Replies
Author Replies
Posted: Monday Dec 3rd, 2012 at 1:55 pm #33332
Bruce
Username: Bruce
Staff Member

Hi Boudewijn,

There is no built-in way to alter the text for the login widget, other than the WordPress I18N translations, which is supported by s2Member. If you internationalized your plugin using I18N, you could change the text.

I18N:
http://codex.wordpress.org/Translating_WordPress

Otherwise, if you’d like a quick-and-dirty solution, you could create an edited /includes/classes/login-widget.inc.php file, and put it into a Must Use plugin file by creating a .php file within /wp-content/mu-plugins/ on your server (create the directory if you don’t have it).

You should be able to simply CTRL + F and find where s2Member echos the data you’d like to change.

Posted: Monday Dec 3rd, 2012 at 4:14 pm #33366

Hmmm, this is not what I am looking for.
My site has visitors from different countries like USA, Canada, Germany, Spain and Holland. (Russian in preparation). For each registered visitor I have a pofile with the language they speak.

Based on that I want to show them content in their own language.
I use the get_user_field() function to retrieve the local language.
what I see now is that the title of the login widget can be different (using the $options[“profile_title”] etc…)
I would like to have a different text for the “My Account” and “Edit My Profile” based on the user language.

Posted: Monday Dec 3rd, 2012 at 4:41 pm #33369
Bruce
Username: Bruce
Staff Member

Hi Boudewijn,

You’ll need to filter the translation with 'gettext_with_context'. Try something like this in a Must Use plugin:

Posted: Thursday Dec 6th, 2012 at 3:00 am #33672

Hi Bruce,

Thanks for the code. I tried it and it seems to work … nearly
The code you gave does work ok.
HOWEVER (there is always a however).
I have subscribers who either speak Dutch or English.
I have one user-field in the profile called _taal_ it contains either “NL” or “EN” (Netherlands / English).
So I adjusted your code a bit to the following:

<?php
add_filter('gettext_with_context', 's2hack_translate_login_widget', 10, 4);
function s2hack_translate_login_widget($translated, $original, $context, $domain) 
{
	$Lang = get_user_field("_taal_");
	switch ($Lang) 
	{
	    case "NL":
			if ($domain === 's2member' && $context === 's2member-front' && $original === 'My Account' )
				$translated = 'Mijn Account';
			elseif($domain === 's2member' && $context === 's2member-front' && $original === 'Edit My Profile' )
				$translated = 'Mijn Profiel';
	        break;
	
	    case "EN":
			if ($domain === 's2member' && $context === 's2member-front' && $original === 'My Account' )
				$translated = 'My English Account';
			elseif($domain === 's2member' && $context === 's2member-front' && $original === 'Edit My Profile' )
				$translated = 'English Profile';
	        break;
	}
	
return $translated;
} 

For some reason it is not working even though, as far as I can see, the code only fires AFTER logging in.
In the future I want to add more languages (German, French, Spanish and Russian) and I want to offer a site that is as much localized as I can. Therefore I need to be able to translate things like “edit my profile”, “My Account” etc…
How do I do that? The best option possible I see now is what I asked already, to add those translations into the $options array. But that comes from a total lack of knowledge about PHP (so forgive me if I say something entirely stupid.)

Posted: Thursday Dec 6th, 2012 at 1:41 pm #33720
Bruce
Username: Bruce
Staff Member

In the future I want to add more languages (German, French, Spanish and Russian) and I want to offer a site that is as much localized as I can. Therefore I need to be able to translate things like “edit my profile”, “My Account” etc…
How do I do that? The best option possible I see now is what I asked already, to add those translations into the $options array. But that comes from a total lack of knowledge about PHP (so forgive me if I say something entirely stupid.)

For logged-in users, your code will work fine. This is because you’re using get_user_field() to grab the data for a user. If the user is logged-out, there is no data. If you’d rather grab the user’s language from something like IP, you could do that as well. I reformatted your code a bit and added the lines:

if(!$lang)
	$lang = 'EN'; 

This sets the default language to ‘EN’, or English. If you’d rather set this to something else, or use another method to find the correct language for users that are NOT logged-in, you can set $lang to whatever you need to here.

  • This reply was modified 4 years, 1 month ago by  Bruce.
Posted: Thursday Dec 6th, 2012 at 4:02 pm #33761

I get a 500 error…
SIgh, maybe the solution I propose is still the better one…

Posted: Thursday Dec 6th, 2012 at 4:22 pm #33767
Bruce
Username: Bruce
Staff Member

Try this instead:

Posted: Thursday Dec 6th, 2012 at 4:39 pm #33778

doesn’t seem to work. All I get is the English version, no matter how I set the user language.
I repeat, maybe the solution I propose is the simplest one…

(add the options for those texts to the $options array)

BL

Posted: Thursday Dec 6th, 2012 at 4:44 pm #33782
Bruce
Username: Bruce
Staff Member

If you find editing the file easier, that should work fine as well.

Posted: Sunday Dec 9th, 2012 at 3:40 am #34042

What I notice is that the title of the loginbox does change after logging in. (My Profile / Mijn Profiel)
The rest of the text is not changing at all.
It looks like the mu-plugin is not firing at all. The chamges that appear are in the php script I made.
Is there any way I can include your code in the schript I have?
And no, editing the file as you suggest is not an option. That makes the login box static again and I need it to be dynamic based on the language the logged in user speaks.
So once more my suggestion to add the strings to the $options array.

Posted: Sunday Dec 9th, 2012 at 4:47 pm #34077

Where do I find info on the $translated, $original, $content and $domain variables?
I looked in the docs but cannot find it.

Posted: Monday Dec 10th, 2012 at 7:20 am #34122
Posted: Tuesday Dec 11th, 2012 at 1:05 am #34207

I am totally lost now on the use of MU plugins.
I tried calling the function in a PHP script but that doesn’t seem to work.
It definetely looks like mu plugins fire once, at startup time only and that they are not callable in scripts whatsoever.
So how do I go along and make this login box/profile box dynamical?
maybe my initial idea to add all the options into the $profile array is not so bad after all.

Posted: Tuesday Dec 11th, 2012 at 1:58 pm #34279
Bruce
Username: Bruce
Staff Member

This code:

  • This reply was modified 4 years ago by  Bruce. Reason: Edited code snippet slightly
Posted: Tuesday Dec 11th, 2012 at 6:35 pm #34305

that hangs the site completely.

Posted: Wednesday Dec 12th, 2012 at 2:44 pm #34401
Bruce
Username: Bruce
Staff Member

Boudewijn,

Are you saying it gives you a parse error?

What exactly happens?

Posted: Wednesday Dec 12th, 2012 at 4:54 pm #34423

It might be a parse error. What happens is that the site doesn’t show up at all.
Just a beautiful white page, in IE, Chrome and FF. But not quite the page I need to see.

The longer I work on this the more I am convinced that my suggestion to add all these options in the $options array is the simplest one.

Still the $original, $domain, $context and $translated variables are as clear as thick fog to me.
Can I use these in a simple function in the functions.php?

Posted: Friday Dec 14th, 2012 at 2:32 pm #34689
Bruce
Username: Bruce
Staff Member

Boudewijn,

I updated the code snippet that was in my post that you said affected your site this way.

Can you try the new code?

Also, I would advise against using this code in your theme’s functions.php file, as it might not load in time for the data to be filtered.

Posted: Monday Dec 17th, 2012 at 1:32 am #34809

what do you mean with “It might not load in time”?

This is the scenario:
a visitor comes to the site. (s)he is not logged in yet.
At that moment the language of the visitor cannot be determined since the visitor is unknown.
Then the visitor logs in. After logging in the language can be determined.
Only at that moment the function can be called to translate texts into the langage of the user.
Ideally, if the user edit’s his/her profile and changes the language then the texts should be translated again.

Posted: Monday Dec 17th, 2012 at 1:35 am #34811

What you mean with

…it might not load in time…?

Is that function loaded once at startup and cannot be called?
That would make it completely useless for me to start with.
This is the scenario:
A user comes to the site, not logged in yet.
At that moment the site is then in its original state (English in this case)
Then the user logs in. At that moment the langage the user speak can be determined.
At that moment I want the site to show all texts in the language of the user.
Loading the text-translations before the user logs in makes no sense to me.

Once more, I need a function to translate text dynamically based on the language of the user that logs in (and that might NOT be the language the system uses)

Posted: Monday Dec 17th, 2012 at 1:36 am #34812

sorry for the double reply. somehow the connection failed for a moment and it looked like my comment was not saved… (duuuhhh)

Posted: Tuesday Dec 18th, 2012 at 2:03 pm #34960
Bruce
Username: Bruce
Staff Member

Loading the text-translations before the user logs in makes no sense to me.

The translation functionality needs to be fired before the text is created in the workspace. In other words, if WordPress includes the file that is creating the translation after the text is created, it won’t change it.

Posted: Friday Dec 21st, 2012 at 12:30 am #35204

So this mu-plugin is useless then.
Now that this option is ruled out, what can we do then to translate texts AFTER the user logged in?

Posted: Saturday Dec 22nd, 2012 at 2:24 pm #35343
Bruce
Username: Bruce
Staff Member

So this mu-plugin is useless then.
Now that this option is ruled out, what can we do then to translate texts AFTER the user logged in?

This is not the case. You’ll want to use the gettext_with_context filter here. The reason that the code is not working properly is because of either a small error in the code, or because of an error with the way that you’re attempting to get the user’s language.

Posted: Sunday Dec 23rd, 2012 at 2:42 am #35401

I will definetely come back to this. For now I have to fight the ugly beast called WordPress 3.5. That mean son of a B**ch completely screwed up my site and I am pretty much out of options except for ompletely rebuilding it.

If only I could have version 3.4.2 back on that server.

Viewing 25 replies - 1 through 25 (of 27 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.