Skip to content

Commit

Permalink
Merge e159f75 into 06c6497
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Sep 7, 2021
2 parents 06c6497 + e159f75 commit e91b308
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 184 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.2.3
* Version: 5.2.4
* Requires at least: 5.1
* Requires PHP: 5.6.20
* Author: Sergey Biryukov, Mikhail Kobzarev, Igor Gergel
Expand All @@ -36,7 +36,7 @@
/**
* Plugin version.
*/
define( 'CYR_TO_LAT_VERSION', '5.2.3' );
define( 'CYR_TO_LAT_VERSION', '5.2.4' );

/**
* Path to the plugin dir.
Expand Down
6 changes: 5 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: 5.8
Stable tag: 5.2.3
Stable tag: 5.2.4
Requires PHP: 5.6.20

Convert Non-Latin characters in post, page and term slugs to Latin characters.
Expand Down Expand Up @@ -188,6 +188,10 @@ Yes you can!

== Changelog ==

= 5.2.4 (07.09.2021) =
* Fix issue with not showing WooCommerce variable product attributes.
* Fix issue with Elementor and WPML, endless loop.

= 5.2.3 (07.09.2021) =
* Fix issue with WP Foro plugin - transliterate topic slug when created on frontend.
* Fix bug with Polylang on REST request.
Expand Down
42 changes: 24 additions & 18 deletions src/php/class-main.php
Expand Up @@ -108,16 +108,18 @@ class Main {
*/
protected $wpml_locale;

/**
* WPML languages.
*
* @var array
*/
protected $wpml_languages;

