wpcf7_switch_locale()CF7 1.0

Switches translation locale, calls the callback, then switches back to the original locale.

Хуков нет.

Возвращает

Разное. The return value of the callback.

Использование

wpcf7_switch_locale( $locale, $callback, ...$args );
$locale(строка) (обязательный)
Locale code.
$callback(callable) (обязательный)
The callable to be called.
...$args (обязательный)
-

Код wpcf7_switch_locale() CF7 5.7.3

function wpcf7_switch_locale( $locale, callable $callback, ...$args ) {
	static $available_locales = null;

	if ( ! isset( $available_locales ) ) {
		$available_locales = array_merge(
			array( 'en_US' ),
			get_available_languages()
		);
	}

	$previous_locale = determine_locale();

	$do_switch_locale = (
		$locale !== $previous_locale &&
		in_array( $locale, $available_locales, true ) &&
		in_array( $previous_locale, $available_locales, true )
	);

	if ( $do_switch_locale ) {
		wpcf7_unload_textdomain();
		switch_to_locale( $locale );
		wpcf7_load_textdomain( $locale );
	}

	$result = call_user_func( $callback, ...$args );

	if ( $do_switch_locale ) {
		wpcf7_unload_textdomain( true );
		restore_previous_locale();
		wpcf7_load_textdomain( $previous_locale );
	}

	return $result;
}