WordPress filter hook

pll_sanitize_string_translation

Fired by 3 WordPress plugins, running on 907K+ sites between them.

“Filters the string translation before it is saved in DB. Allows to sanitize strings registered with pll_register_string().”

How to use pll_sanitize_string_translation

It's a filter: your callback receives the value and 4 more arguments, and must return the (changed) value. Add this to your theme's functions.php or a small custom plugin:

functions.php
add_filter( 'pll_sanitize_string_translation', function( $translation, $arg2, $arg3, $arg4, $arg5 ) {
	// Change $translation here.
	return $translation;
}, 10, 5 );

Argument names come from Polylang's source. Other plugins may pass different values: check the call in the plugin you're targeting below.

3 plugins that fire pll_sanitize_string_translation

Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.

  1. Polylang icon Polylang900,000+ installs apply_filters( 'pll_sanitize_string_translation', $translation, $this->strings[ $key ]['name'], $this->strings[ $key ]['context'], $this->strings[ $key ]['string'], $mo->translate_if_any( $this->strings[ $key ]['string'] ) ) src/settings/table-string.php:449
  2. Ray Enterprise Translation icon Ray Enterprise Translation7,000+ installs apply_filters( 'pll_sanitize_string_translation', $translation, $strings[ $key ], $this->name ) include/group-string.php:160
  3. LATW AI Translation for Polylang icon LATW AI Translation for Polylang10+ installs apply_filters( 'pll_sanitize_string_translation', (string) $item['translation'], isset($entry['name']) ? $entry['name'] : '', isset($entry['context']) ? $entry['context'] : '', $source, $mo->translate_if_any($source) ) includes/class-latwaitp-string-translator.php:336

Need a customisation built on this hook?

Tell us what you want to change and which plugin it's for. We'll write it, test it and send it back as a small plugin.