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 kovali - February 5, 2016

Hi Ross, thanks for the reply.

I can see what you mean, but it won't work well for me because the user-login.php page has a lot of other content ( that should be in the right language when redirected to...)   

I saw another topic in this forum, maybe I could do something like that also ? : http://www.interactivetools.com/forum/forum-posts.php?postNum=2207991#post2207991 

I don't know much about php so maybe you could direct me in this ? The code I'm thinking of :

On all French website pages:

$language = "french";

In websiteMembership.php:

if($language)=="french"){

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

}
else{

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

}


Does this make any sense at all ;-) ?

Cheers,

Koen

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';

}

...

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 !!