: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Retrieves an associative array of languages to which
* this plugin is translated.
* @return array Array of languages.
if ( ! empty( $l10n ) ) {
require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
$api = translations_api( 'plugins', array(
'slug' => 'contact-form-7',
'version' => WPCF7_VERSION,
or empty( $api['translations'] ) ) {
foreach ( (array) $api['translations'] as $translation ) {
if ( ! empty( $translation['language'] )
and ! empty( $translation['english_name'] ) ) {
$l10n[$translation['language']] = $translation['english_name'];
* Returns true if the given locale code looks valid.
* @param string $locale Locale code.
function wpcf7_is_valid_locale( $locale ) {
if ( ! is_string( $locale ) ) {
$pattern = '/^[a-z]{2,3}(?:_[a-zA-Z_]{2,})?$/';
return (bool) preg_match( $pattern, $locale );
* Returns true if the given locale is an RTL language.
function wpcf7_is_rtl( $locale = '' ) {
static $rtl_locales = array(
'ary' => 'Moroccan Arabic',
'azb' => 'South Azerbaijani',
and function_exists( 'is_rtl' ) ) {
if ( empty( $locale ) ) {
$locale = determine_locale();
return isset( $rtl_locales[$locale] );
* Loads a translation file into the plugin's text domain.
* @param string $locale Locale code.
* @return bool True on success, false on failure.
function wpcf7_load_textdomain( $locale = '' ) {
WP_LANG_DIR . '/plugins/',
sprintf( '%s-%s.mo', WPCF7_TEXT_DOMAIN, $locale )
return load_textdomain( WPCF7_TEXT_DOMAIN, $mofile, $locale );
* Unloads translations for the plugin's text domain.
* @param bool $reloadable Whether the text domain can be loaded
* @return bool True on success, false on failure.
function wpcf7_unload_textdomain( $reloadable = false ) {
return unload_textdomain( WPCF7_TEXT_DOMAIN, $reloadable );
* Switches translation locale, calls the callback, then switches back
* to the original locale.
* @param string $locale Locale code.
* @param callable $callback The callable to be called.
* @param mixed $args Parameters to be passed to the callback.
* @return mixed The return value of the callback.
function wpcf7_switch_locale( $locale, callable $callback, ...$args ) {
static $available_locales = null;
if ( ! isset( $available_locales ) ) {
$available_locales = array_merge(
get_available_languages()
$previous_locale = determine_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 );