Tips and Tricks HQ Support Portal › Forums › WP eMember › WP eMember F.A.Q/Instructions › How to Load the WP eMember's Language File from Another Folder
Tagged: customization, Language, WP eMember, wpml
- This topic has 16 replies, 5 voices, and was last updated 4 years, 2 months ago by admin.
-
AuthorPosts
-
July 4, 2018 at 1:33 am #14944adminKeymaster
If you are customizing the text/messages displayed by the eMember plugin then this tweak maybe helpful.
You can keep your customized copy of the language file in a different folder (outside the plugins folder). Then use the following code to load it (uses the emember_language_loading_override filter).
That way the changes you make to the language file don’t get overridden if the plugin is updated.
You would add the following code to your theme’s functions.php file or a custom plugin.
add_filter('emember_language_loading_override', 'load_my_custom_emember_language');
function load_my_custom_emember_language()
{
$language_file = "/path/to/your/custom/language/file/lang.php";
include_once($language_file);
return "custom-file-loaded";
}This ensures that the plugin will always load your custom language file from your custom folder (so the one inside the plugin folder doesn’t matter).
August 3, 2018 at 2:09 pm #78080clem90MemberHi,
Thanks !
Can I use this code with WPML and eMember WPML Addon ?
August 4, 2018 at 11:01 pm #78081adminKeymasterYou should be able to. I have never tested it so I can’t say for sure.
January 9, 2020 at 11:08 pm #78082drjansonSpectatorI’m sorry, but I think im messing up the file path and do not get that working..
What would the path be if its called frome child-theme’s function.php and the language file is in the same directory?
e.g.
wp-content/themes/my-childtheme/function.php
and
wp-content/themes/my-childtheme/lang.php
thanks.
January 11, 2020 at 1:26 am #78083wzpModeratorIt should be the absolute path to the custom language file. If the path is accessible via an HTTP or HTTPS address, that is “easiest.” Otherwise, figure out the path, starting at the document root of your WordPress instance. You “could” use a relative path to the file, starting from the directory containing the calling file; but as you determined, “it’s hard” to get right the first time.
January 12, 2020 at 12:22 am #78084adminKeymasterIf you echo the value of the following constant, it will give you the path to the emember plugin:
WP_EMEMBER_PATH
That can help you back-calculate the path to your theme (since the path upto the “wp-content” folder is going to be the same)
January 14, 2020 at 2:14 pm #78085drjansonSpectatorIn my functions.php i tried an absolute path with no success:
$language_file = "https://weblab.geronne.de/wp-content/themes/customizr-pro-child/ger_custom.php"
Next I tried to put my customized language file into the plugins “lang” directory and tried:
$language_file = "/ger_custom.php";
Next I echoed the WP_EMEMBER_PATH as suggested and it returned
“/www/htdocs/myaccount/weblab.geronne.de/wp-content/plugins/wp-eMember”
and since my child-theme’s location is “/www/htdocs/myaccount/weblab.geronne.de/wp-content/themes/customizr-pro-child”
i tried the following code in my child-themes functions.php:
add_filter('emember_language_loading_override', 'load_my_custom_emember_language');
function load_my_custom_emember_language()
{
$language_file = "/../../themes/customizr-pro-child/ger_custom.php";
include_once($language_file);
return "custom-file-loaded";
}But still none of the solutions turned out to be working…
Any suggestions whats going wrong?
thanks!!!
January 15, 2020 at 12:34 am #78086adminKeymasterThat is not an absolute path. An absolute path should never have the “http” keyword there. An absolute path should look like the following:
/www/htdocs/myaccount/weblab.geronne.de/wp-content/themes/customizr-pro-child/ger_custom.php
September 13, 2020 at 4:16 pm #78087duncaagnesMemberI’ve inserted the below code (real username is used in the code) into my Enfold-child themes functions.php, but the changes I make in the hun.php do not take affect.
If I change the hun.php in the original folder, changes appear immediately, so changes in hun.php should be ok. The functions.php language override code works for the theme itself, so the setup of the child theme should be also ok.
Please help! How can I make this work?
Inserted code:
add_filter(’emember_language_loading_override’, ‘load_my_custom_emember_language’);
function load_my_custom_emember_language()
{
$language_file = “/home/username/public_html/wp-content/plugins/wp-emember-child-lang/hun.php”;
include_once($language_file);
return “custom-file-loaded”;
}
September 13, 2020 at 9:06 pm #78088wzpModeratorAre you sure about the absolute file path?
September 14, 2020 at 8:16 pm #78089duncaagnesMemberMy storage provider uses Cpanel. As long as I know, absolute path in Cpanel always starts with /home/username/..
Cpanel has a built in editor for php files, that shows the path. I copied that and pasted in the code.
Is there a way to check if the path is correct?
September 14, 2020 at 11:03 pm #78090wzpModeratorIs there a way to check if the path is correct?
In the directory /home/username/public_html/wp-content/plugins/wp-emember-child-lang create file hello.html that contains:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>Then see if the URL yoursite/wp-content/plugins/wp-emember-child-lang/hello.html does what we think it should do.
Next, create file test.html in the same directory, containing:
<html>
<div w3-include-html="/home/username/public_html/wp-content/plugins/wp-emember-child-lang/hello.html"></div>
</html>Then see if the URL yoursite/wp-content/plugins/wp-emember-child-lang/test.html does what we think it should do.
September 15, 2020 at 7:59 am #78091duncaagnesMemberThanks for the quick answer.
hello.html works (displays “Hello World’; ?>”)
test.html does not work (blank page appears)
On the other hand, I created a .php file with the following content, to get the absolute root from server:
<?php
echo $_SERVER[“DOCUMENT_ROOT”]
?>
The result was:
/home/username/public_html
The root path seems to be ok, but not working for some reason. Any ida, why? Or any other solution?
September 15, 2020 at 8:23 am #78092adminKeymasterThat means the path you are assuming in not correct (it is not finding the script there). You can’t really assume a path.
Add the following PHP code to your “hello.html” file which will output the current working directory. That will show you the path info. You can then work out the absolute path to the language file.
<?php
echo getcwd();
?>September 15, 2020 at 4:03 pm #78093duncaagnesMemberIf I put the code in the hello.html, nothing happens, but if I create a .PHP file with the this code alone, ‘<?php echo getcwd(); ?>’ it provides the exect same result I’m using in “test.html” and “functions.php”:
/home/username/public_html/wp-content/plugins/wp-emember-child-lang
It seems,
-
AuthorPosts
- You must be logged in to reply to this topic.