Skip to content

Commit

Permalink
Merge pull request #103 from mihdan/v5.2
Browse files Browse the repository at this point in the history
V5.2
  • Loading branch information
kagg-design authored Jul 27, 2021
2 parents 39c9eff + 5673d1b commit 9c6c7dd
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 52 deletions.
4 changes: 2 additions & 2 deletions cyr-to-lat.php
Original file line number Diff line number Diff line change
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.1.0
* Version: 5.2.0
* 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.1.0' );
define( 'CYR_TO_LAT_VERSION', '5.2.0' );

/**
* Path to the plugin dir.
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
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.1.0
Stable tag: 5.2.0
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,9 @@ Yes you can!

== Changelog ==

= 5.2.0 (27.07.2021) =
* Add support for categories and tags in other languages with wpml.

= 5.1.0 (19.07.2021) =
* Fix issue-95 - 404 on localized terms created before plugin install.
* Add cache flushing after batch conversion.
Expand Down
3 changes: 1 addition & 2 deletions src/php/Settings/Abstracts/SettingsBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ protected function parent_slug() {
* Is this the main menu page.
*
* @return bool
* @noinspection PhpPureAttributeCanBeAddedInspection
*/
protected function is_main_menu_page() {
// Main menu page should have empty string as parent slug.
Expand Down Expand Up @@ -262,7 +261,7 @@ protected function is_tab() {
* With Multisite active this can also include
* 'network_active' and 'network_only' items.
*
* @return array|mixed Plugin links
* @return array|string[] Plugin links
*/
public function add_settings_link( array $actions ) {
$new_actions = [
Expand Down
11 changes: 1 addition & 10 deletions src/php/Settings/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,6 @@ protected function section_title() {
return '';
}

/**
* Get parent slug.
*
* @return string
*/
protected function parent_slug() {
return 'options-general.php';
}

/**
* Init class hooks.
*/
Expand Down Expand Up @@ -201,7 +192,7 @@ public function delayed_init_form_fields() {
public function delayed_init_settings() {
$this->delayed_init_form_fields();

parent::init_settings();
$this->init_settings();
}

/**
Expand Down
4 changes: 0 additions & 4 deletions src/php/Settings/PluginSettingsBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ protected function plugin_basename() {
* Get plugin url.
*
* @return string
*
* @noinspection PhpPureAttributeCanBeAddedInspection
*/
protected function plugin_url() {
return constant( 'CYR_TO_LAT_URL' );
Expand All @@ -40,8 +38,6 @@ protected function plugin_url() {
* Get plugin version.
*
* @return string
*
* @noinspection PhpPureAttributeCanBeAddedInspection
*/
protected function plugin_version() {
return constant( 'CYR_TO_LAT_VERSION' );
Expand Down
2 changes: 2 additions & 0 deletions src/php/Settings/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public function __construct() {

/**
* Init class.
*
* @noinspection UnnecessaryCastingInspection
*/
protected function init() {
// Allow to specify MENU_PAGES item as one class, not an array.
Expand Down
10 changes: 0 additions & 10 deletions src/php/Settings/Tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,6 @@ protected function section_title() {
return '';
}

/**
* Get parent slug.
*
* @return string
*/
protected function parent_slug() {
// Indicate that it is the main menu page.
return 'options-general.php';
}

/**
* Init locales.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/php/background-processes/class-conversion-process.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct( $main ) {
*
* @param mixed $item Queue item to iterate over.
*
* @return mixed
* @return boolean
*/
protected function task( $item ) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct( $main ) {
*
* @param stdClass $post Queue item to iterate over.
*
* @return mixed
* @return boolean
* @noinspection PhpParameterNameChangedDuringInheritanceInspection
*/
protected function task( $post ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct( $main ) {
*
* @param stdClass $term Queue item to iterate over.
*
* @return mixed
* @return boolean
* @noinspection PhpParameterNameChangedDuringInheritanceInspection
*/
protected function task( $term ) {
Expand Down
1 change: 0 additions & 1 deletion src/php/class-conversion-tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,6 @@ public static function get( $locale = '' ) {
* On MacOS, files containing characters in the table, are sometimes encoded improperly.
*
* @return array
* @noinspection PhpArrayShapeAttributeCanBeAddedInspection
*/
public static function get_fix_table_for_mac() {
/**
Expand Down
41 changes: 34 additions & 7 deletions src/php/class-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Cyr_To_Lat;

use Polylang;
use SitePress;
use WP_Error;
use wpdb;
use Exception;
Expand Down Expand Up @@ -153,9 +155,15 @@ public function init_hooks() {
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 ( class_exists( 'Polylang' ) ) {
if ( class_exists( Polylang::class ) ) {
add_filter( 'locale', [ $this, 'pll_locale_filter' ] );
}

if ( class_exists( SitePress::class ) ) {
// We cannot use locale filter here
// as WPML reverts locale at PHP_INT_MAX in \WPML\ST\MO\Hooks\LanguageSwitch::filterLocale.
add_filter( 'ctl_locale', [ $this, 'wpml_locale_filter' ], - PHP_INT_MAX );
}
}

/**
Expand Down Expand Up @@ -390,7 +398,7 @@ private function is_gutenberg_editor_active() {
* @param array $data An array of slashed post data.
* @param array $postarr An array of sanitized, but otherwise unmodified post data.
*
* @return mixed
* @return array
* @noinspection PhpUnusedParameterInspection
*/
public function sanitize_post_name( $data, $postarr = [] ) {
Expand Down Expand Up @@ -579,6 +587,24 @@ private function pll_locale_filter_with_term() {
return $pll_get_term_language;
}

/**
* Locale filter for WPML.
*
* @param string $locale Locale.
*
* @return string
*/
public function wpml_locale_filter( $locale ) {
$language_code = wpml_get_current_language();
$languages = apply_filters( 'wpml_active_languages', null );

if ( isset( $languages[ $language_code ] ) ) {
return $languages[ $language_code ]['default_locale'];
}

return $locale;
}

/**
* Changes array of items into string of items, separated by comma and sql-escaped
*
Expand All @@ -593,14 +619,15 @@ private function pll_locale_filter_with_term() {
public function prepare_in( $items, $format = '%s' ) {
global $wpdb;

$items = (array) $items;
$how_many = count( $items );
$prepared_in = '';
$items = (array) $items;
$how_many = count( $items );

if ( $how_many > 0 ) {
$placeholders = array_fill( 0, $how_many, $format );
$prepared_format = implode( ',', $placeholders );
$prepared_in = $wpdb->prepare( $prepared_format, $items ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
} else {
$prepared_in = '';
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$prepared_in = $wpdb->prepare( $prepared_format, $items );
}

return $prepared_in;
Expand Down
5 changes: 1 addition & 4 deletions src/php/class-requirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ private function is_max_input_vars_required() {

/**
* Try to fix max_input_vars.
*
* @noinspection PhpStrFunctionsInspection
*/
protected function try_to_fix_max_input_vars() {
$user_ini_filename = $this->get_user_ini_filename();
Expand Down Expand Up @@ -225,7 +223,6 @@ static function ( $line ) {
* Get .user.ini filename.
*
* @return string
* @noinspection PhpPureAttributeCanBeAddedInspection
*/
private function get_user_ini_filename() {
return ABSPATH . 'wp-admin/' . ini_get( 'user_ini.filename' );
Expand All @@ -238,7 +235,7 @@ private function ask_to_increase_max_input_vars() {
$message = __( 'Please increase max input vars limit up to 1500.', 'cyr2lat' );

$message .= '<br>';
$message .= __( 'See: <a href="http://sevenspark.com/docs/ubermenu-3/faqs/menu-item-limit" target="_blank">Increasing max input vars limit.</a>', 'cyr2lat' );
$message .= __( 'See: <a href="https://sevenspark.com/docs/ubermenu-3/faqs/menu-item-limit" target="_blank">Increasing max input vars limit.</a>', 'cyr2lat' );

$this->admin_notices->add_notice(
$message,
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
/**
* Plugin version.
*/
define( 'CYR_TO_LAT_TEST_VERSION', '5.1.0' );
define( 'CYR_TO_LAT_TEST_VERSION', '5.2.0' );

/**
* Path to the plugin dir.
Expand Down
Loading

0 comments on commit 9c6c7dd

Please sign in to comment.