L
L
Lelouch2020-05-12 16:10:36
WordPress
Lelouch, 2020-05-12 16:10:36

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;
  }

}


The problem is that when the plugin is activated, ACF PRO starts to work incorrectly. When the plugin is active, ACF does not save any new field to the database (both in posts and on settings pages). There are no errors in this. I can't understand why he bothers him.

I tried to disable all plugins except ACF PRO and this + test with the default theme. The problem is in this code.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question