Skip to content

Commit

Permalink
Merge bc8c6e5 into 78a80fd
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Sep 6, 2021
2 parents 78a80fd + bc8c6e5 commit 4f47eea
Show file tree
Hide file tree
Showing 12 changed files with 708 additions and 145 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -17,6 +17,20 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Get Composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Set up Composer caching
uses: actions/cache@v2
env:
cache-name: cache-composer-dependencies
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
Expand Down
23 changes: 17 additions & 6 deletions .github/workflows/deploy-to-wp-org.yml
Expand Up @@ -12,6 +12,20 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

- name: Get Composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Set up Composer caching
uses: actions/cache@v2
env:
cache-name: cache-composer-dependencies
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install dependencies in prod version
run: |
composer config github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -29,11 +43,8 @@ jobs:
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}

- name: Upload release asset
uses: actions/upload-release-asset@v1
uses: softprops/action-gh-release@v1
with:
files: ${{github.workspace}}/${{ github.event.repository.name }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{github.workspace}}/${{ github.event.repository.name }}.zip
asset_name: ${{ github.event.repository.name }}.zip
asset_content_type: application/zip
6 changes: 1 addition & 5 deletions composer.json
Expand Up @@ -45,10 +45,6 @@
{
"type": "vcs",
"url": "https://github.com/humbug/php-scoper.git"
},
{
"type": "vcs",
"url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git"
}
],
"minimum-stability": "dev",
Expand All @@ -60,8 +56,8 @@
},
"require-dev": {
"roave/security-advisories": "dev-master",
"lucatume/function-mocker": "^1.3",
"10up/wp_mock": "0.2 - 0.4",
"lucatume/function-mocker": "dev-master",
"phpunit/phpunit": "5.7 - 9.5",
"squizlabs/php_codesniffer": "^3.6",
"phpcompatibility/php-compatibility": "^9.3",
Expand Down
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.1
* Version: 5.2.2
* 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.1' );
define( 'CYR_TO_LAT_VERSION', '5.2.2' );

/**
* Path to the plugin dir.
Expand Down
8 changes: 7 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.1
Stable tag: 5.2.2
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,12 @@ Yes you can!

== Changelog ==

= 5.2.2 (15.08.2021) =
* Fix issue caused by the bug in Jetpack sync.
* Optimize code related to WPML locale filtering.
* Fix endless loading of a taxonomy page with WPML.
* Fix 'nothing found' on a taxonomy page with WPML.

= 5.2.1 (29.07.2021) =
* Determine WPML language only once to improve performance.
* Avoid notice on bad SQL request when taxonomies are empty.
Expand Down
9 changes: 9 additions & 0 deletions src/php/Settings/Abstracts/SettingsBase.php
Expand Up @@ -395,6 +395,15 @@ public function setup_sections() {
* Setup tabs section.
*/
public function setup_tabs_section() {
/**
* Protection from the bug in \Automattic\Jetpack\Sync\Sender::get_items_to_send(),
* which sets screen without loading of wp-admin/includes/template.php,
* where add_settings_section() is defined.
*/
if ( ! function_exists( 'add_settings_section' ) ) {
return;
}

$tab = $this->get_active_tab();

add_settings_section(
Expand Down
79 changes: 56 additions & 23 deletions src/php/class-main.php
Expand Up @@ -24,6 +24,13 @@
*/
class Main {

/**
* Request type.
*
* @var Request
*/
protected $request;

/**
* Plugin settings.
*
Expand Down Expand Up @@ -99,12 +106,18 @@ class Main {
*
* @var string
*/
private $wpml_locale;
protected $wpml_locale;

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

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

$this->settings = new Settings();
$this->admin_notices = new Admin_Notices();
$requirements = new Requirements( $this->settings, $this->admin_notices );
Expand All @@ -123,7 +136,7 @@ public function __construct() {
$this->admin_notices
);

if ( defined( 'WP_CLI' ) && constant( 'WP_CLI' ) ) {
if ( $this->request->is_cli() ) {
$this->cli = new WP_CLI( $this->converter );
}

Expand All @@ -136,7 +149,11 @@ public function __construct() {
* @noinspection PhpUndefinedClassInspection
*/
public function init() {
if ( defined( 'WP_CLI' ) && constant( 'WP_CLI' ) ) {
if ( $this->request->is_frontend() ) {
return;
}

if ( $this->request->is_cli() ) {
try {
/**
* Method WP_CLI::add_command() accepts class as callable.
Expand Down Expand Up @@ -167,9 +184,13 @@ public function init_hooks() {
}

if ( class_exists( SitePress::class ) ) {
$this->wpml_locale = $this->get_wpml_locale();

// 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 );

add_action( 'wpml_language_has_switched', [ $this, 'wpml_language_has_switched' ], 10, 3 );
}
}

Expand Down Expand Up @@ -282,14 +303,14 @@ public function sanitize_filename( $filename, $filename_raw ) {
}

/**
* Fix string encoding on MacOS.
* Fix string encoding on macOS.
*
* @param string $string String.
* @param array $table Conversion table.
*
* @return string
*/
private function fix_mac_string( $string ) {
$table = $this->get_filtered_table();
private function fix_mac_string( $string, $table ) {
$fix_table = Conversion_Tables::get_fix_table_for_mac();

$fix = [];
Expand Down Expand Up @@ -329,15 +350,6 @@ protected function split_chinese_string( $string, $table ) {
return $string;
}

/**
* Get transliteration table.
*
* @return array
*/
private function get_filtered_table() {
return (array) apply_filters( 'ctl_table', $this->settings->get_table() );
}

/**
* Transliterate string using a table.
*
Expand All @@ -346,9 +358,9 @@ private function get_filtered_table() {
* @return string
*/
public function transliterate( $string ) {
$table = $this->get_filtered_table();
$table = (array) apply_filters( 'ctl_table', $this->settings->get_table() );

$string = $this->fix_mac_string( $string );
$string = $this->fix_mac_string( $string, $table );
$string = $this->split_chinese_string( $string, $table );

return strtr( $string, $table );
Expand All @@ -360,6 +372,8 @@ 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 @@ -485,6 +499,7 @@ public function pll_locale_filter( $locale ) {
if ( false === $rest_locale ) {
return $locale;
}

if ( $rest_locale ) {
$this->pll_locale = $rest_locale;

Expand Down Expand Up @@ -518,7 +533,7 @@ public function pll_locale_filter( $locale ) {
* @return false|null|string
*/
private function pll_locale_filter_with_rest() {
if ( ! defined( 'REST_REQUEST' ) || ! constant( 'REST_REQUEST' ) ) {
if ( ! $this->request->is_rest() ) {
return null;
}

Expand Down Expand Up @@ -609,16 +624,34 @@ public function wpml_locale_filter( $locale ) {
return $this->wpml_locale;
}

return $locale;
}

/**
* Get wpml locale.
*
* @return string|null
*/
protected function get_wpml_locale() {
$language_code = wpml_get_current_language();
$languages = apply_filters( 'wpml_active_languages', null );

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

return $this->wpml_locale;
}
/**
* Save switched locale.
*
* @param null|string $language_code Language code to switch into.
* @param bool|string $cookie_lang Optionally also switch the cookie language to the value given.
* @param string $original_language Original language.
*
* @noinspection PhpUnusedParameterInspection
*/
public function wpml_language_has_switched( $language_code, $cookie_lang, $original_language ) {
$languages = apply_filters( 'wpml_active_languages', null );

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

/**
Expand Down

0 comments on commit 4f47eea

Please sign in to comment.