WP_Locale_Switcher::restore_previous_locale() WordPress Method

TheWP_Locale_Switcher::restore_previous_locale()method is used to restore the previous locale that was active before the current one. This is useful for restoring the original locale after a user has changed the locale for a specific action or request.

WP_Locale_Switcher::restore_previous_locale() #

Restores the translations according to the previous locale.


Return

(string|false) Locale on success, false on failure.


Top ↑

Source

File: wp-includes/class-wp-locale-switcher.php

	public function restore_previous_locale() {
		$previous_locale = array_pop( $this->locales );

		if ( null === $previous_locale ) {
			// The stack is empty, bail.
			return false;
		}

		$locale = end( $this->locales );

		if ( ! $locale ) {
			// There's nothing left in the stack: go back to the original locale.
			$locale = $this->original_locale;
		}

		$this->change_locale( $locale );

		/**
		 * Fires when the locale is restored to the previous one.
		 *
		 * @since 4.7.0
		 *
		 * @param string $locale          The new locale.
		 * @param string $previous_locale The previous locale.
		 */
		do_action( 'restore_previous_locale', $locale, $previous_locale );

		return $locale;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.