Answer the question
In order to leave comments, you need to log in
Why does this plugin break ACF?
Good afternoon.
There is such a simple plugin that transliterates the post link and filenames in WP:
if ( !defined( 'WPINC' ) ) {
die;
}
add_action( 'init', function() {
new Rus_Transliteration;
} );
class Rus_Transliteration {
/**
* Set public actions and filters
*/
public function __construct()
{
add_action( 'sanitize_title', array( $this, 'sanitize_title' ), 9 );
add_action( 'sanitize_file_name', array( $this, 'sanitize_file_name' ), 9 );
}
/**
* Replace latin with cyrillic using Mosmetro
*/
private function replace_latin( $name )
{
$replace = array(
'ЬА' => 'YA',
'ЬЕ' => 'YE',
'ЬИ' => 'YI',
'ЬО' => 'YO',
'ЬУ' => 'YU',
'ЬЭ' => 'YE',
'ЪА' => 'YA',
'ЪЕ' => 'YE',
'ЪИ' => 'YI',
'ЪО' => 'YO',
'ЪУ' => 'YU',
'ЪЭ' => 'YE',
'ЫЙ' => 'Y',
'ИЙ' => 'Y',
'А' => 'A',
'Б' => 'B',
'В' => 'V',
'Г' => 'G',
'Д' => 'D',
'Е' => 'E',
'ЬЁ' => 'YO',
'ЪЁ' => 'YO',
'Ё' => 'E',
'Ж' => 'ZH',
'З' => 'Z',
'И' => 'I',
'Й' => 'Y',
'К' => 'K',
'Л' => 'L',
'М' => 'M',
'Н' => 'N',
'О' => 'O',
'П' => 'P',
'Р' => 'R',
'С' => 'S',
'Т' => 'T',
'У' => 'U',
'Ф' => 'F',
'Х' => 'KH',
'ТЦ' => 'S',
'Ц' => 'TS',
'Ч' => 'CH',
'Ш' => 'SH',
'Щ' => 'SCH',
'Ъ' => '',
'Ы' => 'Y',
'Ь' => '',
'Э' => 'E',
'Ю' => 'YU',
'Я' => 'YA',
'ьа' => 'ya',
'ье' => 'ye',
'ьи' => 'yi',
'ьо' => 'yo',
'ьу' => 'yu',
'ьэ' => 'ye',
'ъа' => 'ya',
'ъе' => 'ye',
'ъи' => 'yi',
'ъо' => 'yo',
'ъу' => 'yu',
'ъэ' => 'ye',
'ый' => 'y',
'ий' => 'y',
'а' => 'a',
'б' => 'b',
'в' => 'v',
'г' => 'g',
'д' => 'd',
'е' => 'e',
'ьё' => 'yo',
'ъё' => 'yo',
'ё' => 'e',
'ж' => 'zh',
'з' => 'z',
'и' => 'i',
'й' => 'y',
'к' => 'k',
'л' => 'l',
'м' => 'm',
'н' => 'n',
'о' => 'o',
'п' => 'p',
'р' => 'r',
'с' => 's',
'т' => 't',
'у' => 'u',
'ф' => 'f',
'х' => 'h',
'тц' => 's',
'ц' => 'ts',
'ч' => 'ch',
'ш' => 'sh',
'щ' => 'sch',
'ъ' => '',
'ы' => 'y',
'ь' => '',
'э' => 'e',
'ю' => 'yu',
'я' => 'ya'
);
$name = strtr( $name, $replace );
return $name;
}
/**
* Leave only latin chars and digits in slugs
*/
public function sanitize_title( $name )
{
$name = $this->replace_latin( $name );
// Leave only latin chars and digits in slugs
$name = preg_replace( '/[^a-z0-9]/i', '-', $name );
return $name;
}
/**
* Update file names
*/
public function sanitize_file_name( $name )
{
$name = $this->replace_latin( $name );
if ( seems_utf8( $name ) ) {
$name = urldecode( $name );
}
return $name;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question