wordpress blog basepath - wordpress

im working on a wordpress blog tryin to develop a multilanguage system.
Whenever the user clicks on his language button the lang query parameter is added to the url
Ex. localhost/my-blog?lang=es
Everything works.The point is i have the blog main menu that has links to different sections of the site that are using the wordpress bloginfo('url') :
Ex. contact us
And whenever the user choose it's language at the home-page and then clicks on "contact us"
he receive this wrong link:
localhost/my-blog?lang=es/contact-us
which wordpress function you use guys for this kind of things?
thanks
Luca

I think this type of url query will get you into trouble in the future, why not conform to using either a session value or base cookie to store the users choice,
then that way you can simply add some code to your functions.php file to read the session value or cookie, and return the translation type?
there is also this plugin xili-language
ie: functions.php
// START THE SESSION
function start_session(){
session_start();
}
add_action('init', 'start_session', 1);
function set_lang_pref($lang_pref){
if(isset($_GET['lang']) && ($_GET['lang']!=''){
$setlang = $_GET['lang'];
switch($setlang){
case "es" :
$lang = "es_ES";
$_SESSION['selectedlanguage']=$lang;
break;
}
}else{
return false;
}
}
the code is really rough, but you get the idea..?
store the users choice,
check for that choice,
if its been set then use that value as the language pref on the site..?
else just revert back to the default..

Related

Redirect "dumb" URL to Author's custom post

I have created a website whereby users register and create their own templated profile pages. The profile pages are automatically created as Custom Posts upon registration, with the user being set as the Author of their specific post (profile).
(Users can only ever have one Custom Post)
I want to redirect a "dumb" URL like www.website.com/my-profile to a user's custom post when they are logged in.
For example, when John Smith visits www.website.com/my-profile he is directed to his profile page: www.website.com/users/john.smith
I have found many PHP solutions going the other way, but I can't seem to find a solution that does what I need. Any help would be greatly appreciated. Thanks!
This may not be the correct answer to the original query, but proved to be a solid workaround:
Instead of redirecting www.website.com/my-profile to www.website.com/users/john.smith every time it is entered in the URL bar, I created a shortcode that could be used when needed throughout the site.
add_shortcode('bt_redirect_user_link', 'bt_redirect_user_link');
function bt_redirect_user_link ($atts) {
// check if user is logged in
if (is_user_logged_in()) {
// get current user object
$current_user = wp_get_current_user();
// get user nickname
$user_nickname = $current_user->data->user_nicename;
// set the link href
$link_href = '/users/' . $user_nickname;
// output the link html
return $link_href;
}
}
Fortunately for me, the www.website.com/my-profile link (which needs to be redirected) is only available on buttons/icons visible to logged in users. This may not be a fully workable solution for websites that need to display the link to logged out users, and I assume IF/ELSE statements would needed to be added in those cases.

Create an external link on wordpress site passing the username as a querystring parameter

I am adding a quick link on my wordpress site but that link is a custom link that redirects with the current username thats logged in. So, the link would be something like "http://www.example.com?currentuser={username}". I want this {username} to come from the system but I am not able to find either the right token for it or not sure what I am doing is correct? I am trying to add a quick link -> custom link on my site but needs the current username to be able to pass to as my querystring parameter. How should I go about accomplishing this on the wordpress site?
Try if following is useful.
$current_user = wp_get_current_user();
$loggedinuser = $current_user->user_login;
$linkurl = get_site_url().'/?currentuser='.$loggedinuser;
$displaylink = 'Click Here';
echo($displaylink);

Wordpress: Polylang and ACF Options page on ajax calls takes default language value

I'm working on a website, which is multilingual.
We're using Polylang and the ACF custom fields plugin.
Works fine in general, the issue is with the ACF Option pages.
The option pages are translated also in different languages.
The content we are taking from there is being displayed according to translation - in english on the english version of a page, french on the french etc.
The problem: We have a contact us form, where we take the recipients email address from the ACF option pages.
(We want to send it to a different recepient when its a different language.)
Here it always takes the email address from the default language option page and I don't understand why.
We are taking the email recipient for the ajax call with get field command, like on pages displaying content:
get_field('service_email', 'option' );
Anyone got an idea what could cause this? Or where to look?
In the end we found the solution. It took a bit of digging, but I hope this helps if anyone encounters the same issue.
We needed to add the following setup in the functions.php of our theme to have the ACF options pages also translated for the each language:
// Translating Options Page Compatibility
// add filter with the path to your acf installation
add_filter('acf/settings/default_language', 'my_settings_default_language');
add_filter('acf/settings/current_language', 'my_settings_current_language');
function my_settings_default_language( $lang ) {
if($lang == "") {
$lang = pll_default_language(); // pll_ is a polylang function
}
return $lang;
}
function jfrog_settings_current_language( $lang ) {
$lang = pll_current_language();
return $lang;
}
Side Note: We're using a theme installed version of ACF.
hope this helps, Cheers

how to change the link in the wordpress email with newpassword?

how to change the link in the wordpress email with newpassword?
this information we get when we click on forgot password.
username : admin
password : admin
http://www.example.com/wp-login.php
here i want to change this url "http://www.example.com/wp-login.php" and set my own url... how can i do?
some reference code:
if ( !function_exists('is_user_logged_in') ) :function is_user_logged_in() {
$user = wp_get_current_user();
You can hook into the retrieve_password_message filter
function someFunction($message, $key){
}
add_filter('retrieve_password_message', 'someFunction');
You would then have to use the "someFunction" function to parse the $message variable and change the link.
The message variable contains the entire message. So you could simply trim the message based on the number of characters then tack on your new link...
HTH
(Untested)
Using hooks would be my first thought so that you wouldn't have to edit any core files, however I have used the SB Welcome Email Editor plugin a couple times for this exact reason. Their are a couple plugins like this out their and they are fairly light weight and allow full customization of all Wordpress generated emails.
Try using a plugin such as Theme My Login, which does everything for you.
Editing core wordpress files is never a good idea, when updating wordpress, you'll loose all your work.
You can simply follow steps if you want to edit your code file.
Go to your wordpress folder. Look for the following files:
1. /wp-login.php
2. /includes/functions.php
Change the all the codes which contains wp-login.php into your custom URL.
for example: admin.php or client-login.php
Now you can changed your login/signup URL into your custom URL.
Known issue: You can find some database error if you make any mistakes. Just refresh the page and try with the customized Url it will work...
Example site I used here : http://androideveloper.com/admin.php from http://androideveloper.com/wp-login.php
Cheers.

WP: redirect users to a certain category using cookies

Basically like cragslist. once you select city on craigslist, nexttime when you go to the site, it redirects you to the city you selected.
What I want to achieve: When a person comes to the site and selects a particular category, the next time they come to the site (returning user) - the page will open up on that category section.
I would think this would be fairly easy to do via setting a cookie when the visitor clicks on the category link (or when the category page loads). When they return the following time, the cookie is read and then the page redirects accordingly.
Unfortunately my knowledge of PHP and cookies is limited, (hence my search for answers) so I need to ask if anyone can help me out!
Anyone have any ideas?
Thanks!
markratledge has a good link, but WordPress has a built in function to redirect users and pass an http status code as well as it's own preferred method of settings cookies.
wp_redirect() Function
Reference
Setting Cookies in WordPress via MTSTS
Give this a shot. I'm not too sure if it works, because I can't test it out right now, but it should point you in the right direction.
function user_cat()
{
//Check to see if our cookie is set
if(isset($_COOKIE['visitorhome']))
{
//Redirect to the link defined in the cookie
wp_redirect($_COOKIE['visitorhome'], 302);
}
else
{
//If it's a category page than get the current URL set the cookie with it.
if(is_category())
{
$user_cat = get_permalink();
setcookie("visitorhome", $user_cat, time()+86400, "/", str_replace('http://www','',get_bloginfo('url')) );
}
}
}
add_action('init', 'user_cat');
Read this article on how to set and get cookies with PHP: http://www.w3schools.com/PHP/php_cookies.asp
Then read this page on PHP header redirecting: http://php.net/manual/en/function.header.php
Put the two together, and you can direct users anywhere!
Good luck.

Resources