Skip to content

Commit

Permalink
Merge cb68685 into f544afb
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Mar 31, 2023
2 parents f544afb + cb68685 commit 5f3be50
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cyr-to-lat.php
Expand Up @@ -10,7 +10,7 @@
* Plugin Name: Cyr-To-Lat
* Plugin URI: https://wordpress.org/plugins/cyr2lat/
* Description: Convert Non-Latin characters in post and term slugs to Latin characters. Useful for creating human-readable URLs. Based on the original plugin by Anton Skorobogatov.
* Version: 5.5.1
* Version: 5.5.2
* Requires at least: 5.1
* Requires PHP: 5.6.20
* Author: Sergey Biryukov, Mikhail Kobzarev, Igor Gergel
Expand Down Expand Up @@ -43,7 +43,7 @@
/**
* Plugin version.
*/
define( 'CYR_TO_LAT_VERSION', '5.5.1' );
define( 'CYR_TO_LAT_VERSION', '5.5.2' );

/**
* Path to the plugin dir.
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Expand Up @@ -3,7 +3,7 @@ Contributors: SergeyBiryukov, mihdan, karevn, webvitaly, kaggdesign
Tags: cyrillic, belorussian, ukrainian, bulgarian, macedonian, georgian, kazakh, latin, l10n, russian, cyr-to-lat, cyr2lat, rustolat, slugs, translations, transliteration
Requires at least: 5.1
Tested up to: 6.2
Stable tag: 5.5.1
Stable tag: 5.5.2
Requires PHP: 5.6.20
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -194,6 +194,9 @@ Yes you can!

== Changelog ==

= 5.5.2 (31.03.2023) =
* Fixed transliteration of tags with Polylang and WPML.

= 5.5.1 (21.03.2023) =
* Fixed transliteration of attributes on WC frontend.

Expand Down
6 changes: 5 additions & 1 deletion src/php/class-main.php
Expand Up @@ -233,7 +233,11 @@ public function sanitize_title( $title, $raw_title = '', $context = '' ) {
! $title ||
// Fixed bug with `_wp_old_slug` redirect.
'query' === $context ||
doing_filter( 'pre_term_slug' )
// Transliterate on pre_term_slug with Polylang and WPML only.
(
doing_filter( 'pre_term_slug' ) &&
! ( class_exists( 'Polylang' ) || class_exists( 'SitePress' ) )
)
) {
return $title;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/bootstrap.php
Expand Up @@ -39,7 +39,7 @@
/**
* Plugin version.
*/
const CYR_TO_LAT_TEST_VERSION = '5.5.1';
const CYR_TO_LAT_TEST_VERSION = '5.5.2';

/**
* Path to the plugin dir.
Expand Down
38 changes: 38 additions & 0 deletions tests/phpunit/tests/class-test-main.php
Expand Up @@ -320,6 +320,17 @@ public function test_init_hooks_when_not_allowed() {
$subject->init_hooks();
}

/**
* Test that sanitize_title() does nothing when title is empty.
*/
public function test_sanitize_title_empty_title() {
$subject = Mockery::mock( Main::class )->makePartial();

$title = '';

self::assertSame( $title, $subject->sanitize_title( $title ) );
}

/**
* Test that sanitize_title() does nothing when context is 'query'
*/
Expand All @@ -333,6 +344,33 @@ public function test_sanitize_title_query_context() {
self::assertSame( $title, $subject->sanitize_title( $title, $raw_title, $context ) );
}

/**
* Test that sanitize_title() does nothing on pre_term_slug filter with Polylang or SitePress.
*/
public function test_sanitize_title_pre_term_slug() {
$subject = Mockery::mock( Main::class )->makePartial();
WP_Mock::userFunction( 'doing_filter' )->with( 'pre_term_slug' )->andReturn( true );

FunctionMocker::replace(
'class_exists',
static function ( $class ) {
if ( 'Polylang' === $class ) {
return false;
}

if ( 'SitePress' === $class ) {
return false;
}

return null;
}
);

$title = 'some title';

self::assertSame( $title, $subject->sanitize_title( $title ) );
}

/**
* Test that sanitize_title() returns ctl_pre_sanitize_title filter value if set
*/
Expand Down

0 comments on commit 5f3be50

Please sign in to comment.