From f4b12034d6d18a1fb77e66cf40007ce4fc4c91ea Mon Sep 17 00:00:00 2001 From: Julien MA Jacob Date: Fri, 22 Nov 2024 20:22:37 -0200 Subject: [PATCH 1/9] Better translatable URL management --- inc/url.php | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/inc/url.php b/inc/url.php index 3935ec2..20d6027 100644 --- a/inc/url.php +++ b/inc/url.php @@ -25,16 +25,6 @@ function wplng_url_translate( $url, $language_target_id = '' ) { return $url; } - // Check if it's an WooCommece AJAX URL - if ( wplng_str_contains( $url, '?wc-ajax=' ) ) { - return $url; - } - - // Check if URL is an anchor link for the current page - if ( '#' === substr( $url, 0, 1 ) ) { - return $url; - } - $languages_target = wplng_get_languages_target(); if ( '' === $language_target_id ) { @@ -150,20 +140,29 @@ function wplng_url_is_translatable( $url = '' ) { $is_translatable = false; } - // Check if is wp-login.php + // Check if URL is an anchor link for the current page if ( $is_translatable - && wplng_str_contains( $url, 'wp-login.php' ) + && '#' === substr( $url, 0, 1 ) ) { - $is_translatable = false; + return $url; } - // Check if is a /feed/ if ( $is_translatable - && wplng_str_ends_with( $url, '/feed/' ) + && ( + wplng_str_contains( $url, 'wp-login.php' ) + || wplng_str_ends_with( $url, '/feed/' ) + || wplng_str_contains( $url, 'wp-comments-post.php' ) + || wplng_str_contains( $url, 'wp-register.php' ) + || wplng_str_contains( $url, '/wp-json/' ) + || wplng_str_contains( $url, '/wp-includes/' ) + || wplng_str_contains( $url, '?wc-ajax=' ) + ) ) { $is_translatable = false; } + + // Check if is Divi editor if ( $is_translatable && ( @@ -175,13 +174,6 @@ function wplng_url_is_translatable( $url = '' ) { $is_translatable = false; } - // Check if is wp-comments-post.php - if ( $is_translatable - && wplng_str_contains( $url, 'wp-comments-post.php' ) - ) { - $is_translatable = false; - } - // Check if is in wp-uploads if ( $is_translatable && wplng_str_contains( $url, wp_make_link_relative( content_url() ) ) From a72b86a5bbb0f1dbb39450d9f28e38fa9f04b29e Mon Sep 17 00:00:00 2001 From: Julien MA Jacob Date: Mon, 25 Nov 2024 21:06:46 -0200 Subject: [PATCH 2/9] Not translate slug if contain a dot --- inc/slug.php | 8 +++++--- inc/url.php | 2 -- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/inc/slug.php b/inc/slug.php index 3bb43ec..7b24191 100644 --- a/inc/slug.php +++ b/inc/slug.php @@ -118,7 +118,9 @@ function wplng_slug_original_path( $path, $language_id ) { */ function wplng_slug_translate( $slug, $language_id, $slugs_translations = false ) { - if ( ! wplng_text_is_translatable( $slug ) ) { + if ( ! wplng_text_is_translatable( $slug ) + || wplng_str_contains( $slug, '.' ) + ) { return $slug; } @@ -128,7 +130,7 @@ function wplng_slug_translate( $slug, $language_id, $slugs_translations = false $slug_translation_exist = false; - foreach ( $slugs_translations as $key => $slug_translations ) { + foreach ( $slugs_translations as $slug_translations ) { if ( $slug !== $slug_translations['source'] || ! isset( $slug_translations['translations'][ $language_id ] ) @@ -219,6 +221,7 @@ function wplng_slug_translate_path( $path, $language_id ) { if ( wplng_text_is_translatable( $slug ) && ! wplng_str_starts_with( $slug, '#' ) && ! wplng_str_starts_with( $slug, '?' ) + && ! wplng_str_contains( $slug, '.' ) ) { $path_translated .= wplng_slug_translate( $slug, @@ -243,7 +246,6 @@ function wplng_slug_translate_path( $path, $language_id ) { } return $path_translated; - } diff --git a/inc/url.php b/inc/url.php index 20d6027..5cb4788 100644 --- a/inc/url.php +++ b/inc/url.php @@ -161,8 +161,6 @@ function wplng_url_is_translatable( $url = '' ) { $is_translatable = false; } - - // Check if is Divi editor if ( $is_translatable && ( From 29981fec5b5d4a990bbcd93999a163cc1d57046e Mon Sep 17 00:00:00 2001 From: Julien MA Jacob Date: Mon, 25 Nov 2024 21:10:20 -0200 Subject: [PATCH 3/9] Not create slug if is a valid language ID --- inc/slug.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/inc/slug.php b/inc/slug.php index 7b24191..1ae400d 100644 --- a/inc/slug.php +++ b/inc/slug.php @@ -263,7 +263,9 @@ function wplng_create_slug( $slug ) { $slug = sanitize_title( $slug ); - if ( '' === $slug ) { + if ( '' === $slug + || wplng_is_valid_language_id( $slug ) + ) { return false; } From 6b69c8e4487899e3dbe68ee92f798f4088ccc664 Mon Sep 17 00:00:00 2001 From: Julien MA Jacob Date: Mon, 25 Nov 2024 22:02:32 -0200 Subject: [PATCH 4/9] Automatic delete bad slug saved --- inc/slug.php | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/inc/slug.php b/inc/slug.php index 1ae400d..e715000 100644 --- a/inc/slug.php +++ b/inc/slug.php @@ -358,6 +358,8 @@ function wplng_create_slug( $slug ) { */ function wplng_get_slugs_from_query() { + $slug_to_delete = array(); + $slugs = array(); $args = array( 'post_type' => 'wplng_slug', @@ -374,7 +376,8 @@ function wplng_get_slugs_from_query() { $the_query->the_post(); - $meta = get_post_meta( get_the_ID() ); + $slug_id = get_the_ID(); + $meta = get_post_meta( $slug_id ); /** * Check and clear source slug @@ -386,7 +389,12 @@ function wplng_get_slugs_from_query() { continue; } - $source = esc_attr( $meta['wplng_slug_original'][0] ); + $source = sanitize_title( $meta['wplng_slug_original'][0] ); + + if ( 'index-php' === $source ) { + $slug_to_delete[] = $slug_id; + continue; + } /** * Check and clear slug translations, setup review array @@ -443,10 +451,19 @@ function wplng_get_slugs_from_query() { wp_reset_postdata(); - set_transient( - 'wplng_cached_slugs', - $slugs - ); + if ( ! empty( $slug_to_delete ) ) { + foreach ( $slug_to_delete as $key => $id ) { + if ( $key >= 50 ) { + break; + } + wp_delete_post( $id, true ); + } + } else { + set_transient( + 'wplng_cached_slugs', + $slugs + ); + } return $slugs; } From 4c2df0e8e8660334d749a8535cf8c2f0f4f5ff3a Mon Sep 17 00:00:00 2001 From: Julien MA Jacob Date: Mon, 25 Nov 2024 22:18:26 -0200 Subject: [PATCH 5/9] Better automatic delete bad slug saved --- inc/slug.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/inc/slug.php b/inc/slug.php index e715000..899d6a5 100644 --- a/inc/slug.php +++ b/inc/slug.php @@ -458,6 +458,11 @@ function wplng_get_slugs_from_query() { } wp_delete_post( $id, true ); } + set_transient( + 'wplng_cached_slugs', + $slugs, + 30 + ); } else { set_transient( 'wplng_cached_slugs', From f392cb2c83f1bbda2023eed7469e8707ddc6616c Mon Sep 17 00:00:00 2001 From: Julien MA Jacob Date: Mon, 25 Nov 2024 22:20:46 -0200 Subject: [PATCH 6/9] Automatic delete wp-includes and wp-json slug --- inc/slug.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/inc/slug.php b/inc/slug.php index 899d6a5..fe77497 100644 --- a/inc/slug.php +++ b/inc/slug.php @@ -391,7 +391,10 @@ function wplng_get_slugs_from_query() { $source = sanitize_title( $meta['wplng_slug_original'][0] ); - if ( 'index-php' === $source ) { + if ( 'index-php' === $source + || 'wp-includes' === $source + || 'wp-json' === $source + ) { $slug_to_delete[] = $slug_id; continue; } From ec8d9a41856038f1366e9467a9e3b01ae2f0f270 Mon Sep 17 00:00:00 2001 From: Julien MA Jacob Date: Mon, 25 Nov 2024 22:34:15 -0200 Subject: [PATCH 7/9] Automatic bad slug delete 32 by 32 --- inc/slug.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/slug.php b/inc/slug.php index fe77497..59dcac0 100644 --- a/inc/slug.php +++ b/inc/slug.php @@ -456,7 +456,7 @@ function wplng_get_slugs_from_query() { if ( ! empty( $slug_to_delete ) ) { foreach ( $slug_to_delete as $key => $id ) { - if ( $key >= 50 ) { + if ( $key >= 32 ) { break; } wp_delete_post( $id, true ); From f26e6bff8a3fa0dd082c54b65564c747ddc890e4 Mon Sep 17 00:00:00 2001 From: Julien MA Jacob Date: Mon, 25 Nov 2024 22:39:02 -0200 Subject: [PATCH 8/9] Update version number and changelog --- readme.txt | 7 ++++++- wplingua.php | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/readme.txt b/readme.txt index 2a577fe..46e1ab2 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://wplingua.com/ Tags: translate, translation, multilingual, localization, language Requires at least: 6.0 Tested up to: 6.7 -Stable tag: 2.1.2 +Stable tag: 2.1.3 Requires PHP: 7.4 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -174,6 +174,11 @@ No, not at the moment but in the meantime, you can easily display the language s == Changelog == += 2.1.3 = + +* Better untranslatable URL detection +* Automatic bad slug deletion + = 2.1.2 = * Better plugin translations loading diff --git a/wplingua.php b/wplingua.php index 007f38c..d6428b9 100644 --- a/wplingua.php +++ b/wplingua.php @@ -7,7 +7,7 @@ * Author URI: https://github.com/julien-jacob/wplingua * Text Domain: wplingua * Domain Path: /languages/ - * Version: 2.1.2 + * Version: 2.1.3 * Requires PHP: 7.4 * License: GPL v2 or later * License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -24,7 +24,7 @@ define( 'WPLNG_API_URL', 'https://api.wplingua.com' ); define( 'WPLNG_API_VERSION', '2.0' ); define( 'WPLNG_API_SSLVERIFY', true ); -define( 'WPLNG_PLUGIN_VERSION', '2.1.2' ); +define( 'WPLNG_PLUGIN_VERSION', '2.1.3' ); define( 'WPLNG_PLUGIN_FILE', plugin_basename( __FILE__ ) ); define( 'WPLNG_PLUGIN_PATH', dirname( __FILE__ ) ); define( 'WPLNG_MAX_TRANSLATIONS', 256 ); From 7012256ce71d1cf4b4653c2141c8e945d9804a89 Mon Sep 17 00:00:00 2001 From: Julien MA Jacob Date: Mon, 25 Nov 2024 22:44:53 -0200 Subject: [PATCH 9/9] wplingua.com as Plugin URI and Author URI --- wplingua.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wplingua.php b/wplingua.php index d6428b9..c9321df 100644 --- a/wplingua.php +++ b/wplingua.php @@ -4,7 +4,7 @@ * Plugin URI: https://wplingua.com/ * Description: An all-in-one solution that makes your websites multilingual and translates them automatically, without word or page limits. The highlights: a free first language, an on-page visual editor for editing translations, a customizable language switcher, search engine optimization (SEO), self-hosted data and more! * Author: wpLingua Team - * Author URI: https://github.com/julien-jacob/wplingua + * Author URI: https://wplingua.com/ * Text Domain: wplingua * Domain Path: /languages/ * Version: 2.1.3