/**
* Main constructor.
*/
public function __construct() {
$this->request = new Request();

if ( ! $this->request->is_allowed() ) {
return;
}

$this->request = new Request();
$this->settings = new Settings();
$this->admin_notices = new Admin_Notices();
$requirements = new Requirements( $this->settings, $this->admin_notices );
Expand Down Expand Up @@ -149,10 +151,6 @@ public function __construct() {
* @noinspection PhpUndefinedClassInspection
*/
public function init() {
if ( ! $this->request->is_allowed() ) {
return;
}

if ( $this->request->is_cli() ) {
try {
/**
Expand All @@ -177,7 +175,10 @@ public function init_hooks() {
add_filter( 'sanitize_file_name', [ $this, 'sanitize_filename' ], 10, 2 );
add_filter( 'wp_insert_post_data', [ $this, 'sanitize_post_name' ], 10, 2 );
add_filter( 'pre_insert_term', [ $this, 'pre_insert_term_filter' ], PHP_INT_MAX, 2 );
add_filter( 'get_terms_args', [ $this, 'get_terms_args_filter' ], PHP_INT_MAX, 2 );

if ( ! $this->request->is_frontend() ) {
add_filter( 'get_terms_args', [ $this, 'get_terms_args_filter' ], PHP_INT_MAX, 2 );
}

if ( class_exists( Polylang::class ) ) {
add_filter( 'locale', [ $this, 'pll_locale_filter' ] );
Expand Down Expand Up @@ -372,8 +373,6 @@ public function transliterate( $string ) {
* @link https://kagg.eu/how-to-catch-gutenberg/
*
* @return bool
*
* @noinspection PhpIncludeInspection
*/
private function is_classic_editor_plugin_active() {
// @codeCoverageIgnoreStart
Expand Down Expand Up @@ -633,10 +632,14 @@ public function wpml_locale_filter( $locale ) {
* @return string|null
*/
protected function get_wpml_locale() {
$language_code = wpml_get_current_language();
$languages = apply_filters( 'wpml_active_languages', null );
$language_code = wpml_get_current_language();
$this->wpml_languages = (array) apply_filters( 'wpml_active_languages', [] );

return isset( $languages[ $language_code ] ) ? $languages[ $language_code ]['default_locale'] : null;
return (
isset( $this->wpml_languages[ $language_code ] ) ?
$this->wpml_languages[ $language_code ]['default_locale'] :
null
);
}

/**
Expand All @@ -649,9 +652,12 @@ protected function get_wpml_locale() {
* @noinspection PhpUnusedParameterInspection
*/
public function wpml_language_has_switched( $language_code, $cookie_lang, $original_language ) {
$languages = apply_filters( 'wpml_active_languages', null );
$language_code = (string) $language_code;

$this->wpml_locale = isset( $languages[ $language_code ] ) ? $languages[ $language_code ]['default_locale'] : null;
$this->wpml_locale =
isset( $this->wpml_languages[ $language_code ] ) ?
$this->wpml_languages[ $language_code ]['default_locale'] :
null;
}

/**
Expand Down
23 changes: 0 additions & 23 deletions src/php/class-request.php
Expand Up @@ -14,15 +14,6 @@
*/
class Request {

/**
* Is allowed request for plugin to work.
*
* @return bool
*/
public function is_allowed() {
return ! $this->is_frontend() || ( $this->is_frontend() && $this->is_post() );
}

/**
* Is frontend.
*
Expand Down Expand Up @@ -97,18 +88,4 @@ protected function get_rest_route() {

return $is_rest ? substr( $current_path, strlen( $rest_path ) ) : '';
}

/**
* If current request is POST.
*
* @return bool
*/
public function is_post() {
$request_method = filter_var(
isset( $_SERVER['REQUEST_METHOD'] ) ? wp_unslash( $_SERVER['REQUEST_METHOD'] ) : '',
FILTER_SANITIZE_STRING
);

return 'POST' === $request_method;
}
}
7 changes: 3 additions & 4 deletions tests/phpunit/Settings/Abstracts/SettingsBaseTest.php
Expand Up @@ -199,6 +199,7 @@ public function test_tab_name() {
* Test get_class_name().
*
* @throws ReflectionException ReflectionException.
* @noinspection PhpParamsInspection
*/
public function test_get_class_name() {
$subject = Mockery::mock( SettingsBase::class )->makePartial();
Expand Down Expand Up @@ -463,7 +464,6 @@ public function test_base_admin_enqueue_scripts() {
*
* @dataProvider dp_test_setup_sections
* @throws ReflectionException ReflectionException.
* @noinspection NullCoalescingOperatorCanBeUsedInspection
*/
public function test_setup_sections( $tabs ) {
$tab_option_page = 'cyr-to-lat';
Expand Down Expand Up @@ -664,7 +664,6 @@ public function test_get_tabs() {
* Test get_active_tab().
*
* @throws ReflectionException ReflectionException.
* @noinspection JsonEncodingApiUsageInspection
*/
public function test_get_active_tab() {
$tab = Mockery::mock( SettingsBase::class )->makePartial()->shouldAllowMockingProtectedMethods();
Expand Down Expand Up @@ -1624,7 +1623,7 @@ public function test_load_plugin_text_domain() {
* Test is_options_screen().
*
* @param mixed $current_screen Current admin screen.
* @param boolean $is_main_menu_page It it the main menu page.
* @param boolean $is_main_menu_page It is the main menu page.
* @param boolean $expected Expected result.
*
* @dataProvider dp_test_is_options_screen
Expand All @@ -1648,7 +1647,7 @@ public function test_is_options_screen( $current_screen, $is_main_menu_page, $ex
}

/**
* Data provider for test_is_options_screen(0.
* Data provider for test_is_options_screen().
*
* @return array
*/
Expand Down
2 changes: 0 additions & 2 deletions tests/phpunit/Settings/ConverterTest.php
Expand Up @@ -12,11 +12,9 @@

namespace Cyr_To_Lat\Tests\Settings;

use Cyr_To_Lat\Settings\Abstracts\SettingsBase;
use Cyr_To_Lat\Settings\Converter;
use Cyr_To_Lat\Cyr_To_Lat_TestCase;
use Mockery;
use ReflectionClass;
use ReflectionException;
use tad\FunctionMocker\FunctionMocker;
use WP_Mock;
Expand Down
1 change: 0 additions & 1 deletion tests/phpunit/Settings/SettingsTest.php
Expand Up @@ -55,7 +55,6 @@ public function test_constructor() {
* @preserveGlobalState disabled
*
* @throws ReflectionException ReflectionException.
* @noinspection JsonEncodingApiUsageInspection
*/
public function test_init_and_screen_ids() {
$subject = Mockery::mock( Settings::class )->makePartial()->shouldAllowMockingProtectedMethods();
Expand Down
2 changes: 0 additions & 2 deletions tests/phpunit/Settings/TablesTest.php
Expand Up @@ -160,8 +160,6 @@ public function test_init_locales() {
/**
* Test init_form_fields()
*
* @noinspection PhpSwitchCanBeReplacedWithMatchExpressionInspection
*
* @throws ReflectionException ReflectionException.
*/
public function test_init_form_fields() {
Expand Down
25 changes: 10 additions & 15 deletions tests/phpunit/bootstrap.php
Expand Up @@ -10,11 +10,6 @@

use tad\FunctionMocker\FunctionMocker;

/**
* Plugin test dir.
*/
define( 'PLUGIN_TESTS_DIR', __DIR__ );

/**
* Plugin main file.
*/
Expand All @@ -28,7 +23,7 @@
/**
* Kilobytes in bytes.
*/
define( 'KB_IN_BYTES', 1024 );
const KB_IN_BYTES = 1024;

require_once PLUGIN_PATH . '/vendor/autoload.php';

Expand All @@ -42,47 +37,47 @@
/**
* Plugin version.
*/
const CYR_TO_LAT_TEST_VERSION = '5.2.3';
const CYR_TO_LAT_TEST_VERSION = '5.2.4';

/**
* Path to the plugin dir.
*/
define( 'CYR_TO_LAT_TEST_PATH', PLUGIN_PATH );
const CYR_TO_LAT_TEST_PATH = PLUGIN_PATH;

/**
* Plugin dir url.
*/
define( 'CYR_TO_LAT_TEST_URL', 'http://site.org/wp-content/plugins/cyr2lat' );
const CYR_TO_LAT_TEST_URL = 'https://site.org/wp-content/plugins/cyr2lat';

/**
* Main plugin file.
*/
define( 'CYR_TO_LAT_TEST_FILE', PLUGIN_MAIN_FILE );
const CYR_TO_LAT_TEST_FILE = PLUGIN_MAIN_FILE;

/**
* Plugin prefix.
*/
define( 'CYR_TO_LAT_TEST_PREFIX', 'cyr_to_lat' );
const CYR_TO_LAT_TEST_PREFIX = 'cyr_to_lat';

/**
* Post conversion action.
*/
define( 'CYR_TO_LAT_TEST_POST_CONVERSION_ACTION', 'post_conversion_action' );
const CYR_TO_LAT_TEST_POST_CONVERSION_ACTION = 'post_conversion_action';

/**
* Term conversion action.
*/
define( 'CYR_TO_LAT_TEST_TERM_CONVERSION_ACTION', 'term_conversion_action' );
const CYR_TO_LAT_TEST_TERM_CONVERSION_ACTION = 'term_conversion_action';

/**
* Minimum required php version.
*/
define( 'CYR_TO_LAT_TEST_MINIMUM_PHP_REQUIRED_VERSION', '5.6' );
const CYR_TO_LAT_TEST_MINIMUM_PHP_REQUIRED_VERSION = '5.6';

/**
* Minimum required max_input_vars value.
*/
define( 'CYR_TO_LAT_TEST_REQUIRED_MAX_INPUT_VARS', 1000 );
const CYR_TO_LAT_TEST_REQUIRED_MAX_INPUT_VARS = 1000;

FunctionMocker::init(
[
Expand Down
6 changes: 6 additions & 0 deletions tests/phpunit/classes/class-cyr-to-lat-testcase.php
Expand Up @@ -88,6 +88,9 @@ abstract class Cyr_To_Lat_TestCase extends TestCase {

/**
* Setup test
*
* @noinspection PhpLanguageLevelInspection
* @noinspection PhpUndefinedClassInspection
*/
public function setUp(): void {
FunctionMocker::setUp();
Expand Down Expand Up @@ -131,6 +134,9 @@ function ( $name ) {

/**
* End test
*
* @noinspection PhpLanguageLevelInspection
* @noinspection PhpUndefinedClassInspection
*/
public function tearDown(): void {
WP_Mock::tearDown();
Expand Down
Expand Up @@ -29,6 +29,9 @@ class Test_Post_Conversion_Process extends Cyr_To_Lat_TestCase {

/**
* End test
*
* @noinspection PhpLanguageLevelInspection
* @noinspection PhpUndefinedClassInspection
*/
public function tearDown(): void {
unset( $GLOBALS['wpdb'] );
Expand Down
Expand Up @@ -28,6 +28,9 @@ class Test_Term_Conversion_Process extends Cyr_To_Lat_TestCase {

/**
* End test
*
* @noinspection PhpLanguageLevelInspection
* @noinspection PhpUndefinedClassInspection
*/
public function tearDown(): void {
unset( $GLOBALS['wpdb'] );
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/class-test-admin-notices.php
Expand Up @@ -25,7 +25,7 @@ class Test_Admin_Notices extends Cyr_To_Lat_TestCase {
* @noinspection NullPointerExceptionInspection
*/
public function test_constructor() {
$classname = __NAMESPACE__ . '\Admin_Notices';
$classname = Admin_Notices::class;

// Get mock, without the constructor being called.
$mock = $this->getMockBuilder( $classname )->disableOriginalConstructor()->getMock();
Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/tests/class-test-converter.php
Expand Up @@ -30,6 +30,9 @@ class Test_Converter extends Cyr_To_Lat_TestCase {

/**
* End test
*
* @noinspection PhpLanguageLevelInspection
* @noinspection PhpUndefinedClassInspection
*/
public function tearDown(): void {
// phpcs:disable WordPress.Security.NonceVerification.Recommended
Expand Down

0 comments on commit e91b308

Please sign in to comment.