{"id":8314210,"date":"2016-10-17T12:54:52","date_gmt":"2016-10-17T12:54:52","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/redirect-based-on-language\/"},"modified":"2016-10-17T12:54:52","modified_gmt":"2016-10-17T12:54:52","slug":"redirect-based-on-language","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/redirect-based-on-language\/","title":{"rendered":"Redirect based on Language"},"content":{"rendered":"<p>Hi, I was having trouble with the pll_current_language function. The function below will echo helo but not the current language. Trying to determine language on login for redirect to fr or en page. Thx<\/p>\n<pre><code>function cm_redirect_users_by_role() {\n \n    $current_user   = wp_get_current_user();\n    $role_name      = $current_user-&gt;roles[0];\n\t\n\t\n\tif ( function_exists( &#039;pll_current_language&#039; ) ) {\n\t\techo &quot;helo&quot;;\n\t\t$current_lang = pll_current_language();\n\t\techo $current_lang; exit;\n\t\t}\n\t\t\n    if ( &#039;subscriber&#039; === $role_name ) {\n        wp_redirect( &#039;http:\/\/coda-services.com\/project-upload&#039; );\n    } \/\/ if\n \n} \/\/ cm_redirect_users_by_role\nadd_action( &#039;admin_init&#039;, &#039;cm_redirect_users_by_role&#039; );\n\n}<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-8314210","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/8314210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/8314210\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=8314210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}