Multilangual Website Membership

By kovali - February 3, 2016

Hi,

I've build a website in 3 languages (English, Dutch, French), now my client wants parts of the website to be for members only...

I've succesfully setup the Website Membership Plug-in (1-10) for the English part, but I'm having problems with the other language parts:

The login page is always directing to the English Login page, while I want it to show the French or Dutch login page respectively.

Like: http://www.mysite.be/fr/user-login.php?loginRequired=1 

and: http://www.mysite.be/nl/user-login.php?loginRequired=1

instead of: http://www.mysite.be/user-login.php?loginRequired=1

I can see this code in the WebsiteMembership.php: $GLOBALS['WEBSITE_LOGIN_LOGIN_FORM_URL']  = '/user-login.php';

How can I arrange this code so it will show a different page for each language please ??

Thanks for helping me out already !!

Koen

By ross - February 4, 2016

Hi Koen

Thanks for posting.

I have an idea on how to get this working for you that involves cookies. It's rather advanced though so I want to go over a different idea that's easier to implement.

Basically, the easier idea is to still just have the one /user-login.php page.  But on that page, add a link to each of the other language login pages.  

Does that sound like it would work?

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By ross - February 5, 2016 - edited: February 5, 2016

Hi Koen.

I get what you mean with all the other content on the page.

The problem here will be that there isn't enough information for the login page to know what language the current user wants.

What you could do is have a cookie called "language" set on every single page. On all the French pages, set the the language cookie to "French. On all the English pages, set the language cooke to "English". And so forth.

Then, when they get redirected to your login, you can check the cookie.  If the cookie is set to French, redirect to the French login page.

Does that make sense?

Let me know what you think.

Thanks!

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By kovali - February 8, 2016

Okay Ross,

I'm trying the solution with a cookie, but I'm getting a php error:

Notice: Undefined index: language in /home/ajkdirec/public_html/beheer/plugins/websiteMembership.php on line 14 setPrefixedCookie: Can't set cookie, headers already sent! Output started in /home/ajkdirec/public_html/beheer/plugins/websiteMembership.php line 14

Could you check what I'm doing wrong please ?

My code in the French webpages to set the cookie (at the top):

<?php
setcookie("language", "fr");
?>
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */

// load viewer library
$libraryPath = 'beheer/lib/viewer_functions.php';
$dirsToCheck = array('/home/ajkdirec/public_html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

...

My code in websiteMembership.php to read the cookie:

<?php
/*
Plugin Name: Website Membership
Description: Website membership functions for user sign-up, password reminder, login, user specific content, and login only content
Version: 1.10
Requires at least: 2.52
Required System Plugin: True
*/

// UPDATE THESE VALUES

$cookie_var = $_COOKIE['language'];

if ($cookie_var == "fr"){

$GLOBALS['WEBSITE_LOGIN_LOGIN_FORM_URL'] = '/fr/user-login.php';

}
else{

$GLOBALS['WEBSITE_LOGIN_LOGIN_FORM_URL'] = '/user-login.php';

}

...

By gregThomas - February 8, 2016

Hi Kovali,

It looks like the issue is the language cookie isn't always set, so the $_COOKIE['language'] variable can only be found when setCookie('language', 'fr') is set before the website membership plugin loads. This might fix the issue:

<?php
/*
Plugin Name: Website Membership
Description: Website membership functions for user sign-up, password reminder, login, user specific content, and login only content
Version: 1.10
Requires at least: 2.52
Required System Plugin: True
*/

// UPDATE THESE VALUES

$cookie_var = @$_COOKIE['language'];

if ($cookie_var == "fr"){
  $GLOBALS['WEBSITE_LOGIN_LOGIN_FORM_URL'] = '/fr/user-login.php';
}else{
  $GLOBALS['WEBSITE_LOGIN_LOGIN_FORM_URL'] = '/user-login.php';
}

So the @ symbol tells the code that if there is an error, it should ignore it. In this case that stops an error appearing if it can't find anything set for the $_COOKIE['language'] variable. 

Let me know if you have any questions.

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By kovali - February 11, 2016

Seems to work fine now! Thanks !!