Title: Infinite loop
Last modified: January 5, 2019

---

# Infinite loop

 *  [Kerfred](https://wordpress.org/support/users/kerfred/)
 * (@kerfred)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/infinite-loop-17/)
 * The “locale” filter which calls the on_locale() function can raise an infinite
   loop, that makes the browser tab crash.
 * A solution is to unhook the “locale” filter at the beginning of the on_locale()
   function, then rehook it before each “return” in the same function.
    Here is 
   the amended function (in file wp-native-dashboard.php):
 *     ```
       	//setup the correct user prefered language
       	function on_locale($loc) {
       		// FG: To avoid an infinite loop
       		remove_filter('locale', array(&$this, 'on_locale'), 9999);
   
       		if($this->orig_locale === false) $this->orig_locale = $loc;
       		$skip = !$this->options->enable_login_selector && !$this->options->enable_profile_extension && !$this->options->enable_language_switcher && !$this->options->enable_adminbar_switcher;
       		if ((is_admin() && !$skip) || ($this->options->translate_front_adminbar && $this->user_agent_is_wp_native_dashboard)) {
       			if (function_exists('wp_get_current_user')) {
       				$u = wp_get_current_user();
       				if (!is_object($u) || $u->ID == 0) return $loc; //bugfix: for ajax based login's
       				if (!isset($u->wp_native_dashboard_language)) {
       					if ($loc)
       						$u->wp_native_dashboard_language = $loc;
       					else
       						$u->wp_native_dashboard_language = 'en_US';
       				}
   
       				if(($u->wp_native_dashboard_language != 'en_US') && !@file_exists(WP_LANG_DIR.'/' . $u->wp_native_dashboard_language.'.mo')) {
       					// FG: Rehook this function
       					add_filter('locale', array(&$this, 'on_locale'), 9999);
       					return $loc ? $loc : 'en_US';
       				}
       				// FG: Rehook this function
       				add_filter('locale', array(&$this, 'on_locale'), 9999);
       				return $u->wp_native_dashboard_language;
       			}
       		}
       		// FG: Rehook this function
       		add_filter('locale', array(&$this, 'on_locale'), 9999);
       		return $loc;
       	}
       ```
   

The topic ‘Infinite loop’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wp-native-dashboard_d8d8d8.svg)
 * [WP Native Dashboard](https://wordpress.org/plugins/wp-native-dashboard/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-native-dashboard/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-native-dashboard/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-native-dashboard/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-native-dashboard/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-native-dashboard/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [Kerfred](https://wordpress.org/support/users/kerfred/)
 * Last activity: [7 years, 5 months ago](https://wordpress.org/support/topic/infinite-loop-17/)
 * Status: not resolved