idk.man
Forum Replies Created
-
I know, I agree, other than this lack of a specific feature though the plugin is incredible and very robust!
No help needed but would love for you guys to integrate this or a similar solution in future iterations of Translate Press for specific applications like this one where a user has to select a language upon login (if the page is restricted). Thank you so much!
Never mind, I was able to resolve it based on your idea 🙂 thank you!
Hey, I ended up consulting everyone’s favorite coding body, chatGPT for this.
For my use case, we are dealing with a restricted site content so I needed the language to be selected on the login screen. Attempts to generate the translate press language switcher didn’t work so instead I used the default wordpress language switcher on the login page. The way it works is that it takes the cookie that stores the user preference on language and based on that, redirects to the appropriate url.
It wrote me a simple plugin (basically save this file as a whatever you wanna call it .php file, zip it, and upload it and activate it). It will show one error upon activation: “The plugin generated 1 character of unexpected output during activation.” but after activation it’s fine and the wordpress debug log didn’t show any concerns.
<?php /* Plugin Name: Custom Login Language Redirect Description: Adds a language selector to the WordPress login screen and redirects users based on their selection. Version: 1.0 Author: Your Name */ // Add language switcher to login form function tp_add_language_switcher_to_login() { $languages = apply_filters('translatepress_get_translated_languages', array()); echo '<p>'; echo '<label for="language">Choose Language:</label>'; echo '<select name="language" id="language">'; foreach ($languages as $lang) { if (in_array($lang['language'], ['en', 'fr'])) { echo '<option value="' . esc_attr($lang['language']) . '">' . esc_html($lang['name']) . '</option>'; } } echo '</select>'; echo '</p>'; } add_action('login_form', 'tp_add_language_switcher_to_login'); // Redirect users based on language selection function tp_redirect_users_based_on_language($redirect_to, $requested_redirect_to, $user) { if (isset($_POST['language'])) { $language = sanitize_text_field($_POST['language']); $redirect_to = home_url('/' . $language . '/'); } return $redirect_to; } add_filter('login_redirect', 'tp_redirect_users_based_on_language', 10, 3);I hope this helps anyone that ever needs a similar application.
- This reply was modified 2 years, 8 months ago by idk.man.
@frifugl I appreciate your response. Thank you so much. I’ve been desperate to find an answer to this because it’s such a nightmare from a user experience point of view. Is there anyone that helped you that I can ask just one question from? If not, I understand and thanks for responding again.
@frifugl any chance you can share this with me? I am looking to achieve the exact same thing
Forum: Hacks
In reply to: Problem with simplecdn.maxcdn.com@scott White: THANK YOU so much for the explanation and provided fix. Do you know of any way to find out all the places our site is calling the cdn address?
Forum: Hacks
In reply to: Problem with simplecdn.maxcdn.comSame problem here. Does anyone know how to fix it?